slitaz-arm annotate sat @ rev 28

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