slitaz-arm view rpi/tazbian @ rev 207
tazbian: check for model 1 in postinstall
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Aug 08 23:42:01 2015 +0200 (2015-08-08) |
parents | 4ed997df7958 |
children | 5be8b2141f10 |
line source
1 #!/bin/sh
2 #
3 # (C) 2014-2015 SliTaz GNU/Linux - GPL2
4 #
5 # Creates a Debian package to install SliTaz on a Raspbian without
6 # repartitioning.
7 #
8 # AUTHORS: Pascal Bellard <pascal.bellard@slitaz.org>
9 #
11 [ $(id -u) -ne 0 ] && echo "Must be root. Abort." && exit 1
13 DESTDIR=var/os/slitaz
14 DESCRIPTION="Tiny Linux distribution with multi boot features"
15 LONG_DESCRIPTION="SliTaz can run fully in RAM or can be installed \
16 on the SD card in a\nsubdirectory of your Raspbian (example /$DESTDIR)."
17 WEB_SITE="http://arm.slitaz.org/rpi/"
18 MAINTAINER="Pascal Bellard <pascal.bellard@slitaz.org>"
20 tazpkg()
21 {
22 if [ -x /usr/bin/tazpkg ]; then
23 /usr/bin/tazpkg "$@"
24 return $?
25 fi
26 [ "$1" == "get-install" ] && echo "abort: can't find $2" && exit 1
27 mkdir -p tazpkg$$
28 cd tazpkg$$
29 cpio -i < ../$2
30 gunzip fs.cpio.gz 2> /dev/null
31 [ -s fs.cpio ] || unlzma fs.cpio.lzma
32 cpio -idmu < fs.cpio
33 cd ..
34 sh <<EOT
35 . tazpkg$$/receipt
36 mkdir -p ${3#--root=}/var/lib/tazpkg/installed/\$PACKAGE
37 grep -qs ^pre_install tazpkg$$/receipt && pre_install ${3#--root=}
38 cp -a tazpkg$$/fs/. ${3#--root=}
39 grep -qs ^post_install tazpkg$$/receipt && post_install ${3#--root=}
40 rm -rf tazpkg$$/fs*
41 mv tazpkg$$/* ${3#--root=}/var/lib/tazpkg/installed/\$PACKAGE
42 EOT
43 md5sum $2 >> ${3#--root=}/var/lib/tazpkg/installed.md5
44 rm -rf tazpkg$$
45 }
47 buildfs()
48 {
49 CURDIR=$PWD
50 EXE=$(cd $(dirname $0); pwd)/$(basename $0)
51 TMPDIR=/tmp/rasp$$
52 mkdir -p $TMPDIR
53 cd $TMPDIR
54 URL=http://mirror.slitaz.org/arm/rpi/
55 wget -O - $URL | sed '/slitaz-rpi/!d;s/.*href=.\([a-zA-Z0-9._-]*\).*/\1/' | sort -r > index
56 VERSION="$(sed '/rpi-desktop/!d' index | sed 's/.*-desktop-\([0-9_-]*\).*/\1/;q')"
58 wget -O - $URL$(sed '/rpi-base/!d;q' index) | tar xjf -
59 wget -O - $URL$(sed '/rpi-desktop/!d;q' index) | tar xjf -
61 mkdir -p fs/$DESTDIR fs/boot/slitaz fs/boot/slitaz-base \
62 fs/boot/$raspos
64 # setup boot configuration
65 BASE=$(ls -d slitaz-rpi-base-*/boot)
66 [ ! -d "$BASE" ] && echo "Abort ($BASE) !" && exit 1
67 mv $BASE/kernel.img fs/boot/slitaz
68 cp $BASE/config.txt fs/boot/slitaz
69 cp $BASE/config.txt fs/boot/slitaz-base
70 echo "initramfs rootfs-base.gz" >> fs/boot/slitaz/config.txt
71 echo "entry=SliTaz $VERSION on SD-card" > fs/boot/slitaz/menu.txt
72 sed -i 's|kernel.img|../slitaz/&|' fs/boot/slitaz-base/config.txt
73 cp -a fs/boot/slitaz-base fs/boot/slitaz-live
74 echo "initramfs ../slitaz/rootfs-base.gz" >> fs/boot/slitaz-base/config.txt
75 echo "entry=SliTaz base $VERSION in RAM" > fs/boot/slitaz-base/menu.txt
76 echo "initramfs ../slitaz/rootfs-base.gz ../slitaz/rootfs-live.gz" >> fs/boot/slitaz-live/config.txt
77 echo "entry=SliTaz desktop $VERSION in RAM" > fs/boot/slitaz-live/menu.txt
79 # update base package
80 BASE=$(ls -d slitaz-rpi-base-*/rootfs)
81 LIVE=$(ls -d slitaz-rpi-desktop-*/rootfs)
82 [ ! -d "$LIVE" ] && echo "Abort ($LIVE) !" && exit 1
83 LIVESZ=$(du -ks $LIVE | cut -f1)
84 [ ! -d "$BASE" ] && echo "Abort ($BASE) !" && exit 1
85 wget http://hg.slitaz.org/slitaz-arm/raw-file/tip/rpi/piboot
86 wget http://hg.slitaz.org/slitaz-boot-scripts/raw-file/tip/init
87 chmod +x piboot init
88 mv piboot $BASE/sbin
89 sed -i 's|mnt /mnt|mnt "/mnt -o noatime"|' init
90 mv init $BASE/sbin/pisubroot
91 mknod -m 660 $BASE/dev/mmcblk0 b 179 0
92 mknod -m 660 $BASE/dev/mmcblk0p1 b 179 1
93 mknod -m 660 $BASE/dev/mmcblk0p2 b 179 2
94 sed -i 's/.*mmcblk0p[2-9].*/# &/;s/noatime/noauto,&/' $BASE/etc/fstab $LIVE/etc/fstab
95 wget http://cook.slitaz.org/cross/arm/packages/packages.list
96 while read file pkg extra ; do
97 [ -s boot$file ] && continue
98 [ -n "$extra" ] && continue
99 pkg=$(grep ^$pkg- packages.list | sort | sed q).tazpkg
100 wget http://cook.slitaz.org/cross/arm/packages/$pkg
101 tazpkg install $pkg --root=$BASE/
102 done <<EOT
103 /usr/lib/libz.so zlib
104 /usr/sbin/kexec kexec-tools
105 /usr/bin/tset ncursesw
106 /usr/bin/dialog dialog
107 /usr/lib/libxml2.so libxml2 aria2
108 /usr/bin/gpg-error libgpg-error aria2
109 /usr/lib/libgcrypt.so libgcrypt aria2
110 /usr/lib/libgmp.so gmp aria2
111 /usr/lib/libnettle.so nettle aria2
112 /usr/lib/libreadline.so readline aria2
113 /usr/bin/p11-kit p11-kit aria2
114 /usr/lib/libgnutls.so libgnutls aria2
115 /usr/lib/libtasn1.so libtasn1 aria2
116 /usr/bin/gnutls-cli gnutls aria2
117 /usr/bin/aria2c aria2 aria2
118 EOT
120 # deduplicate base & live
121 ( cd $BASE/ ; find ! -type d ) | while read file; do
122 if [ -L $BASE/$file ]; then
123 [ -L $LIVE/$file ] &&
124 [ "$(readlink $BASE/$file)" == "$(readlink $LIVE/$file)" ] &&
125 rm -f $LIVE/$file
126 elif [ -f $BASE/$file ]; then
127 [ -f $LIVE/$file ] &&
128 cmp $BASE/$file $LIVE/$file > /dev/null 2>&1 &&
129 rm -f $LIVE/$file
130 elif [ -b $BASE/$file ]; then
131 [ -b $LIVE/$file ] &&
132 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
133 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
134 rm -f $LIVE/$file
135 elif [ -c $BASE/$file ]; then
136 [ -c $LIVE/$file ] &&
137 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
138 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
139 rm -f $LIVE/$file
140 fi
141 done
142 cp $EXE $BASE/root/
143 ( cd $BASE/ ; find -type d ) | while read dir; do
144 rmdir $LIVE/$dir 2> /dev/null
145 done
147 ( cd $BASE ; find * | cpio -o -H newc ) | \
148 gzip -9 > fs/boot/slitaz/rootfs-base.gz
149 ( cd $LIVE ; find * | cpio -o -H newc ) | \
150 gzip -9 > fs/boot/slitaz/rootfs-live.gz
151 if [ -x /usr/bin/advdef ]; then
152 advdef -z4 fs/boot/slitaz/rootfs-base.gz
153 advdef -z4 fs/boot/slitaz/rootfs-live.gz
154 fi
155 }
157 mkpostinst()
158 {
159 cat <<EOT
160 RDEV=\$(sed 's/.*root=\([^ ]*\).*/\1/' /boot/cmdline.txt)
161 FSTYPE=\$(awk '/ \/ / { if (\$1 != "rootfs") print \$3 }' < /proc/mounts)
163 echo "Extracting /$DESTDIR ..."
164 cd /$DESTDIR
165 zcat /boot/slitaz/rootfs-base.gz | cpio -idmu
166 zcat /boot/slitaz/rootfs-live.gz | cpio -idmu
167 if ! grep -qs $raspos etc/fstab ; then
168 echo "Update /$DESTDIR/etc/fstab ..."
169 mkdir -p mnt/$raspos
170 sed -i 's/noauto,//' etc/fstab
171 cat >> etc/fstab <<EOM
172 \$RDEV /mnt/$raspos \$FSTYPE noatime 0 0
173 tmpfs /mnt/$raspos/$DESTDIR tmpfs size=0 0 0
174 EOM
175 fi
176 cd - > /dev/null
178 if ! grep -qs ARMv6-compatible /proc/cpuinfo ; then
180 echo "CPU unknown. Can't update /boot. Not RPI model 1?"
182 elif [ ! -f /boot/menu.txt ]; then
184 echo "Update /boot ..."
185 for i in keyboard locale ; do
186 [ -s /etc/default/\$i ] && . /etc/default/\$i
187 done
188 KMAP=\$(find /$DESTDIR/usr/share/kbd/keymaps | grep /\$XKBLAYOUT[.-] | head -n1)
189 [ "\$KMAP" ] && KMAP="kmap=\$(basename \$KMAP .map.gz)"
190 cat > /boot/menu.txt <<EOM
191 title=Raspberry PI boot menu
192 subtitle=Select the OS with ARROW keys and hit RETURN
193 timeout=30
194 default=$raspos
195 \$KMAP
196 edittitle=Edit menu
197 readonly
198 #noedit
199 #nowebboot
200 #webpath=http://my.home.web.site/pxe/rpi/index.php http://or.this.one/rpi.txt
201 EOM
202 KERNEL=\$(sed '/^kernel/!d;s/.*=//' /boot/config.txt)
203 cp /boot/config.txt /boot/cmdline.txt /boot/$raspos/
204 mv /boot/\${KERNEL:-kernel.img} /boot/$raspos/
205 echo "entry=$menustr" > /boot/$raspos/menu.txt
206 sed -i '/^kernel/d;/^initramfs/d' /boot/config.txt
207 echo "kernel=slitaz/kernel.img" >> /boot/config.txt
208 echo "initramfs slitaz/rootfs-base.gz" >> /boot/config.txt
209 echo "root=/dev/null rdinit=/sbin/piboot quiet" > /boot/cmdline.txt
210 L=
211 [ -s /$DESTDIR/usr/share/i18n/locales/\${LANG%.*} ] && L=lang=\${LANG%.*}
212 echo "root=/dev/null \$L \$KMAP rdinit=/sbin/pisubroot mount=\$RDEV subroot=$DESTDIR rootwait quiet" > /boot/slitaz/cmdline.txt
213 echo "root=/dev/null \$L \$KMAP quiet" > /boot/slitaz-base/cmdline.txt
214 cp /boot/slitaz-base/cmdline.txt /boot/slitaz-live/cmdline.txt
215 echo "The SliTaz boot menu is available for the next (re)boot."
217 fi
218 EOT
219 }
221 mkpurge()
222 {
223 cat <<EOT
224 echo "Remove /$DESTDIR & /boot/slitaz* trees..."
225 rm -rf /$DESTDIR /boot/slitaz*
226 EOT
227 }
229 mkdisable()
230 {
231 cat <<EOT
232 if [ -d /boot/$raspos ]; then
233 echo "Restore $raspos boot files..."
234 rm -f /boot/$raspos/menu.txt
235 mv -f /boot/$raspos/* /boot
236 fi
237 rm -f /boot/menu.txt /boot/slitaz*/cmdline.txt
238 EOT
239 }
241 pkgdebian()
242 {
243 # Create raspbian package
244 echo "2.0" > debian-binary
245 cat > control <<EOT
246 Package: slitaz
247 Version: $VERSION-1
248 Architecture: armhf
249 Maintainer: $MAINTAINER
250 Installed-Size: $(($(du -ks fs | cut -f1) + $LIVESZ))
251 Section: miscellaneous
252 Priority: optional
253 Homepage: $WEB_SITE
254 Description: $DESCRIPTION
255 $(echo $LONG_DESCRIPTION | sed 's/^/ /')
256 EOT
257 ( cd fs ; find * -type f -exec md5sum {} \; ) > md5sums
258 cat > postinst <<EOT
259 #!/bin/sh
261 set -e
263 $(mkpostinst)
265 exit 0
266 EOT
267 cat > prerm <<EOT
268 #!/bin/sh
270 purge()
271 {
272 $(mkpurge)
273 }
275 disable()
276 {
277 $(mkdisable)
278 }
280 case "\$1" in
281 purge)
282 disable
283 purge
284 ;;
285 remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
286 disable
287 ;;
288 *)
289 echo "prerm called with unknown argument \\\`\$1'" >&2
290 exit 0
291 esac
292 EOT
293 chmod +x postinst prerm
294 tar czf control.tar.gz md5sums control postinst prerm
295 rm -rf fs/$DESTDIR/*
296 cd fs ; tar czf ../data.tar.gz . ; cd ..
297 ar rcs slitaz-$VERSION-1_armhf.deb debian-binary control.tar.gz data.tar.gz
298 mv slitaz-$VERSION-1_armhf.deb $CURDIR
299 cd $CURDIR
300 rm -rf $TMPDIR
301 ls -l slitaz-$VERSION-1_armhf.deb
302 }
304 mkmtree()
305 {
306 echo "#mtree"
307 echo "/set type=file uid=0 gid=0 mode=644"
308 find .??* * | while read file; do
309 echo -n "$file $(stat -c "time=%Y.000000" "$file")"
310 n="$(stat -c "%a" "$file")"; [ "$n" == "644" ] || echo -n " mode=$n"
311 n="$(stat -c "%u" "$file")"; [ "$n" == "0" ] || echo -n " uid=$n"
312 n="$(stat -c "%g" "$file")"; [ "$n" == "0" ] || echo -n " gid=$n"
313 if [ -f "$file" ]; then
314 echo -n " $(stat -c "size=%s" "$file")"
315 echo -n " md5digest=$(md5sum "$file" | sed 's/ .*//')"
316 echo -n " sha256digest=$(sha256sum "$file" | sed 's/ .*//')"
317 fi
318 [ -d "$file" ] && echo -n " type=dir"
319 echo ""
320 done
321 }
323 pkgarch()
324 {
325 cd fs
326 VERSION=$VERSION-1
327 # Create arch package
328 cat > .PKGINFO <<EOT
329 pkgname = slitaz
330 pkgver = $VERSION
331 pkgdesc = $DESCRIPTION
332 url = $WEB_SITE
333 builddate = $(date +%s)
334 packager = $MAINTAINER
335 size = $(du -s . | awk "{ print \$1*1024+$LIVESZ }")
336 arch = armv6h
337 license = GPL
338 EOT
339 cat > .INSTALL <<EOT
340 post_install() {
341 $(mkpostinst)
342 }
344 post_remove() {
345 $(mkdisable)
346 $(mkpurge)
347 }
348 EOT
349 mkmtree | gzip -9 > ../.MTREE
350 mv ../.MTREE .
351 tar cvzf ../slitaz-$VERSION-armv6h.pkg.tar.gz .??* *
352 mv ../slitaz-$VERSION-armv6h.pkg.tar.gz $CURDIR
353 cd $CURDIR
354 rm -rf $TMPDIR
355 ls -l slitaz-$VERSION-armv6h.pkg.tar.gz
356 }
358 case "$(basename $0)" in
359 tazarch)
360 raspos=archarm
361 menustr="Arch Linux ARM \\\$(uname -r)"
362 buildfs
363 pkgarch
364 ;;
365 *)
366 [ -x /usr/bin/ar -o -x /bin/ar ] || tazpkg get-install binutils
367 raspos=raspbian
368 menustr="Raspbian \\\$(cat /etc/debian_version)"
369 buildfs
370 pkgdebian
371 ;;
372 esac