-
-
Notifications
You must be signed in to change notification settings - Fork 157
Tombautosyncviasshfs
nignux edited this page Feb 12, 2012
·
30 revisions
######################DISCLAIMER######################
THE CODE IN THIS PAGE IS HORRIBLE AND DISGUSTING!!!
READ TI JUST IF YOU UNDERSTAND IT AND YOU WANT TO DEBUG
######################################################
###Scenario
We have two laptop: a big one and a netbook and we need to share a tomb with personal settings and data.
###Description
unfortunately, we can't just use a "shared" tomb, because tomb cannot be mounted by more than one computer. Furthermore, tomb has (still) no way to use a lock. So, we need to do it ourselves with an external lock (just aside to the tomb).
What we do is (periodically):
- acquiring the lock
- mounting the remote tomb
- using unison to do sync
- unmounting
- releasing the lock
###The HORRIBLE code
#/bin/bash
# LOGIN SCRIPT
remotetomb="/media/remote.tomb/"
localtomb="/media/local.tomb/
remotelock="/local/mountpoint/tomb.lock"
export imgpath=`zenity --file-selection --text='Seleziona il file da cui estrarre la chiave' --title='Seleziona un file immagine'`
tomb exhume $imgpath /tmp/local.tomb
(flock 5
if ! tomb open /path/to/local.tomb -k /tmp/local.tomb.key; then
zenity --error --text='Non sono riuscito a montare la tomba locale!' --title='Orrore!'
return 1
fi
zenity --notification --text='Tomba locale montata correttamente'
if sshfs remote.server:/ /local/mountpoint/; then
tomb open /local/mountpoint/remote.tomb -k /tmp/local.tomb.key
zenity --notification --text=zenity --notification --text=''Tomba remota montata correttamente'
else
zenity --error --text='Non ho potuto montare la tomba remota!' --title='Orrore!'
return 1
fi
) 5> $lockfile
# POST-HOOK IN REMOTE TOMB
remotetomb="/media/remote.tomb/"
localtomb="/media/local.tomb/
if unison $remotetomb $localtomb;then
zenity --notification --text='Dati sincronizzati con successo' --title='Ok!'
else
zenity --error --text='Non sono riuscito a sincronizzare i dati!' --title='Orrore!'
return 1
fi
#LOGOUT SCRIPT
lockfile="/local/mountpoint/tomb.lock"
wipe -f -s /tmp/local.tomb.key
(flock 5
if tomb close all; then
zenity --notification --text=zenity --notification --text=''Tombe smontate correttamente'
else
zenity --error --text='Non sono riuscito a smontare le tombe!' --title='Orrore!'
return 1
fi
) 5> $lockfile
# CRON SCRIPT
remotetomb="/media/remote.tomb/"
localtomb="/media/local.tomb/
lockfile="/local/mountpoint/tomb.lock"
(flock 5
if !ping -c 1 lab.olocolors.org;then
return 1
elif !mountpoint /local/mountpoint/; then
if sshfs remote.server:/ /local/mountpoint/; then
tomb open /local/mountpoint/remote.tomb -k /tmp/local.tomb.key;
unison $remotetomb $localtomb;
fi
fi
) 5> $lockfile