]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/unionfs/unionroot/init.unionroot.old
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / unionfs / unionroot / init.unionroot.old
1 #!/bin/sh
2
3 INIT=/sbin/init.sysvinit
4 #OVERLAYS=/media/ram /media/cf /media/card
5 ROOTBACKUP=/media/realroot
6 UNION=/media/union
7 PATH=/usr/bin:/usr/sbin:/bin:/sbin
8
9 if ! test -e ${INIT}; then
10         echo >&2 "ERROR: ${INIT} not found"
11         exit 1
12 fi
13
14 if test x"$*" != "x"; then
15         exec ${INIT} $*
16 fi
17
18 if ! which unionctl; then
19         exec ${INIT}
20 fi
21
22 nodupmount () {
23         opts=""
24         type=""
25         while true; do
26                 if test "$1" = "-o"; then
27                         shift
28                         opts="-o $1"
29                         shift
30                 elif test "$1" = "-t"; then
31                         shift
32                         type="$1"
33                         shift
34                 else
35                         break
36                 fi
37         done
38         if test x"$2" = "x"; then
39                 mountpt="$1"
40         else
41                 device="$1"
42                 mountpt="$2"
43         fi
44         mountmatch="^[^ ]+ $mountpt $type"
45         # echo "NOTE: grep -E -q \"$mountmatch\" /proc/mounts"
46         if grep -E -q "$mountmatch" /proc/mounts; then
47                 return 0;
48         fi
49         if test x"$type" != "x"; then
50                 type="-t $type"
51         fi
52         echo >&2 "NOTE: executing mount $type $opts $device $mountpt"
53         mkdir -p $mountpt
54         /bin/mount.busybox $type $opts $device $mountpt
55         ret="$?"
56         if test "$ret" = "0"; then
57                 wemounted="$wemounted $mountpt"
58         fi
59         return $ret
60 }
61
62 #set -x
63 wemounted=""
64 (
65         set -e
66         /bin/mount.busybox /proc
67         insmod /lib/modules/`uname -r`/kernel/fs/unionfs.o
68         nodupmount -t unionfs -o dirs=/.=rw,setattr=all none ${UNION}
69 #       nodupmount -o bind / ${UNION}/${ROOTBACKUP}
70 #       for OVERLAY in ${OVERLAYS}; do
71 #               nodupmount ${OVERLAY}
72 #               union-ctl /. --add --mode rw ${OVERLAY}
73 #               nodupmount -o bind ${OVERLAY} ${UNION}/${OVERLAY}
74 #       done
75         /bin/umount.busybox /proc
76 #       nodupmount -o bind /proc ${UNION}/proc
77 #       nodupmount -o bind / ${ROOTBACKUP}
78 ) || (
79         echo >&2 "ERROR: unable to setup mounts for chroot";
80         if test x"$wemounted" != "x"; then
81                 # cleanup
82                 for mount in $wemounted; do
83                         /bin/umount.busybox $mount
84                 done
85         fi
86         exec ${INIT}
87 )
88 cd ${UNION}
89 pivot_root . ./${ROOTBACKUP}
90 exec chroot . ${INIT}