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