78 lines
1.9 KiB
Bash
Executable file
78 lines
1.9 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
restoreDir="/etc/restore"
|
|
|
|
function is_bin_in_path {
|
|
builtin type -P "$1" &>/dev/null
|
|
}
|
|
|
|
hook_check() {
|
|
if ! is_bin_in_path aptitude; then
|
|
echo "aptitude needs to be installed for backups to work properly."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
hook_pre() {
|
|
mkdir -p "$restoreDir" || exit 1
|
|
pushd "$restoreDir" || exit 2
|
|
|
|
dpkg --get-selections > Package.list
|
|
aptitude search --disable-columns -F%p '~i!~M!~v' > InstallOnly.list
|
|
#apt-key exportall > /etc/restore/Repo.keys
|
|
cp -a /etc/apt/sources.list "$restoreDir/"
|
|
rsync -avhHi /etc/apt/sources.list.d "$restoreDir/"
|
|
rsync -avhHi /etc/apt/trusted.gpg.d "$restoreDir/"
|
|
|
|
cat > restore.sh <<EOF
|
|
#!/bin/bash
|
|
|
|
if [[ ! -f "InstallOnly.list" ]]; then
|
|
echo "This needs to be run inside the restore directory."
|
|
exit 1
|
|
fi
|
|
if [[ ! -d "trusted.gpg.d" ]]; then
|
|
echo "This needs to be run inside the restore directory."
|
|
exit 1
|
|
fi
|
|
|
|
#apt-key add /etc/restore/Repo.keys
|
|
#dpkg --set-selections < /etc/restore/Package.list
|
|
#apt-get dselect-upgrade
|
|
|
|
install=""
|
|
|
|
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 'borgmatic' &>/dev/null || install+=" borgmatic"
|
|
|
|
if [[ -n "\$install" ]]; then
|
|
apt -y install \$install
|
|
fi
|
|
|
|
grep ':i386' InstallOnly.list &>/dev/null && dpkg --add-architecture i386
|
|
|
|
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/
|
|
|
|
apt update
|
|
|
|
xargs aptitude --schedule-only install < InstallOnly.list
|
|
aptitude install
|
|
EOF
|
|
|
|
popd || exit 2
|
|
}
|
|
|
|
hook_post() {
|
|
:
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
before_check) hook_check || exit $?;;
|
|
before_backup) hook_pre || exit $?;;
|
|
after_backup) hook_post || exit $?;;
|
|
esac
|