Converts the Deb822 format files (whether they have .sources or .list extension) to the legacy one-line format
PURPOSE:
This script ensures all APT repository source files are in the correct format by converting any Deb822 format files (whether they have .sources or .list extension) to the traditional one-line format, while maintaining backups of the original files.
- Download the script:
sudo curl -L "https://raw.githubusercontent.com/bmcder/apt-format-converter/refs/heads/main/apt-format-reverter.sh" -o $output_file /usr/local/bin/apt-format-reverter
- Make it executable
sudo chmod +x /usr/local/bin/apt-format-reverter
- Run the script:
sudo /usr/local/bin/apt-format-reverter
-
Backup:
-
Creates a timestamped backup directory in
/var/tmp -
Preserves the original directory structure and file permissions
-
Stores original files before any modifications
-
-
Format Detection and Conversion:
-
Scans both
.sourcesand.listfiles in/etc/apt/sources.list.d/ -
Checks the main
/etc/apt/sources.listfile as well -
Identifies Deb822 format by checking for the
Types:field -
Converts files to one-line format if necessary
-
Changes
.sourcesfiles to.listextension after conversion -
Preserves existing
.listextension for files already using it
-
-
Format Translation:
- Converts from Deb822 format:
Types: deb
URIs: http://example.com/ubuntu
Suites: jammy
Components: main restricted
- To traditional one-line format:
deb http://example.com/ubuntu jammy main restricted
-
Creates backups before any modifications
-
Validates input format and types
-
Preserves comments and file structure
-
Provides clear error messages and warnings
-
Tracks and reports any errors during conversion
-
Only converts files that need conversion
-
Maintains correct file extensions
-
Back up all source files (both
.sourcesand.list) -
Check each file for correct format
-
Convert any files in Deb822 format to one-line format
-
Update file extensions as needed
-
Display the backup location
-
Provide instructions for reverting changes if needed
TROUBLESHOOTING:
If something goes wrong:
-
Check the backup location shown in the script output
-
Restore the original files:
sudo cp -r /var/tmp/sources_backup_TIMESTAMP/* /
- Run
sudo apt updateto verify the restoration
The script is particularly useful for:
-
Converting newer Deb822 format files to traditional format
-
Fixing misconfigured
.listfiles that accidentally use Deb822 format -
Ensuring consistency across all APT source files
-
Migrating between different Ubuntu versions or tools with different format requirements
-
Always run with sudo privileges
-
Keep note of the backup directory path shown in the output
-
Check the output for any error messages
-
Run
sudo apt updateafter the script completes to verify everything works -
The script is idempotent - running it multiple times won't cause issues
-
Original files are safely backed up before any modifications
Many Thanks to Petar Ivanov for the content