#!/bin/bash #Script to backup all important environment files source /home/shmick/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 $(basename $1) - $(date)" git push elif [[ -z $(git ls-files | grep $(basename $1)) ]]; then git add $CONF_DIR/$(basename $1) -f git commit $CONF_DIR/$(basename $1) -m "Adding file $(basename $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/docker/daemon.json conf_sync /etc/environment conf_sync /etc/fstab conf_sync /etc/hosts conf_sync /etc/postfix/main.cf conf_sync /etc/profile for conf in $(ls /etc/snapper/configs/* 2> /dev/null); do conf_sync $conf done for conf in $(ls /etc/systemd/system/Murchison*); do conf_sync $conf done for conf in $(ls /etc/systemd/system/Kumonoboru*); do conf_sync $conf done #Fix permissions chown -R shmick $CONF_DIR