I'm looking for comments on a hack I've just written to make any Debian system auto-magically recover from apt breakage.
Use case: you have just installed a Debian-based distribution (say, Mint / LMDE) on someone's computer. The owner is not tech-savvy. Some day, apt will break because of a power outage while updating, a forced shutdown or whatever (in my experience, this happens sooner than later). Updates become impossible, installing applications either: the update manager or application manager alike throw an error that recommends opening a terminal and launching "dpkg --configure -a" (or some other technical message). The (non tech-savvy) user won't do that.
This hack is triggered at boot, waits for a working internet connection, tests if apt is broken and tries to fix it.
The main script: fix-apt.shSystemd service configuration file: fix-apt.serviceThe script to install the service: install-fix-apt-on-boot.sh
(All three files should be located in the same folder.)I'm asking for comments because of many doubts!
Use case: you have just installed a Debian-based distribution (say, Mint / LMDE) on someone's computer. The owner is not tech-savvy. Some day, apt will break because of a power outage while updating, a forced shutdown or whatever (in my experience, this happens sooner than later). Updates become impossible, installing applications either: the update manager or application manager alike throw an error that recommends opening a terminal and launching "dpkg --configure -a" (or some other technical message). The (non tech-savvy) user won't do that.
This hack is triggered at boot, waits for a working internet connection, tests if apt is broken and tries to fix it.
The main script: fix-apt.sh
Code:
#!/bin/bashuntil [[ `ping -c 1 archive.org` ]] || [[ `ping -c 1 kernel.org` ]] || [[ `ping -c 1 google.com` ]]; do sleep 10done# Tests wether dpkg -C reports something to do OR apt-get install yields an errorif [[ $(dpkg -C) ]] || ! apt-get install hostname -y; then apt-get -y clean apt-get -y update dpkg --configure -a --force-confdef --force-confnew apt-get install -f -y apt autoremove --purge -yfi
Code:
[Unit]Description=Fix broken APT if needed[Service]ExecStart=/bin/fix-apt.sh[Install]WantedBy=multi-user.target
(All three files should be located in the same folder.)
Code:
#!/bin/bashsudo cp fix-apt.service /etc/systemd/systemsudo cp fix-apt.sh /binsudo systemctl enable fix-apt.service
- Why, in the first place, is apt so vulnerable?
- Why do Debian and Debian-based distributions rely on a terminal-based solution to a broken apt system, that non-tech-savvy users won't be able to do?
- Is it enough to test for a broken apt system like I do?
- Does my script fix *any* situation where the apt system is broken (excluding the user has wrongly fiddled with the system, of course)?
- Would my script do more harm than good?
Statistics: Posted by ricflomag — 2025-01-09 00:25 — Replies 4 — Views 141