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