File: init

package info (click to toggle)
flashybrid 0.002
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 120 kB
  • ctags: 5
  • sloc: sh: 194; makefile: 44
file content (125 lines) | stat: -rwxr-xr-x 2,665 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# Set up/shutdown the flashybrid system, including the ramdisk and partial
# directory bind mounts. This needs to run at the part of system bootup that
# mounts all the disks. It should also run at shutdown right before
# filesystems are unmounted.

CONFDIR=/etc/flashybrid
if [ -e $CONFDIR/config ]; then
	. $CONFDIR/config
fi

ENABLED=no
if [ -e /etc/default/flashybrid ]; then
	. /etc/default/flashybrid
fi

if [ -z "$RAMMOUNT" ]; then
	exit 0
fi

is_mounted () {
	grep -q " $1 " /proc/mounts
}

case "$1" in
start)
	if [ "$ENABLED" != yes ]; then
		echo "Not setting up flashybrid system: disabled."
		exit
	fi
	
	printf "Setting up flashybrid system..."

	# Set up partial directories and so on, make sure disk is
	# unmounted.
	fh-embed >/dev/null
	
	# Set up ram disk to hold variable data.
	if ! is_mounted $RAMMOUNT; then
		mount tmpfs -t tmpfs $RAMMOUNT
	fi

	# Temporary directories on ram disk.
	for dir in $(grep -v '^#' $CONFDIR/ramtmp); do
		mkdir -p -m 1777 $RAMMOUNT/$dir
		if is_mounted $dir; then
			umount $dir
		fi
		mount --bind $RAMMOUNT/$dir $dir
	done

	# Copy data from flash to ram disk for these directories.
	for dir in $(grep -v '^#' $CONFDIR/ramstore); do
		# Skip dirs that are not present.
		if [ -d $dir ]; then
			ramdir=$RAMMOUNT$dir
			if is_mounted $dir; then
				umount $dir
			fi
			if is_mounted $ramdir.flash; then
				umount $ramdir.flash
			fi
			if [ ! -d $ramdir ]; then
				mkdir -p ${ramdir%/*} # dirname
			        cp -a $dir $ramdir
			fi
			mkdir -p $ramdir.flash
			mount --bind $dir $ramdir.flash
			mount --bind $ramdir $dir
		fi
	done

	echo "done."
;;
stop)
	if [ "$ENABLED" != yes ]; then
		echo "Not shutting down flashybrid system: disabled."
		exit
	fi
	
	printf "Shutting down flashybrid system..."
	
	# Copy data to flash.
	# Remount the flash read-write so the copies to it will work.
	mount -o remount,rw /
	for dir in $(grep -v '^#' $CONFDIR/ramstore); do
		if [ -d $RAMMOUNT/$dir ] && [ -d $RAMMOUNT/$dir.flash ]; then
			# rsync is used to avoid churning the flash
			# unnecessarily. The trailing slashes are very
			# important..
			rsync --delete -a $RAMMOUNT/$dir/ $RAMMOUNT/$dir.flash/
		fi
	done

	for dir in $(grep -v '^#' $CONFDIR/ramtmp); do
		if is_mounted $dir; then
			umount $dir
		fi
	done
	
	for dir in $(grep -v '^#' $CONFDIR/ramstore); do
		ramdir=$RAMMOUNT$dir
		if is_mounted $ramdir.flash; then
			umount $ramdir.flash
		fi
		if is_mounted $dir; then
			umount $dir
		fi
	done
	
	if is_mounted $RAMMOUNT; then
		umount $RAMMOUNT
	fi	
	
	echo "done."
;;
restart|force-reload)
	$0 stop
	$0 start
;;
*)
	echo "Usage: $0 {start|stop|restart|force-reload}"
	exit 1
;;
esac