Logging and clearer git updates - yay!

This commit is contained in:
2021-12-18 16:48:08 +02:00
parent 54b2099ed5
commit 0aeac860da

47
ConfigBackup Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
#Script to backup all important environment files
source /etc/environment
source $SCRIPTS/Okiru
logging "ConfigBackup"
export CONF_DIR="/home/shmick/Config"
if [[ ! -d $CONF_DIR ]]; then
debug "Cloning Configuration directory in $CONF_DIR"
if git clone ssh://git@git.pukeko.xyz:64278/shmick/Configuration $CONF_DIR; then
ok "Repository cloned succesfully!"
else
error "Error cloning configuration repository!"
exit 1
fi
else
debug "$CONF_DIR exists; moving on"
fi
##Conf_sync function - if a file exists on filesystem, update in configuration dir;
#+Otherwise, restore it from configuration dir.
conf_sync () {
if [[ -f "$1" ]]; then
info "Copying $1 to configuration directory $CONF_DIR"
rsync -aHAXSvczu "$1" "$CONF_DIR"
cd $CONF_DIR
if [[ -n $(git diff origin/master $(basename $1)) ]]; then
info "Updating changes in file $1"
git commit -am "Auto updating $1 - $(date)"
git push
else
debug "No changes detected in $1"
fi
elif [[ ! -f "$1" ]]; then
warn "$1 does not exist - restoring from configuration directory $CONF_DIR"
rsync -aHAXSvcz "$CONF_DIR/$(basename $1)" "$1"
fi
}
#Configuration files to sync
conf_sync /etc/ddclient.conf $CONF_DIR
for tab in $(ls /var/spool/cron/tabs/*); do
conf_sync $tab
done
conf_sync /etc/environment
conf_sync /etc/hosts
conf_sync /etc/postfix/main.cf
#Fix permissions
chown -R shmick $CONF_DIR