Command: cat /tmp/gordboy-clone3-debian.txt #!/bin/bash # CLONE - clone a debian/ubuntu install ###################################################################### # At the end, all packages will be identical to the list in : # /usr/local/backup/ALL (if it exists) # # All missing Extras packages will be installed from the list in : # /usr/local/backup/EXTRAS (if it exists) # # /usr/local/backup/extras *must* contain EXTRAS packages which # have unique names up to the first _ (underscore), matching the # package names in EXTRAS package list # # All required repos *must* be active in : # /etc/apt/sources.list (or wherever) # # and all required repo GPG/PGP keys *must* be imported # # apt transactions logged to ~/APTLOG ###################################################################### backup_dir=/usr/local/backup extradir=${backup_dir}/extras # sanity checks if [[ ! $(type -t dpkg) ]]; then echo "CLONE: dpkg program not found" exit 1 fi if [[ ! $(type -t awk) ]]; then echo "CLONE: awk program not found" exit 1 fi if [[ ! $(type -t comm) ]]; then echo "CLONE: comm program not found" exit 1 fi if [[ ! $(type -t apt-get) ]]; then echo "CLONE: apt-get program not found" exit 1 fi ################################################################## do_extras_exit() { if [[ "$extras" == "yes" ]]; then echo "CLONE: EXTRAS package list found" # no need to get current again extra_list=$(comm -13 <(echo "$current") ${backup_dir}/EXTRAS) if [[ "$extra_list" ]]; then echo 'CLONE: Installing' $(echo "$extra_list" | wc -l) 'extra package(s) :' echo echo $extra_list echo for p in $extra_list ; do package_deb=$(echo ${extradir}/${p}_*) if [[ "${package_deb: -1}" = "*" ]]; then echo 'CLONE:' package $p not found else if [[ "$package_deb" =~ " " ]]; then echo 'CLONE:' more than one debfile matches package $p else dpkg --force-all -i $package_deb > /dev/null 2>&1 fi fi done echo "CLONE: Extras cloning complete" else echo "CLONE: Extras already installed" fi else echo "CLONE: EXTRAS package list not found" fi exit } ################################################################## # get current (clean install ?) package list current=$(dpkg --get-selections | awk '{print $1}') if [[ -f ${backup_dir}/EXTRAS ]]; then extras=yes else extras=no fi if [[ -f ${backup_dir}/ALL ]]; then echo "CLONE: ALL package list found" else echo "CLONE: ALL package list not found" do_extras_exit fi # get allbase (ALL except EXTRAS) package list if [[ "$extras" == "yes" ]]; then allbase=$(comm -13 ${backup_dir}/EXTRAS ${backup_dir}/ALL) else allbase=$(cat ${backup_dir}/ALL) fi # get currentbase (current except EXTRAS) package list if [[ "$extras" == "yes" ]]; then currentbase=$(comm -13 ${backup_dir}/EXTRAS <(echo "$current")) else currentbase=$current fi # check to see if we are already done if [[ ! $(diff <(echo "$currentbase") <(echo "$allbase")) ]]; then echo "CLONE: Base cloning already done" do_extras_exit fi # remove old APTLOG rm -f ~/APTLOG # remove unwanted (in currentbase but not allbase) packages unwanted=$(comm -13 <(echo "$allbase") <(echo "$currentbase")) # don't try with empty list if [[ "$unwanted" ]]; then echo 'CLONE: Purging' $(echo "$unwanted" | wc -l) 'unwanted package(s) :' echo echo $unwanted echo apt-get -y purge $unwanted >> ~/APTLOG 2>&1 else echo "CLONE: No unwanted packages" fi # update packages echo "CLONE: Updating packages" apt-get -y update >> ~/APTLOG 2>&1 # add missing (in allbase but not currentbase) packages # no need to get currentbase again missing=$(comm -13 <(echo "$currentbase") <(echo "$allbase")) # don't try with empty list if [[ "$missing" ]]; then echo 'CLONE: Installing' $(echo "$missing" | wc -l) 'missing package(s) :' echo echo $missing echo apt-get -y install $missing >> ~/APTLOG 2>&1 else echo "CLONE: No missing packages" fi # clear cache echo "CLONE: Clearing apt cache" apt-get clean >> ~/APTLOG 2>&1 apt-get autoclean >> ~/APTLOG 2>&1 echo "CLONE: Base cloning complete" do_extras_exit