Merge pull request 'feature/os-debian-no-aptitude' (#1) from feature/os-debian-no-aptitude into master
Reviewed-on: #1
This commit is contained in:
commit
e70d631839
3 changed files with 79 additions and 58 deletions
14
scripts/os
14
scripts/os
|
@ -12,14 +12,14 @@ fi
|
||||||
|
|
||||||
createRestoreDir() {
|
createRestoreDir() {
|
||||||
if [[ -d "${restoreDir}" ]]; then
|
if [[ -d "${restoreDir}" ]]; then
|
||||||
rm -rf "${restoreDir}/*" || exit 2
|
rm -rf "${restoreDir:?}/*" || exit 2
|
||||||
else
|
else
|
||||||
mkdir -p "${restoreDir}" || exit 2
|
mkdir -p "${restoreDir}" || exit 2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
checkOS() {
|
checkOS() {
|
||||||
if [[ "$kernel" == "Darin" ]]; then
|
if [[ "$kernel" == "Darwin" ]]; then
|
||||||
return 0
|
return 0
|
||||||
elif [[ "$kernel" == "Linux" ]]; then
|
elif [[ "$kernel" == "Linux" ]]; then
|
||||||
if [[ -f /etc/os-release ]]; then
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
@ -27,7 +27,7 @@ checkOS() {
|
||||||
DISTRO="$ID"
|
DISTRO="$ID"
|
||||||
DISTRO_CURRENT="$DISTRO"
|
DISTRO_CURRENT="$DISTRO"
|
||||||
if [[ -n "$ID_LIKE" ]]; then
|
if [[ -n "$ID_LIKE" ]]; then
|
||||||
DISTRO="$ID_LIKE"
|
DISTRO="${ID_LIKE%% *}"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
@ -45,9 +45,9 @@ runOsHook() {
|
||||||
"${scriptPath}/os_macos" "$hook"
|
"${scriptPath}/os_macos" "$hook"
|
||||||
elif [[ "$kernel" == "Linux" ]]; then
|
elif [[ "$kernel" == "Linux" ]]; then
|
||||||
case "$DISTRO" in
|
case "$DISTRO" in
|
||||||
debian) "${scriptPath}/os_debian" "$hook";;
|
debian|ubuntu) "${scriptPath}/os_debian" "$hook";;
|
||||||
fedora) "${scriptPath}/os_fedora" "$hook";;
|
fedora) "${scriptPath}/os_fedora" "$hook";;
|
||||||
garuda) "${scriptPath}/os_garuda" "$hook";;
|
arch) "${scriptPath}/os_arch" "$hook";;
|
||||||
solus) "${scriptPath}/os_solus" "$hook";;
|
solus) "${scriptPath}/os_solus" "$hook";;
|
||||||
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
|
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
|
||||||
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
|
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
|
||||||
|
@ -62,10 +62,10 @@ runOsHook() {
|
||||||
|
|
||||||
hook_before() {
|
hook_before() {
|
||||||
checkOS || exit 200
|
checkOS || exit 200
|
||||||
pushd "$scriptPath" &>/dev/null
|
pushd "$scriptPath" &>/dev/null || exit 201
|
||||||
git checkout -- .
|
git checkout -- .
|
||||||
git pull
|
git pull
|
||||||
popd &>/dev/null
|
popd &>/dev/null || exit 201
|
||||||
|
|
||||||
createRestoreDir || exit $?
|
createRestoreDir || exit $?
|
||||||
runOsHook before
|
runOsHook before
|
||||||
|
|
|
@ -7,11 +7,6 @@ function is_bin_in_path {
|
||||||
}
|
}
|
||||||
|
|
||||||
hook_before() {
|
hook_before() {
|
||||||
if ! is_bin_in_path aptitude; then
|
|
||||||
echo "aptitude needs to be installed for backups to work properly."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! is_bin_in_path rsync; then
|
if ! is_bin_in_path rsync; then
|
||||||
echo "rsync needs to be installed for backups to work properly."
|
echo "rsync needs to be installed for backups to work properly."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -20,9 +15,8 @@ hook_before() {
|
||||||
mkdir -p "$restoreDir" || exit 1
|
mkdir -p "$restoreDir" || exit 1
|
||||||
pushd "$restoreDir" || exit 2
|
pushd "$restoreDir" || exit 2
|
||||||
|
|
||||||
dpkg --get-selections > Package.list
|
dpkg --get-selections | sort > Package.list
|
||||||
aptitude search --disable-columns -F%p '~i!~M!~v' > InstallOnly.list
|
apt-mark showmanual | sort > InstallOnly.list
|
||||||
#apt-key exportall > /etc/restore/Repo.keys
|
|
||||||
cp -a /etc/apt/sources.list "$restoreDir/"
|
cp -a /etc/apt/sources.list "$restoreDir/"
|
||||||
rsync -avhHi /etc/apt/sources.list.d "$restoreDir/"
|
rsync -avhHi /etc/apt/sources.list.d "$restoreDir/"
|
||||||
rsync -avhHi /etc/apt/trusted.gpg.d "$restoreDir/"
|
rsync -avhHi /etc/apt/trusted.gpg.d "$restoreDir/"
|
||||||
|
@ -40,70 +34,97 @@ if [[ ! -d "trusted.gpg.d" ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
TMPDIR="\$(mktemp -d -t restore-XXXX)"
|
||||||
|
bold="$(tput bold)"
|
||||||
|
normal="$(tput sgr0)"
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
[[ -n "\$TMPDIR" && -d "\$TMPDIR" ]] && rm -rf "\$TMPDIR"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
#apt-key add /etc/restore/Repo.keys
|
#apt-key add /etc/restore/Repo.keys
|
||||||
#dpkg --set-selections < /etc/restore/Package.list
|
#dpkg --set-selections < /etc/restore/Package.list
|
||||||
#apt-get dselect-upgrade
|
#apt-get dselect-upgrade
|
||||||
|
|
||||||
install=""
|
install=""
|
||||||
|
|
||||||
echo " * Installing required packages"
|
echo "\${bold} * Installing required packages\${normal}"
|
||||||
dpkg-query -s 'rsync' &>/dev/null || install+=" rsync"
|
dpkg-query -s 'rsync' &>/dev/null || install+=" rsync"
|
||||||
dpkg-query -s 'aptitude' &>/dev/null || install+=" aptitude"
|
#dpkg-query -s 'borgbackup' &>/dev/null || install+=" borgbackup"
|
||||||
dpkg-query -s 'borgbackup' &>/dev/null || install+=" borgbackup"
|
#dpkg-query -s 'borgmatic' &>/dev/null || install+=" borgmatic"
|
||||||
dpkg-query -s 'borgmatic' &>/dev/null || install+=" borgmatic"
|
|
||||||
dpkg-query -s 'apt-transport-https' &>/dev/null || install+=" apt-transport-https"
|
dpkg-query -s 'apt-transport-https' &>/dev/null || install+=" apt-transport-https"
|
||||||
|
|
||||||
if [[ -n "\$install" ]]; then
|
if [[ -n "\$install" ]]; then
|
||||||
apt -y install \$install
|
apt -y install \$install
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo " * Enabling 32-bit packages"
|
echo "\${bold} * Enabling 32-bit packages\${normal}"
|
||||||
grep ':i386' InstallOnly.list &>/dev/null && dpkg --add-architecture i386
|
grep ':i386' InstallOnly.list &>/dev/null && dpkg --add-architecture i386
|
||||||
|
|
||||||
echo " * Restoring repositories and keys"
|
echo "\${bold} * Checking for flatpak\${normal}"
|
||||||
cp -a sources.list /etc/apt/sources.list
|
|
||||||
rsync --ignore-existing -raz sources.list.d/ /etc/apt/sources.list.d/
|
|
||||||
rsync --ignore-existing -raz trusted.gpg.d/ /etc/apt/trusted.gpg.d/
|
|
||||||
[[ -d keyrings ]] && rsync --ignore-existing -raz keyrings/ /etc/apt/keyrings/
|
|
||||||
|
|
||||||
apt update
|
|
||||||
|
|
||||||
failinstall=""
|
|
||||||
flatpak=0
|
flatpak=0
|
||||||
|
grep 'flatpak' InstallOnly.list &>/dev/null && flatpak=1
|
||||||
echo " * Gathering installed packages"
|
|
||||||
#xargs aptitude --schedule-only install < InstallOnly.list
|
|
||||||
while read p; do
|
|
||||||
if [[ "\$p" = "flatpak" ]]; then
|
|
||||||
flatpak=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
dpkg-query -s "\$p" &>/dev/null
|
|
||||||
if [[ "\$?" -eq 1 ]]; then
|
|
||||||
aptitude --schedule-only install "\$p"
|
|
||||||
if [[ "\$?" -ne 0 ]]; then
|
|
||||||
if [[ -z "\$failinstall" ]]; then
|
|
||||||
failinstall+="\$p"
|
|
||||||
else
|
|
||||||
failinstall+=", \$p"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done < InstallOnly.list
|
|
||||||
|
|
||||||
echo "Packages that failed to schedule for install:"
|
|
||||||
echo "\$failinstall"
|
|
||||||
|
|
||||||
echo " * Restoring installed packages (please confirm)"
|
|
||||||
aptitude install
|
|
||||||
|
|
||||||
if [[ "\$flatpak" -eq 1 ]]; then
|
if [[ "\$flatpak" -eq 1 ]]; then
|
||||||
echo " * Adding flatpak repo: Flathub"
|
echo " * Adding flatpak repo: Flathub"
|
||||||
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
|
flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Packages that failed to schedule for install:"
|
if [[ -r "sources.list" ]]; then
|
||||||
echo "\$failinstall"
|
echo "\${bold}"
|
||||||
|
echo "=============================="
|
||||||
|
echo "INSTALL REPOS"
|
||||||
|
echo "=============================="
|
||||||
|
echo "\${normal}"
|
||||||
|
|
||||||
|
read -p "\${bold}Do you want to continue to install backup repositories? [Y/n]\${normal} " -n 1 -sr promptRepos
|
||||||
|
if [[ "\$promptRepos" =~ ^[Yy]$ ]]; then
|
||||||
|
echo "Yes"
|
||||||
|
cp -a sources.list /etc/apt/sources.list
|
||||||
|
rsync --ignore-existing -raz sources.list.d/ /etc/apt/sources.list.d/
|
||||||
|
rsync --ignore-existing -raz trusted.gpg.d/ /etc/apt/trusted.gpg.d/
|
||||||
|
[[ -d keyrings ]] && rsync --ignore-existing -raz keyrings/ /etc/apt/keyrings/
|
||||||
|
apt update
|
||||||
|
else
|
||||||
|
echo -e "Cancelled\n"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "\${bold}"
|
||||||
|
echo "=============================="
|
||||||
|
echo "INSTALL PACKAGES"
|
||||||
|
echo "=============================="
|
||||||
|
echo "\${normal}"
|
||||||
|
|
||||||
|
read -p "\${bold}About to install the system packages per the backup. Do you want to continue? [Y/n]\${normal} " -n 1 -sr promptPkgs
|
||||||
|
if [[ "\$promptPkgs" =~ ^[Yy] ]]; then
|
||||||
|
echo "Yes"
|
||||||
|
comm --nocheck-order -23 InstallOnly.list <(apt-mark showmanual|sort) | grep -Ev 'linux-image|linux-headers' > "\${TMPDIR}/diff.list"
|
||||||
|
apt-get --simulate install \$(cat "\${TMPDIR}/diff.list") |& awk '/^E: Unable to locate package / {print \$NF}' | sort > "\${TMPDIR}/diff.fail"
|
||||||
|
comm --nocheck-order -23 "\${TMPDIR}/diff.list" "\${TMPDIR}/diff.fail" | xargs apt-get install
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Packages that were omitted because they could not be found:"
|
||||||
|
cat "\${TMPDIR}/diff.fail" | tr '\n' ' ' | fold -s
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
|
||||||
|
read -p "\${bold}Did everything above look okay and do you want to proceed? [Y/n]\${normal} " -n 1 -sr promptPkgsDo
|
||||||
|
if [[ "\$promptPkgsDo" =~ ^[Yy] ]]; then
|
||||||
|
comm --nocheck-order -23 "\${TMPDIR}/diff.list" "\${TMPDIR}/diff.fail" | xargs apt-get install
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo "\${bold}Packages that failed to schedule for install:\${normal}"
|
||||||
|
cat "\${TMPDIR}/diff.fail" | tr '\n' ' ' | fold -s
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo -e "Cancelled\n"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "Cancelled\n"
|
||||||
|
fi
|
||||||
EOF
|
EOF
|
||||||
chmod ug+rx restore.sh
|
chmod ug+rx restore.sh
|
||||||
popd || exit 2
|
popd || exit 2
|
||||||
|
|
Loading…
Reference in a new issue