Botspot / pi-apps

Raspberry Pi App Store for Open Source Projects
GNU General Public License v3.0
1.95k stars 204 forks source link

suggestion for pkg-install #387

Closed Itai-Nelken closed 3 years ago

Itai-Nelken commented 3 years ago

if apt outputs something similar to this:

W: Target Packages (main/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list:4 and /etc/apt/sources.list:5

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.

Botspot commented 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
Itai-Nelken commented 3 years ago

good idea! I'll test it later.

Itai-Nelken commented 3 years ago

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/ /
Botspot commented 3 years ago

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".

Itai-Nelken commented 3 years ago

@Botspot I found a solution: awk '!a[$0]++' /etc/apt/sources.list >/dev/null

Itai-Nelken commented 3 years ago

it doesn't work 100% though, so not a good solution.

Itai-Nelken commented 3 years ago

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

Itai-Nelken commented 3 years ago

@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
Itai-Nelken commented 3 years ago

@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: image 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.

Botspot commented 3 years ago

I've thought long and hard about this, and finally decided not to implement it.

  1. This seems like too much automagic. If someone's install is repeatedly adding multiple entries to sources.list, they would want to know.
  2. Few users have this problem, and those that do, have a reason for it. Likely a defective script. I'd rather track down the defective script than rely on a "bandaid" script to cover over the problem, further obscuring it.
  3. It goes against the KISS principle.