-
Notifications
You must be signed in to change notification settings - Fork 0
/
fh-sync
executable file
·84 lines (66 loc) · 1.84 KB
/
fh-sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
#
# Synchronize the ram storage of flash hybrid with the drive.
# Loosely based on the init scripts of flashybrid 0.002. GPL v2.
#
# - Diego Iastrubni <[email protected]>
CONFDIR=/etc/flashybrid
is_mounted ()
{
grep -q " $1 " /proc/mounts
}
ENABLED=no
if [ -e /etc/default/flashybrid ]; then
. /etc/default/flashybrid
fi
#if [ "$ENABLED" != yes ]; then
# we ignore quietly the setups in which flash hybrid is not configured
# echo "Not syncing flashybrid system: disabled."
# exit
#fi
if [ -e $CONFDIR/config ]; then
. $CONFDIR/config
else
# we ignore quietly the setups in which flash hybrid is not configured
exit
fi
#if ! grep -q "$RAMMOUNT" /proc/mounts; then
if ! is_mounted "$RAMMOUNT" ; then
echo "Flashybrid is not started. Ignoring"
exit
fi
if [ -z "$RAMMOUNT" ]; then
exit 0
fi
echo -n "Syncing flashybrid system..."
# if verbose, make a new line feed,
# this way the first message will get a new line
if [ "$VERBOSE" = "yes" ]; then
echo " "
fi
# Copy data to flash.
RAMSTORAGE=$RAMMOUNT/.fh-config-ramstore
if [ ! -f $RAMSTORAGE ]; then
echo 'Warning, the original configuration was not saved or lost, using the configuration'
RAMSTORAGE=$CONFDIR/ramstore
fi
for dir in $(grep -v '^#' $RAMSTORAGE); do
if [ -d $RAMMOUNT/$dir ] && [ -d $RAMMOUNT/$dir.flash ]; then
if [ "$VERBOSE" = "yes" ]; then
echo -n "Synchronizing $dir"
fi
# Remount every $dir.flash read-write so that copying to it will work.
mount -o remount,rw $RAMMOUNT/$dir.flash/
# rsync is used to avoid churning the flash
# unnecessarily. The trailing slashes are very
# important..
rsync --delete -a $RAMMOUNT/$dir/ $RAMMOUNT/$dir.flash/
# Remount every $dir.flash read-only after copy.
mount -o remount,ro $RAMMOUNT/$dir.flash/
if [ "$VERBOSE" = "yes" ]; then
echo "."
fi
fi
done
echo "done."
sync