slitaz-arm view rpi/tazbian @ rev 214

tazbian: typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 05 17:03:59 2016 +0200 (2016-05-05)
parents 425bf14d2b84
children 4e7726c49011
line source
1 #!/bin/sh
2 #
3 # (C) 2014-2016 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 REVISION=3
14 DESTDIR=var/os/slitaz
15 DESCRIPTION="Tiny Linux distribution with multi boot features"
16 LONG_DESCRIPTION="SliTaz can run fully in RAM or can be installed \
17 on the SD card in a\nsubdirectory of your Raspbian (example /$DESTDIR)."
18 WEB_SITE="http://arm.slitaz.org/rpi/"
19 MAINTAINER="Pascal Bellard <pascal.bellard@slitaz.org>"
20 LICENSE=GPL
22 tazpkg()
23 {
24 if [ -x /usr/bin/tazpkg -a "$1" == "get-install" ]; then
25 /usr/bin/tazpkg "$@"
26 return $?
27 fi
28 [ "$1" == "get-install" ] && echo "abort: can't find $2" && exit 1
29 mkdir -p tazpkg$$
30 cd tazpkg$$
31 cpio -i < ../$2 > /dev/null 2>&1
32 gunzip fs.cpio.gz 2> /dev/null
33 [ -s fs.cpio ] || unlzma fs.cpio.lzma
34 cpio -idmu < fs.cpio > /dev/null 2>&1
35 cd ..
36 sh <<EOT
37 . tazpkg$$/receipt
38 mkdir -p ${3#--root=}/var/lib/tazpkg/installed/\$PACKAGE
39 grep -qs ^pre_install tazpkg$$/receipt && pre_install ${3#--root=}
40 cp -a tazpkg$$/fs/. ${3#--root=}
41 grep -qs ^post_install tazpkg$$/receipt && post_install ${3#--root=}
42 rm -rf tazpkg$$/fs*
43 mv tazpkg$$/* ${3#--root=}/var/lib/tazpkg/installed/\$PACKAGE
44 EOT
45 md5sum $2 >> ${3#--root=}/var/lib/tazpkg/installed.md5
46 rm -rf tazpkg$$
47 }
49 buildfs()
50 {
51 CURDIR=$PWD
52 TMPDIR=/tmp/rasp$$
53 mkdir -p $TMPDIR
54 cd $TMPDIR
55 URL=http://mirror.slitaz.org/arm/rpi/
56 echo "Read $URL"
57 wget -O - $URL | sed '/slitaz-rpi/!d;s/.*href=.\([a-zA-Z0-9._-]*\).*/\1/' | sort -r > index
58 VERSION="$(sed '/rpi-desktop/!d' index | sed 's/.*-desktop-\([0-9_-]*\).*/\1/;q')"
60 for file in $(sed '/rpi-base/!d;q' index) $(sed '/rpi-desktop/!d;q' index); do
61 echo "Get $file "
62 wget -O - $URL$file | tar xjf -
63 WGET_URL=$URL$file
64 done
66 mkdir -p fs/$DESTDIR fs/boot/slitaz fs/boot/slitaz-base fs/boot/slitaz-live \
67 fs/boot/$raspos
69 BOOT=$(ls -d slitaz-rpi-base-*/boot)
70 [ ! -d "$BOOT" ] && echo "Abort ($BOOT) !" && exit 1
72 # setup boot configuration
73 echo "entry=SliTaz $VERSION on SD-card" > fs/boot/slitaz/menu.txt
74 echo "entry=SliTaz base $VERSION in RAM" > fs/boot/slitaz-base/menu.txt
75 echo "entry=SliTaz desktop $VERSION in RAM" > fs/boot/slitaz-live/menu.txt
76 cp $BOOT/config.txt fs/boot/slitaz
77 grep -q ^kernel= fs/boot/slitaz/config.txt ||
78 echo "kernel=kernel.img >> fs/boot/slitaz/config.txt"
79 sed -i '/^initramfs/d' fs/boot/slitaz/config.txt
80 cp fs/boot/slitaz/config.txt fs/boot/slitaz-base
81 cp fs/boot/slitaz/config.txt fs/boot/slitaz-live
82 echo "initramfs rootfs-base.gz" >> fs/boot/slitaz/config.txt
83 echo "initramfs ../slitaz/rootfs-base.gz" >> fs/boot/slitaz-base/config.txt
84 echo "initramfs ../slitaz/rootfs-base.gz,../slitaz/rootfs-live.gz" >> fs/boot/slitaz-live/config.txt
86 if [ -s $BOOT/kernel7.img ]; then
87 mv $BOOT/kernel*.img fs/boot/slitaz
88 sed -i 's|kernel.img|../slitaz/&|' fs/boot/slitaz-*/config.txt
89 else
90 rm -rf slitaz-rpi-*/boot/kernel.img \
91 slitaz-rpi-*/rootfs/lib/modules/* \
92 slitaz-rpi-*/rootfs/lib/firmware/*
93 sed -i 's|kernel.img|../&|' fs/boot/slitaz-*/config.txt
94 fi
96 # update base package
97 BASE=$(ls -d slitaz-rpi-base-*/rootfs)
98 [ ! -d "$BASE" ] && echo "Abort ($BASE) !" && exit 1
99 LIVE=$(ls -d slitaz-rpi-desktop-*/rootfs)
100 [ ! -d "$LIVE" ] && echo "Abort ($LIVE) !" && exit 1
101 LIVESZ=$(du -ks $LIVE | cut -f1)
102 wget http://hg.slitaz.org/slitaz-arm/raw-file/tip/rpi/piboot
103 wget http://hg.slitaz.org/slitaz-boot-scripts/raw-file/tip/init
104 chmod +x piboot init
105 mv piboot $BASE/sbin
106 sed -i 's|mnt /mnt|mnt "/mnt -o noatime"|' init
107 sed -i 's#.*remount,ro#grep -q "tmpfs /mnt tmpfs" /proc/mounts || &#' init
108 mknod -m 660 $BASE/dev/mmcblk0 b 179 0
109 for i in $(seq 1 5); do
110 mknod -m 660 $BASE/dev/mmcblk0p$i b 179 $i
111 done
112 grep /dev/pts $BASE/etc/fstab || cat >> $BASE/etc/fstab <<EOT
113 devpts /dev/pts devpts rw,gid=5,mode=0620 0 0
114 EOT
116 [ -s slitaz-rpi-base*/boot/kernel7.img ] ||
117 sed -i 's#.*d /proc/sys/dev/cdrom#grep -q subroot= /proc/cmdline || for d in /dev/mmc*p[2-9]; do\n\tumount /mnt\n\tmount -r $d /mnt \&\&\n\tcp -a /mnt/lib/firmware /lib/ \&\&\n\tcp -a /mnt/lib/modules/$(uname -r) /lib/modules/ \&\& break\ndone 2> /dev/null\numount /mnt\n\n&#' init
118 mv init $BASE/rdinit
119 sed -i 's/.*mmcblk0p[2-9].*/# &/;s/noatime/noauto,&/' $BASE/etc/fstab $LIVE/etc/fstab
120 wget http://cook.slitaz.org/cross/arm/packages/packages.list
121 while read file pkg extra ; do
122 [ -s boot$file ] && continue
123 [ -n "$extra" ] && continue
124 pkg=$(grep ^$pkg- packages.list | sort | sed q).tazpkg
125 wget http://cook.slitaz.org/cross/arm/packages/$pkg
126 tazpkg install $pkg --root=$BASE/
127 done <<EOT
128 /usr/lib/libz.so zlib
129 /usr/sbin/kexec kexec-tools
130 /usr/bin/tset ncursesw
131 /usr/bin/dialog dialog
132 /usr/lib/libxml2.so libxml2 aria2
133 /usr/bin/gpg-error libgpg-error aria2
134 /usr/lib/libgcrypt.so libgcrypt aria2
135 /usr/lib/libgmp.so gmp aria2
136 /usr/lib/libnettle.so nettle aria2
137 /usr/lib/libreadline.so readline aria2
138 /usr/bin/p11-kit p11-kit aria2
139 /usr/lib/libgnutls.so libgnutls aria2
140 /usr/lib/libtasn1.so libtasn1 aria2
141 /usr/bin/gnutls-cli gnutls aria2
142 /usr/bin/aria2c aria2 aria2
143 EOT
145 echo "Deduplicate base & live"
146 ( cd $BASE/ ; find ! -type d ) | while read file; do
147 if [ -L $BASE/$file ]; then
148 [ -L $LIVE/$file ] &&
149 [ "$(readlink $BASE/$file)" == "$(readlink $LIVE/$file)" ] &&
150 rm -f $LIVE/$file
151 elif [ -f $BASE/$file ]; then
152 [ -f $LIVE/$file ] &&
153 cmp $BASE/$file $LIVE/$file > /dev/null 2>&1 &&
154 rm -f $LIVE/$file
155 elif [ -b $BASE/$file ]; then
156 [ -b $LIVE/$file ] &&
157 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
158 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
159 rm -f $LIVE/$file
160 elif [ -c $BASE/$file ]; then
161 [ -c $LIVE/$file ] &&
162 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
163 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
164 rm -f $LIVE/$file
165 fi
166 done
167 ( cd $BASE/ ; find -type d ) | while read dir; do
168 rmdir $LIVE/$dir 2> /dev/null
169 done
171 while read dir suffix ; do
172 echo "Build $suffix archive"
173 ( cd $dir ; find * | cpio -o -H newc ) | if [ -x /usr/bin/zopfli ]; then
174 cat > fs/boot/slitaz/rootfs-$suffix
175 zopfli fs/boot/slitaz/rootfs-$suffix
176 rm -f fs/boot/slitaz/rootfs-$suffix
177 else
178 gzip -9 > fs/boot/slitaz/rootfs-$suffix.gz
179 fi
180 [ -x /usr/bin/advdef ] && advdef -z4 fs/boot/slitaz/rootfs-$suffix.gz
181 r=$(($(stat -c %s fs/boot/slitaz/rootfs-$suffix.gz) % 4))
182 [ $r -eq 0 ] || dd if=/dev/zero bs=1 count=$((4 - $r)) \
183 >> fs/boot/slitaz/rootfs-$suffix.gz 2> /dev/null
184 done <<EOT
185 $BASE base
186 $LIVE live
187 EOT
188 }
190 mkpostinst()
191 {
192 cat <<EOT
193 RDEV=\$(sed 's/^\(\|.* \)root=\([^ ]*\).*/\2/' /boot/cmdline.txt)
194 FSTYPE=\$(awk '/ \/ / { if (\$1 != "rootfs") print \$3 }' < /proc/mounts)
196 echo "Extracting /$DESTDIR ..."
197 cd /$DESTDIR
198 zcat /boot/slitaz/rootfs-base.gz | cpio -idmu
199 zcat /boot/slitaz/rootfs-live.gz | cpio -idmu
200 EOT
201 [ -s slitaz-rpi-base*/boot/kernel7.img ] || cat <<EOT
202 echo "Get modules & firmwares ..."
203 cp -a /lib/modules /lib/firmware lib
204 EOT
205 cat <<EOT
206 if ! grep -qs $raspos etc/fstab ; then
207 echo "Update /$DESTDIR/etc/fstab ..."
208 mkdir -p mnt/$raspos
209 sed -i 's/noauto,//' etc/fstab
210 cat >> etc/fstab <<EOM
211 \$RDEV /mnt/$raspos \$FSTYPE noatime 0 0
212 tmpfs /mnt/$raspos/$DESTDIR tmpfs size=0 0 0
213 EOM
214 fi
215 cd - > /dev/null
217 if [ ! -f /boot/menu.txt ]; then
219 echo "Update /boot ..."
220 for i in keyboard locale ; do
221 [ -s /etc/default/\$i ] && . /etc/default/\$i
222 done
223 KMAP=\$(find /$DESTDIR/usr/share/kbd/keymaps | grep /\$XKBLAYOUT[.-] | head -n1)
224 [ "\$KMAP" ] && KMAP="kmap=\$(basename \$KMAP .map.gz)"
225 cat > /boot/menu.txt <<EOM
226 title=Raspberry PI boot menu
227 subtitle=Select the OS with ARROW keys and hit RETURN
228 timeout=10
229 default=$raspos
230 \$KMAP
231 edittitle=Edit menu
232 readonly
233 #noedit
234 #nowebboot
235 #webpath=http://my.home.web.site/pxe/rpi/index.php,http://or.this.one/rpi.txt
236 EOM
237 echo "entry=$menustr" > /boot/$raspos/menu.txt
238 KERNEL=\$(sed '/^kernel/!d;s/.*=//' /boot/config.txt)
239 cp /boot/config.txt /boot/cmdline.txt /boot/$raspos/
240 sed -i '/^initramfs/d' /boot/config.txt
241 echo "initramfs slitaz/rootfs-base.gz" >> /boot/config.txt
242 EOT
243 [ -s slitaz-rpi-base*/boot/kernel7.img ] && cat <<EOT
244 mv /boot/\${KERNEL:-kernel.img} /boot/$raspos/
245 sed -i '/^kernel/d' /boot/config.txt
246 echo "kernel=slitaz/kernel.img" >> /boot/config.txt
247 EOT
248 cat <<EOT
249 L=
250 for i in \$LANG \${LANG%.*} \${LANG%@*} \${LANG%_*} ; do
251 [ -s /$DESTDIR/usr/share/i18n/locales/\$i ] && L=lang=\$i
252 done
253 TZ=\$(cat /etc/timezone 2> /dev/null || true)
254 X="\$L \$KMAP \${TZ:+tz=\$TZ} quiet"
255 echo "\$(cat /boot/cmdline.txt) \$X rdinit=/sbin/piboot" > /boot/cmdline.txt
256 echo "root=/dev/null \$X rdinit=/rdinit mount=\$RDEV subroot=$DESTDIR rootwait" > /boot/slitaz/cmdline.txt
257 echo "root=/dev/null \$X" > /boot/slitaz-base/cmdline.txt
258 cp /boot/slitaz-base/cmdline.txt /boot/slitaz-live/cmdline.txt
259 echo "The SliTaz boot menu is available for the next (re)boot."
261 fi
262 EOT
263 }
265 mkpurge()
266 {
267 cat <<EOT
268 echo "Remove /$DESTDIR & /boot/slitaz* trees..."
269 rm -rf /$DESTDIR /boot/slitaz*
270 EOT
271 }
273 mkdisable()
274 {
275 cat <<EOT
276 if [ -d /boot/$raspos ]; then
277 echo "Restore $raspos boot files..."
278 rm -f /boot/$raspos/menu.txt
279 mv -f /boot/$raspos/* /boot
280 rmdir /boot/$raspos
281 fi
282 rm -f /boot/menu.txt /boot/slitaz*/cmdline.txt
283 EOT
284 }
286 pkgdebian()
287 {
288 # Create raspbian package
289 echo "2.0" > debian-binary
290 cat > control <<EOT
291 Package: slitaz
292 Version: $VERSION-$REVISION
293 Architecture: armhf
294 Maintainer: $MAINTAINER
295 Installed-Size: $(($(du -ks fs | cut -f1) + $LIVESZ))
296 Section: miscellaneous
297 Priority: optional
298 Homepage: $WEB_SITE
299 Description: $DESCRIPTION
300 $(echo -e $LONG_DESCRIPTION | sed 's/^/ /')
301 EOT
302 ( cd fs ; find * -type f -exec md5sum {} \; ) > md5sums
303 cat > postinst <<EOT
304 #!/bin/sh
306 set -e
308 $(mkpostinst)
310 exit 0
311 EOT
312 cat > prerm <<EOT
313 #!/bin/sh
315 purge()
316 {
317 $(mkpurge)
318 }
320 disable()
321 {
322 $(mkdisable)
323 }
325 case "\$1" in
326 purge)
327 disable
328 purge
329 ;;
330 remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
331 disable
332 ;;
333 *)
334 echo "prerm called with unknown argument \\\`\$1'" >&2
335 exit 0
336 esac
337 EOT
338 chmod +x postinst prerm
339 tar czf control.tar.gz md5sums control postinst prerm
340 rm -rf fs/$DESTDIR/*
341 cd fs ; tar czf ../data.tar.gz . ; cd ..
342 ar rcs slitaz-$VERSION-${REVISION}_armhf.deb debian-binary control.tar.gz data.tar.gz
343 mv slitaz-$VERSION-${REVISION}_armhf.deb $CURDIR
344 cd $CURDIR
345 rm -rf $TMPDIR
346 ls -l slitaz-$VERSION-${REVISION}_armhf.deb
347 }
349 mkmtree()
350 {
351 echo "#mtree"
352 echo "/set type=file uid=0 gid=0 mode=644"
353 find .??* * | while read file; do
354 echo -n "$file $(stat -c "time=%Y.000000" "$file")"
355 n="$(stat -c "%a" "$file")"; [ "$n" == "644" ] || echo -n " mode=$n"
356 n="$(stat -c "%u" "$file")"; [ "$n" == "0" ] || echo -n " uid=$n"
357 n="$(stat -c "%g" "$file")"; [ "$n" == "0" ] || echo -n " gid=$n"
358 if [ -f "$file" ]; then
359 echo -n " $(stat -c "size=%s" "$file")"
360 echo -n " md5digest=$(md5sum "$file" | sed 's/ .*//')"
361 echo -n " sha256digest=$(sha256sum "$file" | sed 's/ .*//')"
362 fi
363 [ -d "$file" ] && echo -n " type=dir"
364 echo ""
365 done
366 }
368 pkgarch()
369 {
370 cd fs
371 VERSION=$VERSION-$REVISION
372 # Create arch package
373 cat > .PKGINFO <<EOT
374 pkgname = slitaz
375 pkgver = $VERSION
376 pkgdesc = $DESCRIPTION
377 url = $WEB_SITE
378 builddate = $(date +%s)
379 packager = $MAINTAINER
380 size = $(du -s . | awk "{ print \$1*1024+$LIVESZ }")
381 arch = armv6h
382 license = $LICENSE
383 EOT
384 cat > .INSTALL <<EOT
385 post_install() {
386 $(mkpostinst)
387 }
389 post_remove() {
390 $(mkdisable)
391 $(mkpurge)
392 }
393 EOT
394 mkmtree | gzip -9 > ../.MTREE
395 mv ../.MTREE .
396 tar cvzf ../slitaz-$VERSION-armv6h.pkg.tar.gz .??* *
397 mv ../slitaz-$VERSION-armv6h.pkg.tar.gz $CURDIR
398 cd $CURDIR
399 rm -rf $TMPDIR
400 ls -l slitaz-$VERSION-armv6h.pkg.tar.gz
401 }
403 pkgrpm()
404 {
405 cat > rpm.spec <<EOT
406 %define desktop_vendor newrpms
407 %{!?_dist: %{expand: %%define dist rhfc14}}
409 Name: slitaz
410 Version: $VERSION
411 Release: $REVISION
412 Summary: $DESCRIPTION
413 License: $LICENSE
414 Group: System Environment/Boot loader
415 URL: $WEB_SITE
416 Source0: $WGET_URL
417 ExclusiveArch: arm
418 Distribution: $raspos
419 Packager: $MAINTAINER
420 BuildRoot: $PWD/fs
422 %description
423 $(echo -e "$LONG_DESCRIPTION")
425 %post
426 $(mkpostinst)
428 %postun
429 $(mkdisable)
430 $(mkpurge)
432 %files
434 %defattr(0755, root, root)
435 /boot
436 /var/os/slitaz
437 EOT
438 rpmbuild -bb --target=arm --buildroot=$PWD/fs rpm.spec
439 mv ~/rpmbuild/RPMS/arm/slitaz-$VERSION-$REVISION.arm.rpm $CURDIR
440 cd $CURDIR
441 rm -rf $TMPDIR
442 ls -l slitaz-$VERSION-$REVISION.arm.rpm
444 }
446 case "$(basename $0)" in
447 tazarch)
448 raspos=archarm
449 menustr="Arch Linux ARM \$(uname -r)"
450 buildfs
451 pkgarch
452 ;;
453 tazrpm)
454 [ -x /usr/bin/rpmbuild ] || tazpkg get-install rpm4
455 [ -e /usr/share/misc/magic.mgc ] || tazpkg get-install file
456 raspos=pidora
457 menustr="\$(cat /etc/pidora-release)"
458 buildfs
459 pkgrpm
460 ;;
461 *)
462 [ -x /usr/bin/ar -o -x /bin/ar ] || tazpkg get-install binutils
463 raspos=raspbian
464 menustr="Raspbian \$(cat /etc/debian_version)"
465 buildfs
466 pkgdebian
467 ;;
468 esac