slitaz-arm view rpi/tazbian @ rev 200

tazbian: need mmcblk0 devices
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Nov 18 13:40:01 2014 +0100 (2014-11-18)
parents e04e276de7ec
children aef225322253
line source
1 #!/bin/sh
2 #
3 # (C) 2014 SliTaz GNU/Linux - GPL2
4 #
5 # creates a debian package to install SliTaz on a RaspBian without
6 # repartitionning.
7 #
8 # AUTHORS: Pascal Bellard <pascal.bellard@slitaz.org>
9 #
11 [ $(id -u) -ne 0 ] && echo "Must be root. Abort." && exit 1
13 CURDIR=$PWD
14 TMPDIR=/tmp/rasp$$
15 mkdir -p $TMPDIR
16 cd $TMPDIR
17 DESTDIR=var/os/slitaz
18 URL=http://mirror.slitaz.org/arm/rpi/
19 wget -O - $URL | sed '/slitaz-rpi/!d;s/.*href=.\([a-zA-Z0-9._-]*\).*/\1/' | sort -r > index
20 VERSION="$(sed '/rpi-desktop/!d' index | sed 's/.*-desktop-\([0-9_-]*\).*/\1/;q')"
22 wget -O - $URL$(sed '/rpi-base/!d;q' index) | tar xjf -
23 wget -O - $URL$(sed '/rpi-desktop/!d;q' index) | tar xjf -
25 mkdir -p fs/$DESTDIR fs/boot/slitaz fs/boot/slitaz-base \
26 fs/boot/raspbian
28 # setup boot configuration
29 BASE=$(ls -d slitaz-rpi-base-*/boot)
30 [ ! -d "$BASE" ] && echo "Abort ($BASE) !" && exit 1
31 mv $BASE/kernel.img fs/boot/slitaz
32 cp $BASE/config.txt fs/boot/slitaz
33 cp $BASE/config.txt fs/boot/slitaz-base
34 echo "initramfs rootfs-base.gz" >> fs/boot/slitaz/config.txt
35 echo "entry=SliTaz $VERSION on SD-card" > fs/boot/slitaz/menu.txt
36 sed -i 's|kernel.img|../slitaz/&|' fs/boot/slitaz-base/config.txt
37 cp -a fs/boot/slitaz-base fs/boot/slitaz-live
38 echo "initramfs ../slitaz/rootfs-base.gz" >> fs/boot/slitaz-base/config.txt
39 echo "entry=SliTaz base $VERSION in RAM" > fs/boot/slitaz-base/menu.txt
40 echo "initramfs ../slitaz/rootfs-base.gz ../slitaz/rootfs-live.gz" >> fs/boot/slitaz-live/config.txt
41 echo "entry=SliTaz desktop $VERSION in RAM" > fs/boot/slitaz-live/menu.txt
43 # update base package
44 BASE=$(ls -d slitaz-rpi-base-*/rootfs)
45 [ ! -d "$BASE" ] && echo "Abort ($BASE) !" && exit 1
46 wget http://hg.slitaz.org/slitaz-arm/raw-file/tip/rpi/piboot
47 wget http://hg.slitaz.org/slitaz-boot-scripts/raw-file/tip/init
48 chmod +x piboot init
49 mv piboot $BASE/sbin
50 sed -i 's|mnt /mnt|mnt "/mnt -o noatime"|' init
51 mv init $BASE/sbin/pisubroot
52 mknod -m 660 $BASE/dev/mmcblk0 b 179 0
53 mknod -m 660 $BASE/dev/mmcblk0p1 b 179 1
54 mknod -m 660 $BASE/dev/mmcblk0p2 b 179 2
55 sed -i 's/.*mmcblk0p[2-9].*/# &/;s/noatime/noauto,/' $BASE/etc/fstab
56 wget http://cook.slitaz.org/cross/arm/packages/packages.list
57 while read file pkg extra ; do
58 [ -s boot$file ] && continue
59 [ -n "$extra" ] && continue
60 pkg=$(grep ^$pkg- packages.list | sort | sed q).tazpkg
61 wget http://cook.slitaz.org/cross/arm/packages/$pkg
62 tazpkg install $pkg --root=$BASE/
63 done <<EOT
64 /usr/lib/libz.so zlib
65 /usr/sbin/kexec kexec-tools
66 /usr/bin/tset ncursesw
67 /usr/bin/dialog dialog
68 /usr/lib/libxml2.so libxml2 aria2
69 /usr/bin/gpg-error libgpg-error aria2
70 /usr/lib/libgcrypt.so libgcrypt aria2
71 /usr/lib/libgmp.so gmp aria2
72 /usr/lib/libnettle.so nettle aria2
73 /usr/lib/libreadline.so readline aria2
74 /usr/bin/p11-kit p11-kit aria2
75 /usr/lib/libgnutls.so libgnutls aria2
76 /usr/lib/libtasn1.so libtasn1 aria2
77 /usr/bin/gnutls-cli gnutls aria2
78 /usr/bin/aria2c aria2 aria2
79 EOT
81 # deduplicate base & live
82 LIVE=$(ls -d slitaz-rpi-desktop-*/rootfs)
83 [ ! -d "$LIVE" ] && echo "Abort ($LIVE) !" && exit 1
84 LIVESZ=$(du -ks $LIVE | cut -f1)
85 ( cd $BASE/ ; find ! -type d ) | while read file; do
86 if [ -L $BASE/$file ]; then
87 [ -L $LIVE/$file ] &&
88 [ "$(readlink $BASE/$file)" == "$(readlink $LIVE/$file)" ] &&
89 rm -f $LIVE/$file
90 elif [ -f $BASE/$file ]; then
91 [ -f $LIVE/$file ] &&
92 cmp $BASE/$file $LIVE/$file > /dev/null 2>&1 &&
93 rm -f $LIVE/$file
94 elif [ -b $BASE/$file ]; then
95 [ -b $LIVE/$file ] &&
96 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
97 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
98 rm -f $LIVE/$file
99 elif [ -c $BASE/$file ]; then
100 [ -c $LIVE/$file ] &&
101 [ "$(stat -c '%a:%u:%g:%t:%T' $BASE/$file)" == \
102 "$(stat -c '%a:%u:%g:%t:%T' $LIVE/$file)" ] &&
103 rm -f $LIVE/$file
104 fi
105 done
106 ( cd $BASE/ ; find -type d ) | while read dir; do
107 rmdir $LIVE/$dir 2> /dev/null
108 done
110 ( cd $BASE ; find * | cpio -o -H newc ) | \
111 gzip -9 > fs/boot/slitaz/rootfs-base.gz
112 ( cd $LIVE ; find * | cpio -o -H newc ) | \
113 gzip -9 > fs/boot/slitaz/rootfs-live.gz
114 if [ -x /usr/bin/advdef ]; then
115 advdef -z4 fs/boot/slitaz/rootfs-base.gz
116 advdef -z4 fs/boot/slitaz/rootfs-live.gz
117 fi
119 # Create raspbian package
120 echo "2.0" > debian-binary
121 cat > control <<EOT
122 Package: slitaz
123 Version: $VERSION-1
124 Architecture: armhf
125 Maintainer: Pascal Bellard <pascal.bellard@slitaz.org>
126 Installed-Size: $(($(du -ks fs | cut -f1) + $LIVESZ))
127 Section: miscellaneous
128 Priority: optional
129 Homepage: http://arm.slitaz.org/
130 Description: Tiny Linux distribution with multi boot feature
131 SliTaz can run fully in RAM or can be installed on the SD card in a
132 subdirectory of your Raspbian (example /$DESTDIR).
133 EOT
134 ( cd fs ; find * -type f -exec md5sum {} \; ) > md5sums
135 cat > postinst <<EOT
136 #!/bin/sh
138 set -e
140 RDEV=\$(sed 's/.*root=\([^ ]*\).*/\1/' /boot/cmdline.txt)
141 FSTYPE=\$(awk '/ \/ / { if (\$1 != "rootfs") print \$3 }' < /proc/mounts)
143 echo "Extracting /$DESTDIR ..."
144 cd /$DESTDIR
145 zcat /boot/slitaz/rootfs-base.gz | cpio -idmu
146 zcat /boot/slitaz/rootfs-live.gz | cpio -idmu
147 if ! grep -qs raspbian etc/fstab ; then
148 echo "Update /$DESTDIR/etc/fstab ..."
149 mkdir -p mnt/raspbian
150 sed -i 's/noauto,//' etc/fstab
151 cat >> etc/fstab <<EOM
152 \$RDEV /mnt/raspbian \$FSTYPE noatime 0 0
153 tmpfs /mnt/raspbian/$DESTDIR tmpfs size=0 0 0
154 EOM
155 fi
156 cd -
158 if [ ! -f /boot/menu.txt ]; then
160 echo "Update /boot ..."
161 for i in keyboard locale ; do
162 [ -s /etc/default/\$i ] && . /etc/default/\$i
163 done
164 KMAP=\$(find /$DESTDIR/usr/share/kbd/keymaps | grep /\$XKBLAYOUT[.-] | head -n1)
165 [ "\$KMAP" ] && KMAP="kmap=\$(basename \$KMAP .map.gz)"
166 cat > /boot/menu.txt <<EOM
167 title=Raspberry PI boot menu
168 subtitle=Select the OS with ARROW keys and hit RETURN
169 timeout=30
170 default=raspbian
171 \$KMAP
172 edittitle=Edit menu
173 readonly
174 #noedit
175 #nowebboot
176 #webpath=http://my.home.web.site/pxe/rpi/index.php http://or.this.one/rpi.txt
177 EOM
178 KERNEL=\$(sed '/^kernel/!d;s/.*=//' /boot/config.txt)
179 cp /boot/config.txt /boot/cmdline.txt /boot/raspbian/
180 mv /boot/\${KERNEL:-kernel.img} /boot/raspbian/
181 echo "entry=Raspbian \$(cat /etc/debian_version)" > /boot/raspbian/menu.txt
182 sed -i '/^kernel/d;/^initramfs/d' /boot/config.txt
183 echo "kernel=slitaz/kernel.img" >> /boot/config.txt
184 echo "initramfs slitaz/rootfs-base.gz" >> /boot/config.txt
185 echo "root=/dev/null rdinit=/sbin/piboot quiet" > /boot/cmdline.txt
186 L=
187 [ -s /$DESTDIR/usr/share/i18n/locales/\${LANG%.*} ] && L=lang=\${LANG%.*}
188 echo "root=/dev/null \$L \$KMAP rdinit=/sbin/pisubroot mount=\$RDEV subroot=$DESTDIR rootwait quiet" > /boot/slitaz/cmdline.txt
189 echo "root=/dev/null \$L \$KMAP quiet" > /boot/slitaz-base/cmdline.txt
190 cp /boot/slitaz-base/cmdline.txt /boot/slitaz-live/cmdline.txt
192 fi
194 echo "The SliTaz boot menu is available for next (re)boot."
196 exit 0
197 EOT
198 cat > postrm <<EOT
199 #!/bin/sh
201 purge()
202 {
203 echo "Remove /$DESTDIR /boot/slitaz* trees..."
204 rm -rf /$DESTDIR /boot/slitaz*
205 }
207 disable()
208 {
209 if [ -d /boot/rasbian ]; then
210 echo "Restore rasbian boot files..."
211 mv -f /boot/rasbian/* /boot
212 rm -rf /boot/rasbian
213 fi
214 rm -f /boot/menu.txt
215 }
217 case "\$1" in
218 purge)
219 disable
220 purge
221 ;;
222 remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
223 disable
224 ;;
225 *)
226 echo "postrm called with unknown argument \\\`\$1'" >&2
227 exit 0
228 esac
229 EOT
230 chmod +x postinst postrm
231 tar czf control.tar.gz md5sums control postinst postrm
232 rm -rf fs/$DESTDIR/*
233 cd fs ; tar czf ../data.tar.gz . ; cd ..
234 [ -x /usr/bin/ar ] || tazpkg get-install binutils
235 ar rcs slitaz-$VERSION-1_armhf.deb debian-binary control.tar.gz data.tar.gz
236 mv slitaz-$VERSION-1_armhf.deb $CURDIR
237 cd $CURDIR
238 rm -rf $TMPDIR
239 ls -l slitaz-$VERSION-1_armhf.deb