slitaz-arm annotate sat @ rev 21

sat: some fixes and improvments
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 23 16:27:57 2014 +0100 (2014-02-23)
parents 432ac2334e26
children 6d8bc047addb
rev   line source
pankso@1 1 #!/bin/sh
pankso@1 2 #
pankso@1 3 # Sat - SliTaz ARM Tool
pankso@1 4 #
pankso@13 5 # Copyright (C) 2012 SliTaz ARM - BSD License
pankso@1 6 # Author: Christophe Lincoln <pankso@slitaz.org>
pankso@1 7 #
pankso@1 8 . /lib/libtaz.sh
pankso@6 9 #. /usr/lib/slitaz/libpkg.sh
pankso@6 10 . /etc/slitaz/slitaz.conf
pankso@1 11
pankso@11 12 # Internal variables: libtaz.sh set: --work= --init=
pankso@11 13 [ "$work" ] || work="$(pwd)"
pankso@11 14 [ "$init" ] || init="gz"
pankso@11 15 initramfs="slitaz-arm.$init"
pankso@1 16 packages=$work/packages
pankso@1 17 distro=$work/distro
pankso@6 18 # http://mirror.slitaz.org/packages/cooking/arm/
pankso@6 19 mirror="http://cook.slitaz.org/cross/arm/packages/"
pankso@1 20
pankso@1 21 # Help and usage
pankso@1 22 usage() {
pankso@1 23 cat << EOT
pankso@1 24
pankso@1 25 $(boldify "Usage:") $(basename $0) [command|--options]
pankso@1 26
pankso@1 27 $(boldify "Commands:")
paul@17 28 gen Generate a distro cpio/gzip initramfs
pankso@1 29 clean Clean up the work directory
pankso@1 30 vdisk Create a virtual disk to be used by Qemu
pankso@1 31 emu Emulate the distro with qemu-system-arm
pankso@6 32 mirror Download or sync the SliTaz ARM mirror
pankso@1 33
pankso@1 34 $(boldify "Options:")
pankso@1 35 --spk Include Spk package manager in the distro
pankso@13 36 --kmap Include the system keymap config in the distro
pankso@1 37 --work= Path to work dir with packages and rootfs
pankso@1 38 --size= Specify optional vdisk size (default 20Mb)
pankso@20 39 --init= Specify the initramfs compression: gz bz2 xz
pankso@1 40
pankso@1 41 EOT
pankso@1 42 }
pankso@1 43
paul@17 44 # --> use libpkg.sh when released (function is shared with spk)
pankso@6 45 # Check mirror ID: return 1 if no changes or mirror unreachable
pankso@6 46 check_mirror_id() {
pankso@6 47 [ "$forced" ] && rm -f ID
pankso@6 48 [ -f "ID" ] || echo $$ > ID
pankso@6 49 mv ID ID.bak
pankso@20 50 if busybox wget -qs ${mirror%/}/ID 2>/dev/null; then
pankso@20 51 busybox wget -q ${mirror%/}/ID
pankso@6 52 else
pankso@6 53 gettext "Mirror is unreachable"; false
pankso@6 54 status && return 1
pankso@6 55 fi
pankso@6 56 if [ "$(cat ID)" == "$(cat ID.bak)" ]; then
pankso@6 57 gettext "Mirror is up-to-date"; true
pankso@6 58 status && return 1
pankso@6 59 fi
pankso@6 60 }
pankso@6 61
pankso@1 62 #
pankso@1 63 # Commands
pankso@1 64 #
pankso@1 65
pankso@1 66 case "$1" in
pankso@1 67 gen)
pankso@1 68 time=$(date +%s)
pankso@1 69 check_root
pankso@9 70 rm -rf $distro slitaz-arm.xz
pankso@1 71 mkdir -p $distro
pankso@1 72
paul@17 73 # Packages. Dep install is not well handled by tazpkg/spk actually.
pankso@21 74 # So simply install all packages and don't resolve deps.
pankso@21 75 if [ -f "packages.list" ]; then
pankso@21 76 for pkg in $(cat $packages.list)
pankso@21 77 do
pankso@21 78 IFS="|"
pankso@21 79 grep "^$pkg |" $work/mirror/packages.desc | while read pkg version desc
pankso@21 80 do
pankso@21 81 echo ${pkg}-${version}.tazpkg | sed s'/ //'g
pankso@21 82 done
pankso@21 83 unset IFS
pankso@21 84 done
pankso@21 85 exit 0
pankso@21 86 else
pankso@21 87 [ ! -d "$packages" ] && echo "Missing: $packages" && exit 1
pankso@1 88 cd $packages
pankso@1 89 for pkg in $packages/*.tazpkg
pankso@1 90 do
pankso@1 91 pkgdir=$(basename $pkg .tazpkg)
pankso@6 92 db=$distro/var/lib/tazpkg
pankso@1 93 echo -n "Installing: $(basename $pkg)"
pankso@1 94 tazpkg extract $pkg >/dev/null
pankso@1 95 . $pkgdir/receipt
pankso@6 96 mkdir -p $db/installed/$PACKAGE
pankso@1 97 cp $pkgdir/receipt $pkgdir/files.list \
pankso@6 98 $db/installed/$PACKAGE
pankso@1 99 cp -a $pkgdir/fs/* $distro && rm -rf $pkgdir
pankso@6 100 md5sum $(basename $pkg) >> $db/installed.md5
pankso@1 101 status
pankso@1 102 done
pankso@21 103 fi
pankso@1 104
pankso@1 105 # Install spk if requested. Spk multiarch support must be tested
pankso@1 106 if [ "$spk" ]; then
pankso@1 107 hg=http://hg.slitaz.org
pankso@1 108 echo -n "Installing: spk ($hg)"
pankso@1 109 cd $work
pankso@1 110 [ -d "spk" ] || hg clone $hg/spk >/dev/null
pankso@7 111 cd $work/spk
pankso@1 112 [ "$noup" ] || hg pull -u >/dev/null
pankso@1 113 make DESTDIR=$distro install >/dev/null
pankso@1 114 status
pankso@1 115 fi
pankso@1 116
pankso@1 117 # Move kernel outside the distro
pankso@21 118 if [ -d "$distro/boot" ]; then
pankso@21 119 cd $work && mv -f $distro/boot/linux-* linux-arm
pankso@21 120 else
pankso@21 121 echo -n "Missing: $distro/boot"; false
pankso@21 122 status && exit 1
pankso@21 123 fi
pankso@1 124
pankso@1 125 # SLITAZ_ARCH
pankso@1 126 echo -n "Setting SliTaz arch to: arm"
pankso@1 127 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
pankso@1 128 $distro/etc/slitaz/slitaz.conf
pankso@1 129 status
pankso@1 130
pankso@6 131 # Mirror
pankso@6 132 echo "$mirror" > $distro/var/lib/tazpkg/mirror
pankso@1 133
pankso@19 134 # /init & /run
pankso@1 135 cd $distro
pankso@1 136 rm init && ln -s /bin/busybox init
pankso@21 137 mkdir -p run
pankso@1 138
pankso@1 139 # Update modules.dep
pankso@20 140 . var/lib/tazpkg/installed/linux/receipt
pankso@20 141 depmod -b . ${VERSION}-slitaz
pankso@1 142
pankso@11 143 # Custom rootfs: make sure all files belong to root.
pankso@1 144 if [ -d "$work/rootfs" ]; then
pankso@1 145 echo -n "Copying custom ARM rootfs..."
pankso@11 146 tmp=$work/tmp-$$
pankso@11 147 mkdir -p $tmp
pankso@11 148 cp -r $work/rootfs/* $tmp
pankso@13 149 if [ "$kmap" ]; then
pankso@13 150 cp /etc/keymap.conf $tmp/etc
pankso@13 151 fi
pankso@11 152 chown -R root.root $tmp
pankso@11 153 cp -a $tmp/* $distro && rm -rf $tmp
pankso@1 154 status
pankso@1 155 fi
pankso@1 156
pankso@11 157 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
pankso@11 158 echo -n "Compressing initramfs: $initramfs"
pankso@11 159 case $initramfs in
pankso@20 160 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
pankso@11 161 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
pankso@11 162 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma \
pankso@9 163 > ../$initramfs ;;
pankso@9 164 esac
pankso@1 165 status
pankso@1 166 time=$(($(date +%s) - $time))
pankso@1 167 echo "Build time : ${time}s"
pankso@1 168 echo -n "Distro size : "
pankso@9 169 cd $work && du -sh $initramfs | awk '{print $1}' ;;
pankso@21 170
pankso@1 171 clean)
pankso@1 172 check_root
pankso@9 173 for r in distro linux-arm *.*z spk; do
pankso@9 174 echo -n "Cleaning: $r"
pankso@9 175 rm -rf $work/$r && status
pankso@9 176 done ;;
pankso@21 177
pankso@1 178 vdisk)
paul@17 179 # Lets use and HD in Qemu to store files|packages|whatever
pankso@1 180 vdisk="vdisk.img"
pankso@1 181 : ${size=20}
pankso@1 182 cd $work
pankso@1 183 dd if=/dev/zero of=$vdisk bs=1M count=$size
pankso@1 184 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;;
pankso@21 185
pankso@1 186 emu)
pankso@1 187 cd $work
pankso@1 188 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
pankso@9 189 qemu-system-arm -m 256 $opts \
pankso@1 190 -M versatilepb -cpu arm1176 \
pankso@1 191 -kernel linux-arm \
pankso@9 192 -initrd $initramfs ;;
pankso@21 193
pankso@6 194 mirror)
pankso@6 195 #
pankso@6 196 # --> spk-mirror $mirror --sync --dest=/path ???
pankso@6 197 #
pankso@6 198 count=0
pankso@6 199 mkdir -p $work/mirror && cd $work/mirror
pankso@6 200 if ! check_mirror_id; then
pankso@6 201 exit 0
pankso@6 202 fi
pankso@6 203 for list in packages.list packages.desc packages.md5; do
pankso@6 204 echo -n "Fetching: $list"
pankso@6 205 rm -f $list && wget -q ${mirror%/}/$list
pankso@6 206 status
pankso@6 207 done
pankso@6 208 echo -n "Checking packages $SUM..."
pankso@6 209 for pkg in $(cat $work/mirror/packages.list); do
pankso@6 210 pkg=${pkg}.tazpkg
pankso@7 211 if [ ! -f "$pkg" ]; then
pankso@7 212 count=$(($count + 1))
pankso@7 213 [ "$count" == 1 ] && newline
pankso@20 214 echo -n "Fetching: ${pkg}"
pankso@7 215 wget -q ${mirror%/}/$pkg
pankso@7 216 status
pankso@7 217 fi
pankso@6 218 pkgsum=$($CHECKSUM $pkg)
pankso@6 219 debug "$pkgsum"
pankso@6 220 [ "$pkgsum" ] || pkgsum=$$
pankso@6 221 mirsum=$(fgrep -h $pkgsum packages.$SUM)
pankso@6 222 debug "$mirsum"
pankso@7 223 if [ ! "$pkgsum" == "$mirsum" ]; then
pankso@7 224 count=$(($count + 1))
pankso@6 225 [ "$count" == 1 ] && newline
pankso@6 226 echo -n "Fetching: ${pkg}.tazpkg"
pankso@6 227 rm -f $pkg
pankso@6 228 wget -q ${mirror%/}/$pkg
pankso@6 229 status
pankso@6 230 fi
pankso@6 231 done
pankso@21 232 [ "$count" == 0 ] && status ;;
pankso@21 233
pankso@1 234 *) usage ;;
pankso@1 235 esac
pankso@1 236 exit 0