-
-
Save alberthdev/1834fc1fa0679f0671fe to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # Debian System Reinstaller | |
| # Copyright (C) 2015 Albert Huang | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| # | |
| # --- | |
| # This script assumes you are using a Debian based system | |
| # (Debian, Mint, Ubuntu, #!), and have sudo installed. If you don't | |
| # have sudo installed, replace "sudo" with "su -c" instead. | |
| # | |
| becho() { | |
| echo -e "\033[1m$@\033[0m" | |
| } | |
| spinat=0 | |
| spinner() { | |
| spinat=`expr $spinat + 1` | |
| if [ "$spinat" = "1" ];then | |
| spin="|" | |
| elif [ "$spinat" = "2" ];then | |
| spin="/" | |
| elif [ "$spinat" = "3" ];then | |
| spin="-" | |
| elif [ "$spinat" = "4" ];then | |
| spin="\\" | |
| spinat=0; | |
| else | |
| spinat=0; | |
| fi | |
| printf "\b$spin" | |
| } | |
| spinner_loop() { | |
| while :; do | |
| spinner | |
| sleep 0.1s | |
| done | |
| } | |
| spinner_register() { | |
| spinner_proc=$1 | |
| export spinner_proc | |
| } | |
| spinner_cancel() { | |
| kill -PIPE $spinner_proc | |
| printf "\b \b" | |
| } | |
| stopnow=0 | |
| export stopnow | |
| trap "echo 'Detected CTRL-C, exiting...'; stopnow=1; export stopnow" INT TERM | |
| becho " * Scanning for all installed packages on the system..." | |
| [ "$stopnow" = "1" ] && exit | |
| spinner_loop & | |
| spinner_register %% | |
| pkgs=`dpkg --get-selections | grep -w 'install$' | cut -f 1 | \ | |
| egrep -v '(dpkg|apt)'` | |
| spinner_cancel | |
| [ "$stopnow" = "1" ] && exit | |
| becho " * Reinstallation will start in 3 seconds..." | |
| [ "$stopnow" = "1" ] && exit | |
| sleep 3s | |
| [ "$stopnow" = "1" ] && exit | |
| becho " * Reinstalling..." | |
| rm -f reinstall.log | |
| for pkg in $pkgs; do | |
| echo -e "\033[1m * Reinstalling:\033[0m $pkg" | |
| echo "***** Reinstalling: $pkg *****" >> reinstall.log | |
| printf " " | |
| [ "$stopnow" = "1" ] && exit | |
| spinner_loop & | |
| spinner_register %% | |
| sudo apt-get -q -y --force-yes install --reinstall -o Dpkg::Options::="--force-confmiss" $pkg >> reinstall.log | |
| cerr=$? | |
| spinner_cancel | |
| backstep " " | |
| if [ ! "$cerr" = "0" ]; then | |
| echo "ERROR: Reinstallation failed. See reinstall.log for details." | |
| exit 1 | |
| fi | |
| [ "$stopnow" = "1" ] && exit | |
| done |
8 ) ... magnificent, saved my booty
Hi All,
Let me ask you an interesting question. I have already rewrote the usual util-linux 2.37 package on my PC with a newer 2.39.x built on my PC from a cloned directory. This resulted in that my PC is not booting now. I have another Ubuntu system that is working on the same machine. I am the root on both systems: the working and the not booting also.
I have already corrected GRUB & boot process but it seems right after the boot the system is crashing
Can you please provide me with a script that is able to re-install the old and usable util-linux 2.37 package from the working system? I mean that the target of apt-get install command would be on the other system.
Please advice what alternatives are exist. Thanks.
L.
Very useful script. In my case there were a lot of damaged configuration files. The trick is to pass the argument "force-confask". I also removed the spinner for simplification.