Skip to content

Instantly share code, notes, and snippets.

@brainwater
Created November 18, 2012 20:45
Show Gist options
  • Save brainwater/4107319 to your computer and use it in GitHub Desktop.
Save brainwater/4107319 to your computer and use it in GitHub Desktop.
vcvm git sync program using spiped
#!/bin/sh
# post update hook for repositories so that clients will be notified of repository updates
CHANGEDREPO="$(echo "${PWD}" | sed -e "s_^/[^/]*/[^/]*/vcvm__")"
logger -t "${0}" -i "Updated repo ${CHANGEDREPO}"
echo "${CHANGEDREPO}" >> /srv/vcvm/ctl/repo-updates
#!/bin/bash
# Client side daemon that syncs the repositories
userconfigfile="${HOME}/.config/vcvm/vcvm-settings"
sysconfigfile="/etc/vcvm/vcvm-settings"
userhostfile="${HOME}/.config/vcvm/vcvm-host"
syshostfile="/etc/vcvm/vcvm-host"
if [ -e "${userconfigfile}" ]
then
source "${userconfigfile}"
elif [ -e "${sysconfigfile}" ]
then
source "${sysconfigfile}"
else
echo "No vcvm settings file exists, exiting"
logger -t "${0}" -i "No vcvm config file, exiting"
exit 1
fi
if [ -e "${userhostfile}" ]
then
source "${userhostfile}"
elif [ -e "${syshostfile}" ]
then
source "${syshostfile}"
else
echo "No vcvm host file exists, exiting"
logger -t "${0}" -i "No vcvm host file, exiting"
exit 1
fi
monitor-sync()
{
while read inputvar
do
echo
echo "${inputvar}"
changedrepo="$(echo "${inputvar}" | sed -e "s/\.\./asdfasdf/g" -e "s/\.git$//" -e "s_^/home/__" -e "s_^_${HOME}/_")"
echo "${changedrepo}"
if [ -d "${changedrepo}" ]
then
cd "${changedrepo}"
git pull --ff-only "ext::vcvm-connect ${inputvar}"
fi
done
}
spipe -t "${vcvmaddr}:${vcvmupdateport}" -k "${vcvmkeyfile}" | monitor-sync
# When the raspberry pi is turned off, the connections are severed, so we want to keep trying until it is turned back on
echo
echo "Disconnected, retrying in ${vcvmretrytime}"
sleep "${vcvmretrytime}"
exec "${0}"
#!/bin/bash
# Server side daemon
vcvmsrvcfgfile="/etc/vcvm/vcvm-srv-settings"
if [ -e "${vcvmsrvcfgfile}" ]
then
source "${vcvmsrvcfgfile}"
else
logger -t "${0}" -i "No vcvm server config file, exiting"
fi
# Decrypts incoming git pushes (this has nothing to do with the notifications)
spiped -p "${vcvmspipedpidfile}" -d -s [0.0.0.0]:"${vcvmport}" -t localhost:"${vcvmlocalport}" -k "${vcvmkeyfile}"
# Encrypts outgoing repo update notifications
spiped -d -s [0.0.0.0]:"${vcvmupdateport}" -t [127.0.0.1]:"${vcvmupdatelocalport}" -k "${vcvmkeyfile}"
# Handles decrypted incoming git pushes (this has nothing to do with the notifications)
socat tcp-l:"${vcvmlocalport}",reuseaddr,fork,range=127.0.0.1/32 system:'vcvm-receive',nofork &
# Notifies clients of repo updates
socat tcp-l:${vcvmupdatelocalport},reuseaddr,fork,range=127.0.0.1/32 system:'tail -n 1 -f /srv/vcvm/ctl/repo-updates',nofork
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment