From 4a754e72384c7fad4db6e3adfe5ca2ebeee083a2 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Sun, 17 May 2020 15:25:27 +0100 Subject: [PATCH] Updated package_save to use here-documents and save/restore apt keyring --- VPS/package_save.sh | 57 ++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/VPS/package_save.sh b/VPS/package_save.sh index 25908b1..2841e31 100755 --- a/VPS/package_save.sh +++ b/VPS/package_save.sh @@ -10,7 +10,7 @@ if [ $# -ne 0 ]; then if [ "$2" = here -o "$1" = here ]; then location="." elif [ ! -z "$2" ]; then - echo "Second argument can be void or 'here' only" + echo "Second argument can only be null or 'here'" exit fi fi @@ -19,45 +19,54 @@ cd $location pathName="$name""_$(date +'%Y-%m-%d @ %Hh%M')" mkdir "$pathName" -cd "./$pathName" +cd "$pathName" mkdir "./preferences.d" cp /etc/apt/sources.list . cp /etc/apt/preferences.d/my_preferences ./preferences.d/ cp -r --copy-contents /etc/apt/sources.list.d . -sudo dpkg --get-selections > "manual_package_save" +dpkg --get-selections > "manual_package_save" +apt-key exportall > "apt_keys" a=C4.sh -echo "#! /bin/bash" > $a -echo "" >> $a -echo "cd .." >> $a -echo "rm -r \"$pathName\"" >> $a +cat < "$a" +#! /bin/bash + +cd .. +rm -r "$pathName" + +EOF chmod u+x "$a" b="package_restore.sh" -echo "#! /bin/bash" > $b -echo "" >> $b -echo 'if [ $(id -u) -ne "0" ]; then' >> $b -echo ' echo "Please execute with superuser privileges"' >> $b -echo " exit -1" >> $b -echo fi >> $b -echo "" >> $b -echo cp ./sources.list /etc/apt/sources.list >> $b -echo cp ./preferences.d/my_preferences /etc/apt/preferences.d/my_preferences >> $b -echo 'cp -r ./sources.list.d/* /etc/apt/sources.list.d' >> $b -echo "" >> $b -echo apt-get update >> $b -echo apt-get install dselect >> $b -echo "dpkg --set-selections < "manual_package_save"" >> $b -echo apt-get dselect-upgrade >> $b -echo apt-get remove dselect >> $b +cat < "$b" +#! /bin/bash" + +if [ $(id -u) -ne "0" ]; then + echo "Please execute with superuser privileges" + exit - +fi + +cp ./sources.list /etc/apt/sources.list +cp ./preferences.d/my_preferences /etc/apt/preferences.d/my_preferences +cp -r ./sources.list.d/* /etc/apt/sources.list.d' + +apt-key add < "apt_keys" +apt-get update +apt-get install dselect +dselect update +dpkg --set-selections < "manual_package_save" +apt-get dselect-upgrade -y +apt-get remove dselect + +EOF chmod u-x "$b" cd - -exit \ No newline at end of file +exit