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