wok view slitaz-loram-cdrom/receipt @ rev 4082
slitaz-loram-cdrom: add usb delay
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Sep 15 22:47:44 2009 +0200 (2009-09-15) |
parents | bf6b4e59baf3 |
children | 6509db5aa948 |
line source
1 # SliTaz package receipt.
3 PACKAGE="slitaz-loram-cdrom"
4 VERSION="1.4"
5 CATEGORY="misc"
6 SHORT_DESC="Rules to build low ram system using cdrom."
7 MAINTAINER="pascal.bellard@slitaz.org"
8 WEB_SITE="http://www.slitaz.org/"
9 DEPENDS="slitaz-boot-scripts tazlito"
11 # Rules to gen a SliTaz package suitable for Tazpkg.
12 genpkg_rules()
13 {
14 mkdir -p $fs/etc/tazlito
15 cp stuff/loram.* $fs/etc/tazlito
16 }
18 set_patch()
19 {
20 local tag
21 local line
22 local i
23 tag="Handle kernel cmdline parameter config"
24 i=$(grep -n "$tag" $1/etc/init.d/rcS | cut -d: -f1)
25 i=$(($i-1))
26 tag=$(grep "$tag" $1/etc/init.d/rcS)
27 if [ "$2" = "-R" ]; then
28 line="-$(($i-72)),74 +$(($i-72)),2"
29 i="-"
30 else
31 grep -q 'from slitaz-loram-cdrom package' $1/etc/init.d/rcS && return
32 line="-$i,2 +$i,74"
33 i="+"
34 fi
35 patch -p0 <<EOF
36 --- $1/etc/init.d/rcS
37 +++ $1/etc/init.d/rcS
38 @@ $line @@
40 $i# Try to release the cdrom (from slitaz-loram-cdrom package)
41 $i release_cdrom()
42 $i {
43 $i FREEMEM=\$(busybox free | busybox awk '{ n = \$NF } END { print n }')
44 $i if [ \$FREEMEM -gt \$(busybox du -s \$FS | busybox awk '{ print \$1+40000 }') ]; then
45 $i cp -a \$FS /.usr.fs
46 $i status
47 $i echo -n "Releasing CD-ROM..."
48 $i umount /cdrom
49 $i FS=/.usr.fs
50 $i return 0
51 $i fi
52 $i return 1
53 $i }
54 $i
55 $i# Mount /usr (from slitaz-loram-cdrom package)
56 $i if [ -d /cdrom ]; then
57 $i DEVICE=/dev/cdrom
58 $i DIR=
59 $i if grep -q " loram=" /proc/cmdline; then
60 $i DIR=\`cat /proc/cmdline | sed 's/.* loram=\([^ ]*\).*/\1/'\`
61 $i DEVICE=\${DIR%,*}
62 $i DIR=/\${DIR#*,}
63 $i fi
64 $i if ! /bin/mount -r \$DEVICE /cdrom; then
65 $i if echo \$DEVICE | grep -Eq "/dev/sd|UUID=|LABEL="; then
66 $i USBDELAY=\`cat /sys/module/usb_storage/parameters/delay_use\`
67 $i USBDELAY=\$((1+\$USBDELAY))
68 $i echo "\$DEVICE is potentially a USB device: sleep for \$USBDELAY seconds"
69 $i sleep \$USBDELAY
70 $i fi
71 $i if ! /bin/mount -r \$DEVICE /cdrom; then
72 $i DEVICE=""
73 $i fi
74 $i fi
75 $i if [ -n "\$DEVICE" ]; then
76 $i if [ -d /.usr.rw ]; then
77 $i echo -n "Mounting /usr read-write... "
78 $i usr=.usr.ro
79 $i else
80 $i echo -n "Mounting /usr read-only... "
81 $i usr=usr
82 $i fi
83 $i FS=/cdrom\$DIR/usr.cromfs
84 $i if [ -f \$FS ]; then
85 $i release_cdrom
86 $i /bin/cromfs-driver \$FS /\$usr -o ro,dev,suid,allow_other
87 $i elif [ -f /cdrom\$DIR/usr.sqfs ]; then
88 $i FS=/cdrom\$DIR/usr.sqfs
89 $i release_cdrom
90 $i mount -o loop,ro -t squashfs \$FS /\$usr
91 $i elif [ -L /\$usr ]; then
92 $i FS=/cdrom\$DIR/usr
93 $i if release_cdrom; then
94 $i rm -f /\$usr
95 $i mv \$FS /usr
96 $i fi
97 $i else
98 $i umount /cdrom
99 $i false
100 $i fi
101 $i status
102 $i if [ -d /.usr.rw ]; then
103 $i if [ -x /bin/funionfs ]; then
104 $i /bin/funionfs -o dirs=/.usr.ro=RO:/.usr.rw -o allow_other -o suid,dev NONE /usr
105 $i else
106 $i /bin/mount -t aufs -o br:/.usr.rw:/.usr.ro none /usr
107 $i fi
108 $i fi
109 $i fi
110 $i fi
111 $i
112 $tag
113 EOF
114 tag="/var/log/dmesg.log"
115 i=$(grep -n "$tag" $1/etc/init.d/rcS | cut -d: -f1)
116 i=$(($i-1))
117 tag=$(grep "$tag" $1/etc/init.d/rcS)
118 if [ "$2" = "-R" ]; then
119 line="-$(($i-7)),9 +$(($i-7)),2"
120 i="-"
121 else
122 line="-$i,2 +$i,9"
123 i="+"
124 fi
125 patch -p0 <<EOF
126 --- $1/etc/init.d/rcS
127 +++ $1/etc/init.d/rcS
128 @@ $line @@
130 $i# Build ramdisk if root=/dev/cdrom (from slitaz-loram-cdrom package)
131 $i if [ -L /root ]; then
132 $i mount -t tmpfs ramdisk /tmp
133 $i mkdir -p /tmp/log/lighttpd /tmp/run /tmp/lock
134 $i chown www.www /tmp/log/lighttpd
135 $i fi
136 $i
137 $tag
138 EOF
139 chmod 0755 $1/etc/init.d/rcS
140 }
142 # Pre and post install commands for Tazpkg.
143 pre_install()
144 {
145 local i
146 for i in $(cd /var/lib/tazpkg/installed ; ls -d slitaz-loram* 2> /dev/null); do
147 [ "$i" = "$PACKAGE" ] && continue
148 yes y | tazpkg remove $i
149 . /etc/tazlito/tazlito.conf
150 rm -f $PACKAGES_REPOSITORY/slitaz-boot-scripts-*.tazpkg 2> /dev/null
151 done
152 }
154 post_install()
155 {
156 set_patch "$1"
157 if [ ! -x $1/bin/funionfs -a ! -d $1/var/lib/tazpkg/installed/aufs ]; then
158 cat <<EOF
159 ----
160 You will build a live CD with /usr mounted read-only.
161 You can install aufs or funionfs to have read-write access into /usr with:
163 # tazpkg get-install aufs
164 or
165 # tazpkg get-install funionfs
167 EOF
168 fi
169 }
171 # Pre remove commands for Tazpkg.
172 pre_remove()
173 {
174 set_patch '' -R
175 }