updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / sync-browsersd / sync-browsers
blob8b6723a0f445b8a550ec69bee19f7bc94870a28f
1 #!/bin/bash
2 # Script by graysky <graysky AT archlinux DOT us>
3 # Adapted from a script by Colin Verot at http://www.verot.net/firefox_tmpfs.htm
5 . /etc/sync-browsersd.conf
7 sync() {
8 for user in $USERS; do
9 for i in mozilla chromium; do
10 [[ "$i" = "mozilla" ]] && STATIC="/home/$user/.$i-backup" && LINK="/home/$user/.$i"
11 [[ "$i" = "chromium" ]] && STATIC="/home/$user/.config/$i-backup" && LINK="/home/$user/.config/$i"
13 # check if user has browser profile
14 if [[ -d $LINK ]]; then
15 [[ -r "$VOLATILE/$user-$i" ]] || su -c "install -dm755 $VOLATILE/$user-$i" $user
17 # backup profile and link to tmpfs
18 if [[ $(readlink "$LINK") != "$VOLATILE/$user-$i" ]]; then
19 mv $LINK $STATIC
20 ln -s $VOLATILE/$user-$i $LINK
23 # sync the RAM profile to the disc
24 if [[ -e $LINK/.flagged ]]; then
25 su -c "rsync -a --delete --exclude .flagged $LINK/ $STATIC/" $user
26 else
27 su -c "rsync -a $STATIC/ $LINK/" $user
28 su -c "touch $LINK/.flagged" $user
30 else
31 /bin/true
33 done
34 done
37 unsync() {
38 for user in $USERS; do
39 for i in mozilla chromium; do
40 [[ "$i" = "mozilla" ]] && STATIC="/home/$user/.$i-backup" && LINK="/home/$user/.$i"
41 [[ "$i" = "chromium" ]] && STATIC="/home/$user/.config/$i-backup" && LINK="/home/$user/.config/$i"
43 # check if user has browser profile
44 if [[ -h $LINK ]]; then
45 rm -f $LINK
46 [[ -d $STATIC ]] && mv $STATIC $LINK
47 [[ -d "$VOLATILE/$user-$i" ]] && rm -rf $VOLATILE/$user-$i
48 else
49 /bin/true
51 done
52 done
55 case "$1" in
56 sync)
57 [[ -f /run/daemons/sync-browsersd ]] && sync
59 unsync)
60 [[ -f /run/daemons/sync-browsersd ]] && unsync
63 [[ -f /run/daemons/sync-browsersd ]] && echo "You should not call this script directly, let the /etc/rc.d/sync-browsersd do it for you!" && exit 1
64 esac
65 exit 0