Added new os style hooked agents

This commit is contained in:
Eric Renfro 2021-09-04 09:17:00 -04:00
parent a120d4a8b5
commit 5bf03bc0a4
Signed by: psi-jack
GPG key ID: 14977F3A50D9A5BF
7 changed files with 322 additions and 0 deletions

29
scripts/gitea Normal file
View file

@ -0,0 +1,29 @@
#!/bin/bash
restoreDir=/etc/restore
giteaDir="$restoreDir/gitea"
hook_check() {
if [[ -d "$giteaDir" ]]; then
rm -rf "$giteaDir" || exit 1
fi
}
hook_pre() {
backupDate=$(date +"%Y-%m-%d")
giteaHome=$(getent passwd git | cut -f6 -d:)
mkdir -p "$giteaDir"
sudo -u git "${giteaHome}/bin/gitea" dump --type tar.xz --file - > "${giteaDir}/gitea-dump-${backupDate}.tar.xz"
}
hook_post() {
rm -rf "$giteaDir" || exit 1
}
case "$1" in
before_check) hook_check;;
before_backup) hook_pre;;
after_backup) hook_post;;
esac

75
scripts/os Executable file
View file

@ -0,0 +1,75 @@
#!/bin/bash
restoreDir="/etc/restore"
kernel="$(uname -s)"
scriptPath="$(dirname "$(readlink -f "$0")")"
if [[ "$kernel" == "Darwin" ]]; then
restoreDir="${HOME}/restore"
fi
createRestoreDir() {
if [[ -d "${restoreDir}" ]]; then
rm -rf "${restoreDir}" || exit 2
fi
mkdir -p "${restoreDir}" || exit 2
}
checkOS() {
if [[ "$kernel" == "Darin" ]]; then
return 0
elif [[ "$kernel" == "Linux" ]]; then
if [[ -f /etc/os-release ]]; then
source /etc/os-release
return 0
else
echo "Unknown Linux Distribution"
return 1
fi
fi
return 1
}
runOsHook() {
local hook="$1"
if [[ "$kernel" == "Darwin" ]]; then
"${scriptPath}/os_macos" "$hook"
elif [[ "$kernel" == "Linux" ]]; then
case "$ID" in
debian) "${scriptPath}/os_debian" "$hook";;
fedora) "${scriptPath}/os_fedora" "$hook";;
solus) "${scriptPath}/os_solus" "$hook";;
opensuse-leap) "${scriptPath}/os_suse" "$hook";;
opensuse-tumbleweed) "${scriptPath}/os_suse" "$hook";;
esac
fi
return $?
}
hook_check() {
checkOS || exit 200
runOsHook before_check
}
hook_pre() {
hook_check || exit 200
createRestoreDir || exit $?
runOsHook before_backup
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check || exit $?;;
before_backup) hook_pre || exit $?;;
after_backup) hook_post || exit $?;;
esac

65
scripts/os_debian Normal file
View file

@ -0,0 +1,65 @@
#!/bin/bash
restoreDir="/etc/restore"
hook_check() {
if [[ -d "$restoreDir" ]]; then
rm -rf "$restoreDir" || 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
rsync -avhHi /etc/apt/trusted.gpg.d /etc/restore/
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 -l 'rsync' &>/dev/null || install+=" rsync"
dpkg-query -l 'aptitude' &>/dev/null || install+=" aptitude"
dpkg-query -l 'borgbackup' &>/dev/null || install+=" borgbackup"
dpkg-query -l 'borgmatic' &>/dev/null || install+=" borgmatic"
if [[ -n "\$install" ]]; then
apt -y install \$install
fi
rsync --ignore-existing -raz trusted.gpg.d/ /etc/apt/trusted.gpg.d/
xargs aptitude --schedule-only install < InstallOnly.list
aptitude install
EOF
popd || exit 2
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check || exit $?;;
before_backup) hook_pre || exit $?;;
after_backup) hook_post || exit $?;;
esac

41
scripts/os_fedora Normal file
View file

@ -0,0 +1,41 @@
#!/bin/bash
restoreDir="/etc/restore"
hook_check() {
if [[ -d "$restoreDir" ]]; then
rm -rf "$restoreDir" || exit 1
fi
}
hook_pre() {
mkdir -p "$restoreDir" || exit 1
pushd "$restoreDir" || exit 2
rpm -qa | sort > Package.versions.list
rpm -qa --queryformat '%{NAME}.%{ARCH}\n' | sort > Package.list
cat > restore.sh <<EOF
#!/bin/bash
if [[ ! -f "Package.list" ]]; then
echo "This needs to be run inside the restore directory."
exit 1
fi
dnf install \$(cat Package.list)
EOF
popd || exit 2
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check;;
before_backup) hook_pre;;
after_backup) hook_post;;
esac

42
scripts/os_macos Normal file
View file

@ -0,0 +1,42 @@
#!/bin/bash
restoreDir="$HOME/.borgmatic/restore"
hook_check() {
if [[ -d "$restoreDir" ]]; then
rm -rf "$restoreDir" || exit 1
fi
}
hook_pre() {
mkdir -p "$restoreDir" || exit 1
pushd "$restoreDir" || exit 2
brew bundle dump || exit 3
cat > restore.sh <<EOF
#!/bin/bash
if which brew; then
echo "Installing Homebrew Bundle"
brew bundle
else
echo "Install Homebrew first using the following:"
echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)'
echo "Re-run restore.sh after installing Homebrew to install Homebrew Bundle"
fi
EOF
popd || exit 2
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check || exit $?;;
before_backup) hook_pre || exit $?;;
after_backup) hook_post || exit $?;;
esac

29
scripts/os_solus Normal file
View file

@ -0,0 +1,29 @@
#!/bin/bash
restoreDir="/etc/restore"
hook_check() {
if [[ -d "$restoreDir" ]]; then
rm -rf "$restoreDir" || exit 1
fi
}
hook_pre() {
mkdir -p "$restoreDir" || exit 1
pushd "$restoreDir" || exit 2
eopkg li > Packages.list
popd || exit 2
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check;;
before_backup) hook_pre;;
after_backup) hook_post;;
esac

41
scripts/os_suse Normal file
View file

@ -0,0 +1,41 @@
#!/bin/bash
restoreDir="/etc/restore"
hook_check() {
if [[ -d "$restoreDir" ]]; then
rm -rf "$restoreDir" || exit 1
fi
}
hook_pre() {
mkdir -p "$restoreDir" || exit 1
pushd "$restoreDir" || exit 2
rpm -qa | sort > Package.versions.list
rpm -qa --queryformat '%{NAME}\n' | sort > Package.list
cat > restore.sh <<EOF
#!/bin/bash
if [[ ! -f "Package.list" ]]; then
echo "This needs to be run inside the restore directory."
exit 1
fi
cat Package.list | xargs zypper install
EOF
popd || exit 2
}
hook_post() {
rm -rf "$restoreDir"
}
case "$1" in
before_check) hook_check;;
before_backup) hook_pre;;
after_backup) hook_post;;
esac