Closed Itai-Nelken closed 3 years ago
Or, have the script automatically check for and remove duplicate lines.
Like this: (untested)
echo "$(cat /etc/apt/sources.list | grep . | sort | uniq)" | sudo tee /etc/apt/sources.list >/dev/null
good idea! I'll test it later.
I did this to my sources.list:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
and after running the command, the file looks like this:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
instead of:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb [trusted=yes] https://itai-nelken.github.io/weekly-box86-debs/debs/ /
and after running the command, the file looks like this:
Yes, unfortunately, this approach will mess up the order of things. It will sort everything alphabetically, and grep .
will remove empty lines.
Research something like "bash remove duplicate lines without sorting".
@Botspot I found a solution:
awk '!a[$0]++' /etc/apt/sources.list >/dev/null
it doesn't work 100% though, so not a good solution.
I found a solution that works:
sudo rm -f ~/sources.list /etc/apt/sources.list.bak; awk '/^$/ {print; next} {if ($1 in a) next; a[$1]=$0; print}' /etc/apt/sources.list > ~/sources.list; sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak; sudo mv ~/sources.list /etc/apt/sources.list
@Botspot the above command works well (I edited it), it went from this:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
to this:
deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi
@Botspot can this line be added to pkg-install
?
sudo rm -f ~/sources.list /etc/apt/sources.list.bak >/dev/null; awk '/^$/ {print; next} {if ($1 in a) next; a[$1]=$0; print}' /etc/apt/sources.list > ~/sources.list; sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak; sudo mv ~/sources.list /etc/apt/sources.list
it tries to delete any files from its last run, then it runs the part that actually removes the duplicate lines and writes the output to ~/sources.list
, then it renames the old sources.list
to sources.list.bak
and moves ~/sources.list
to /etc/apt/sources.list
. (running the command to output to /etc/apt/sources.list doesn't work even when run as root)
those lines can be run when apt outputs a error similar to this one:
someting like configured multiple times in
then if after running sudo apt update
apt still errors out with those errors, open a yad window saying something like this:
apt reported there are duplicates in your /etc/apt/sources.list file,
pi-apps tried to fix them for you, but apt still reports the same.
do you want to restore your old sources.list?
if the answer is yes, run:
sudo rm /etc/apt/sources.list
sudo mv /etc/apt/sources.list.bak /etc/apt/sources.list
if the answer is no or the above code is run, exit with a error.
I've thought long and hard about this, and finally decided not to implement it.
if apt outputs something similar to this:
ask user if they wan't to replace the
/etc/apt/sources.list
with the default one on RPiOS. maybe also add OS detection so the default one for Ubuntu is used on Ubuntu, the default one for RPiOS is used for RPiOS, and I think the TwisterOS one is different than the RPiOS one.