2023-03-15 22:50:00 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-02-20 18:50:34 +01:00
|
|
|
##########
|
|
|
|
# This script changes all "one-line" APT sources into "deb822" sources.
|
|
|
|
# It is responsible for searching and processing the files.
|
|
|
|
# The actual format migration is done by a python script.
|
|
|
|
##########
|
|
|
|
|
2023-03-15 22:50:00 +01:00
|
|
|
deb822_migrate_script=$(command -v deb822-migration.py)
|
|
|
|
|
|
|
|
if [ -z "${deb822_migrate_script}" ]; then
|
2023-03-16 21:36:13 +01:00
|
|
|
deb822_migrate_script="$(dirname "$0")/deb822-migration.py"
|
2023-03-15 22:50:00 +01:00
|
|
|
fi
|
|
|
|
if [ ! -x "${deb822_migrate_script}" ]; then
|
|
|
|
>&2 echo "ERROR: '${deb822_migrate_script}' not found or not executable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-17 20:05:42 +01:00
|
|
|
sources_from_file() {
|
|
|
|
grep --extended-regexp "^\s*(deb|deb-src) " $1
|
|
|
|
}
|
|
|
|
|
2023-03-15 22:50:00 +01:00
|
|
|
rc=0
|
2023-03-17 20:05:42 +01:00
|
|
|
count=0
|
2023-03-15 22:50:00 +01:00
|
|
|
|
2023-03-17 20:05:42 +01:00
|
|
|
if [ -f /etc/apt/sources.list ]; then
|
|
|
|
sources_from_file /etc/apt/sources.list | ${deb822_migrate_script}
|
|
|
|
python_rc=$?
|
|
|
|
|
|
|
|
if [ ${python_rc} -eq 0 ]; then
|
|
|
|
mv /etc/apt/sources.list /etc/apt/sources.list.bak
|
|
|
|
echo "OK: /etc/apt/sources.list"
|
|
|
|
count=$(( count + 1 ))
|
2023-03-15 22:50:00 +01:00
|
|
|
else
|
2023-03-17 20:05:42 +01:00
|
|
|
>&2 echo "ERROR: failed migration for /etc/apt/sources.list"
|
|
|
|
rc=1
|
2023-03-15 22:50:00 +01:00
|
|
|
fi
|
2023-03-17 20:05:42 +01:00
|
|
|
fi
|
2023-03-15 22:50:00 +01:00
|
|
|
|
2023-03-17 20:05:42 +01:00
|
|
|
for file in $(find /etc/apt/sources.list.d -mindepth 1 -maxdepth 1 -type f -name '*.list'); do
|
|
|
|
sources_from_file "${file}" | ${deb822_migrate_script}
|
|
|
|
python_rc=$?
|
2023-03-15 22:50:00 +01:00
|
|
|
|
2023-03-17 20:05:42 +01:00
|
|
|
if [ ${python_rc} -eq 0 ]; then
|
|
|
|
mv "${file}" "${file}.bak"
|
|
|
|
echo "OK: ${file}"
|
|
|
|
count=$(( count + 1 ))
|
|
|
|
else
|
|
|
|
>&2 echo "ERROR: failed migration for ${file}"
|
|
|
|
rc=1
|
|
|
|
fi
|
2023-03-15 22:50:00 +01:00
|
|
|
done
|
|
|
|
|
2023-03-17 20:05:42 +01:00
|
|
|
echo "${count} file(s) migrated"
|
2024-02-20 18:50:34 +01:00
|
|
|
exit ${rc}
|