added config checks

This commit is contained in:
snaki 2022-07-12 12:50:08 +02:00
parent 1c3b17ee3f
commit e43bdd9458

32
btrbk
View file

@ -81,9 +81,9 @@ function runFullRestore {
fi
done
if ! [ -e "/etc/btrbk.conf" ]; then
rclone copy $rcloneDir"config/btrbk.conf" "/etc/"
rclone copy $rcloneDir"config/btrbk.conf" "/tmp/"
fi
source /etc/btrbk.conf
source /tmp/btrbk.conf
read -e -r -p "Import GPG key?[y/N]: " gpgtest
case "$gpgtest" in
[yY])
@ -92,7 +92,7 @@ function runFullRestore {
read -e -r -p "Secretkey: " gpgPriv
[ ! -f "$gpgPriv" ] && echo "Not a File" && continue
while true; do
read -e -r -p "Passphrase: " gpgPass
read -e -r -s -p "Passphrase: " gpgPass
gpg --pinentry-mode=loopback --passphrase "$gpgPass" --import $gpgPriv > /dev/null 2>&1 && break
echo "Wrong Passphrase or file is not a valid secret key"
done
@ -145,6 +145,8 @@ function getSnap {
function testConf {
source /etc/btrbk.conf
[[ "${RCLONEDIR}" != */ ]] && RCLONEDIR="${RCLONEDIR}/"
[[ "${SNAPDIR}" != */ ]] && SNAPDIR="${SNAPDIR}/"
if [ -z ${rDate+x} ]; then
if ! date -d "$rDate" > /dev/null 2>&1; then
echo "date is in wrong format: YYYY-MM-DD"
@ -170,10 +172,13 @@ function testConf {
}
function testDate {
if [ $BKCYCLE = "weekly" ]; then
if [ "$BKCYCLE" = "weekly" ]; then
local dateType = "+%u"
elif [ $BKCYCLE = "monthly" ]; then
elif [ "$BKCYCLE" = "monthly" ]; then
local dateType = "+%d"
else
echo "BKCYCLE not correctly configured"
exit 1
fi
for i in ${!BKRETENTION[@]}; do
if [ `date $dateType` = ${BKRETENTION[$i]} ]; then
@ -183,6 +188,13 @@ function testDate {
bkRun "incremental"
}
function testRoot {
if ! [ $(id -u) = 0 ]; then
echo "Please run with root privileges"
exit 2
fi
}
function end {
echo "finished in $(( ($(date +%s) - startDate) / 60 )) min"
exit 0
@ -202,7 +214,7 @@ function echoHelp {
exit 1
}
options=$(getopt -l "backup,force,date::,restore::,full-restore::,help" -o "bfx::h" -- "$@")
options=$(getopt -l "backup,force,date::,restore::,full-restore::,help" -o "bfh" -- "$@")
eval set -- "$options"
for i in ${!options[@]}; do
case $1 in
@ -219,7 +231,13 @@ for i in ${!options[@]}; do
done
if [ "$fullRestore" = true ]; then
testRoot
runFullRestore
else
elif [ "$backup" = true ] || [ "$restore" = true ]; then
testRoot
testConf
else
echo "No valid option given."
echo "Try 'btrbk --help' for more information."
exit 2
fi