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