-
-
Notifications
You must be signed in to change notification settings - Fork 157
Tombautosyncviasshfs
Narrat edited this page Jun 23, 2023
·
30 revisions
######################DISCLAIMER######################
THE CODE IN THIS PAGE IS HORRIBLE AND DISGUSTING!!!
JUST USE IT IF YOU UNDERSTAND IT AFTER READING AND YOU WANT TO DEBUG
######################################################
We have two laptop: a big one and a netbook and we need to share a tomb with personal settings and data.
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
#!/bin/bash
# LOGIN SCRIPT
lockfile="/local/mountpoint/tomb.lock"
imgpath=`zenity --file-selection --text='Choose an image file whith an embedded key' --title='Select File'`
tomb exhume /tmp/local.tomb $imgpath
(flock 5
if ! tomb open /path/to/local.tomb -k /tmp/local.tomb.key; then
zenity --error --text='Imposible to mount local tomb!' --title='Horror!'
return 1
else
zenity --notification --text='Local tomb correctly mounted'
fi
if sshfs remote.server:/ /local/mountpoint/; then
tomb open /local/mountpoint/remote.tomb -k /tmp/local.tomb.key
zenity --notification --text='Remote tomb correctly mounted'
else
zenity --error --text='Impossible to mount remote tomb!' --title='Horror!'
return 1
fi
) 5> $lockfile
#!/bin/bash
# POST-HOOK IN REMOTE TOMB
remotetomb="/media/remote.tomb/"
localtomb="/media/local.tomb/"
if unison $remotetomb $localtomb;then
zenity --notification --text='Data sync success'
else
zenity --error --text='Data sync failed!' --title='Horror!'
return 1
fi
#!/bin/bash
#LOGOUT SCRIPT
lockfile="/local/mountpoint/tomb.lock"
wipe -f -s /tmp/local.tomb.key
(flock 5
if tomb close all; then
zenity --notification --text='Tombs closed your bones will rest in peace.'
else
zenity --error --text='Problems closing tombs!' --title='Horror!'
return 1
fi
) 5> $lockfile
#!/bin/bash
# CRON SCRIPT
remotetomb="/media/remote.tomb/"
localtomb="/media/local.tomb/"
lockfile="/local/mountpoint/tomb.lock"
(flock 5
if !ping -c 1 remote.server;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