slitaz-arm annotate rpi/tazbian @ rev 202

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