slitaz-arm annotate rpi/tazbian @ rev 207

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