slitaz-arm annotate sat @ rev 25

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