#!/bin/bash dir="/var/tmp/portage/config/conf/$(hostname)" username="ctibor" root=/ repo="ssh://git@git.brancik.cz/rpi-config.git" if [ $# != 1 ]; then echo "Usage: sync-config . Action can be either pull or push" exit 1 fi function check_repo { if [ ! -d /var/tmp/portage/config/.git ]; then echo "Cloning repository with config files." mkdir -p /var/tmp/portage chown ${username}:${username} /var/tmp/portage /bin/su ${username} --command="/usr/bin/git clone --depth=1 ${repo} /var/tmp/portage/config" fi } case $1 in push) check_repo /bin/su ${username} --command="/usr/bin/git pull" echo "Pushing config files to overlay folder ..." /usr/bin/rsync -v --files-from /etc/portage/filelist_sync --recursive ${root} ${dir} -- cd ${dir} /bin/su ${username} --command="/usr/bin/git add ." /bin/su ${username} --command="/usr/bin/git commit -a -m \"Update portage config for mizar $(date +%Y%m%d-%H%M%S)\"" /bin/su ${username} --command="/usr/bin/git push";; pull) check_repo cd ${dir} /bin/su ${username} --command="/usr/bin/git pull" echo "Pulling config files from overlay folder ..." /usr/bin/rsync -v --files-from /etc/portage/filelist_sync --recursive ${dir} ${root} --;; *) echo "Usage: sync-config . Action can be either pull or push" exit 1 esac