#!/bin/bash # This should work on a Debian based system, any of them # Some menu things # colors # red = 1 # green = 2 # yellow = 3 # blue = 4 function cprint () { color="$1" shift echo "$(tput setaf $color)$*$(tput sgr0)" } function mprint (){ echo " $1 - $2" } function incorrect_selection() { cprint 1 "Incorrect selection! Try again." } function press_enter() { echo "" cprint 3 "Press Enter to continue " read clear } function copy_config() { cprint 2 "Copying config files..." sleep 1 #cp -r /etc/ /tmp/ # create a temp folder tmpdir=$(mktemp -d) echo $tmpdir cp -r /etc/ $tmpdir apt list --installed | awk -F/ '{print $1}' > $tmpdir/installed_packages # From https://wiki.debian.org/AptCLI#apt-file # dpkg --get-selections >/backup/package-selections # apt install $(cat /backup/package-selections | awk '{print $1}') cprint 2 "Done!" } function cleanup() { cprint 2 "Cleaning up..." sleep 1 rm -rf $tmpdir } # Check for root only important on pure Debian as there is no sudo by default if [ "$(id -u)" != "0" ]; then # check is the system is debian if [ -f /etc/debian_version ]; then cprint 3 "Notice: This script may need to be run as root on Debian, especially if its a stock install" ; press_enter ; fi fi until [ "$selection" = "0" ]; do clear echo "" cprint 3 " Main Menu" mprint 1 "Copy the system config" mprint 2 "Restore the system config" mprint 0 "Exit" echo "" echo -n " Enter selection: " read selection echo "" case $selection in 1 ) clear ; copy_config ; press_enter ;; 2 ) clear ; menu_option_two ; press_enter ;; 0 ) clear ; cleanup ; exit ;; * ) clear ; incorrect_selection ; press_enter ;; esac done