slitaz-arm annotate sat @ rev 75
Add slim support and custom rpi theme
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 23 14:37:38 2014 +0100 (2014-03-23) |
parents | f74a9206fdd0 |
children | 7f8c51f837a5 |
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@50 | 51 --size= Specify optional vdisk size (default 50Mb) |
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@55 | 139 # Install spk Hg 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 # SLITAZ_ARCH |
pankso@27 | 152 if [ -f "${rootfs}/etc/slitaz/slitaz.conf" ]; then |
pankso@27 | 153 echo -n "Setting SliTaz arch to: arm" |
pankso@27 | 154 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \ |
pankso@27 | 155 ${rootfs}/etc/slitaz/slitaz.conf |
pankso@27 | 156 status |
pankso@27 | 157 else |
pankso@27 | 158 echo -n "Missing distro: /etc/slitaz/slitaz.conf"; false |
pankso@27 | 159 status && exit 1 |
pankso@27 | 160 fi |
pankso@1 | 161 |
pankso@6 | 162 # Mirror |
pankso@26 | 163 echo "$mirror" > ${rootfs}/var/lib/tazpkg/mirror |
pankso@1 | 164 |
pankso@62 | 165 # /init & /var/run |
pankso@26 | 166 cd ${rootfs} |
pankso@62 | 167 rm init var/run && ln -s /bin/busybox init |
pankso@62 | 168 mkdir -p run var/run |
pankso@1 | 169 |
pankso@1 | 170 # Update modules.dep |
pankso@27 | 171 if [ -f "var/lib/tazpkg/installed/linux/receipt" ]; then |
pankso@27 | 172 . var/lib/tazpkg/installed/linux/receipt |
pankso@27 | 173 depmod -b . ${VERSION}-slitaz |
pankso@27 | 174 fi |
pankso@55 | 175 |
pankso@55 | 176 # CGI Admin |
pankso@55 | 177 if [ -d "$work/cgi-adm" ]; then |
pankso@55 | 178 echo -n "Installing SliTaz ARM CGI Admin interface..." |
pankso@58 | 179 mkdir -p ${rootfs}/var/www/adm |
pankso@58 | 180 cp -a ${work}/cgi-adm/* ${rootfs}/var/www/adm |
pankso@55 | 181 status |
pankso@55 | 182 fi |
pankso@1 | 183 |
pankso@26 | 184 # Custom rootfs: make sure all files belong to root |
pankso@1 | 185 if [ -d "$work/rootfs" ]; then |
pankso@27 | 186 size=$(du -sh $work/rootfs | awk '{print $1}') |
pankso@27 | 187 echo -n "Copying custom ARM rootfs: $size" |
pankso@26 | 188 tmp=$distro/tmp-$$ |
pankso@11 | 189 mkdir -p $tmp |
pankso@11 | 190 cp -r $work/rootfs/* $tmp |
pankso@11 | 191 chown -R root.root $tmp |
pankso@26 | 192 cp -a $tmp/* ${rootfs} && rm -rf $tmp |
pankso@26 | 193 status |
pankso@26 | 194 fi |
pankso@26 | 195 |
pankso@26 | 196 # Custom flavor rootfs |
pankso@37 | 197 if [ -f "${cache}/flavor.conf" ]; then |
pankso@37 | 198 . ${cache}/flavor.conf |
pankso@27 | 199 fi |
pankso@27 | 200 if [ -d "$flavors/${FLAVOR}/rootfs" ]; then |
pankso@27 | 201 size=$(du -sh $flavors/${FLAVOR}/rootfs | awk '{print $1}') |
pankso@27 | 202 echo -n "Copying ${FLAVOR} ARM rootfs: $size" |
pankso@26 | 203 tmp=$distro/tmp-$$ |
pankso@26 | 204 mkdir -p $tmp |
pankso@27 | 205 cp -r $flavors/${FLAVOR}/rootfs/* $tmp |
pankso@26 | 206 chown -R root.root $tmp |
pankso@26 | 207 cp -a $tmp/* ${rootfs} && rm -rf $tmp |
pankso@26 | 208 status |
pankso@26 | 209 fi |
pankso@26 | 210 |
pankso@26 | 211 # --kmap |
pankso@26 | 212 if [ "$kmap" ]; then |
pankso@26 | 213 echo -n "Copying local: /etc/keymap.conf" |
pankso@28 | 214 cp -f /etc/keymap.conf ${rootfs}/etc |
pankso@28 | 215 status |
pankso@28 | 216 fi |
pankso@28 | 217 |
pankso@28 | 218 # Distro: /etc/slitaz/flavor.conf |
pankso@37 | 219 if [ -f "${cache}/flavor.conf" ]; then |
pankso@28 | 220 echo -n "Including $FLAVOR: flavor.conf" |
pankso@37 | 221 echo "BUILD_DATE=\"$(date '+%Y%m%d')\"" >> ${cache}/flavor.conf |
pankso@37 | 222 cp -f ${cache}/flavor.conf ${rootfs}/etc/slitaz |
pankso@1 | 223 status |
pankso@1 | 224 fi |
pankso@50 | 225 |
pankso@50 | 226 # Move /boot outside the rootfs |
pankso@63 | 227 mkdir -p ${rootfs}/boot |
pankso@50 | 228 if [ "$(ls $rootfs/boot | wc -l)" != 0 ]; then |
pankso@50 | 229 echo -n "Moving /boot outside the rootfs..." |
pankso@50 | 230 mkdir -p ${distro}/boot |
pankso@50 | 231 mv -f ${rootfs}/boot/* ${distro}/boot |
pankso@50 | 232 status |
pankso@50 | 233 |
pankso@50 | 234 # ! wok/linux pkg must be modified to install /boot/kernel.img |
pankso@50 | 235 if ls ${distro}/boot/linux-* >/dev/null 2>/dev/null; then |
pankso@50 | 236 mv ${distro}/boot/linux-* ${distro}/boot/kernel.img |
pankso@50 | 237 chmod -x ${distro}/boot/kernel.img |
pankso@50 | 238 fi |
pankso@50 | 239 |
pankso@50 | 240 fi |
pankso@1 | 241 |
pankso@11 | 242 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ??? |
pankso@30 | 243 if [ ! "$noinit" ]; then |
pankso@30 | 244 echo -n "Compressing initramfs: $initramfs" |
pankso@30 | 245 case "$initramfs" in |
pankso@30 | 246 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;; |
pankso@30 | 247 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;; |
pankso@30 | 248 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;; |
pankso@30 | 249 esac |
pankso@33 | 250 status |
pankso@30 | 251 fi |
pankso@25 | 252 |
pankso@37 | 253 # Clean if no debug mode |
pankso@37 | 254 [ "$debug" ] || rm -rf ${cache} |
pankso@37 | 255 |
pankso@25 | 256 # Summary |
pankso@50 | 257 time=$(($(date +%s) - $time)) |
pankso@50 | 258 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')" |
pankso@50 | 259 pkgs_count="$(ls $db/installed | wc -l)" |
pankso@50 | 260 [ "$noinit" ] || \ |
pankso@50 | 261 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')" |
pankso@30 | 262 separator && newline |
pankso@25 | 263 boldify "SliTaz ARM distro summary" |
pankso@25 | 264 separator |
pankso@27 | 265 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR" |
pankso@27 | 266 echo "Build time : ${time}s" |
pankso@33 | 267 [ "$noinit" ] || echo "Initramfs : $initramfs" |
pankso@33 | 268 [ "$noinit" ] || echo "Initramfs size : $initramfs_size" |
pankso@27 | 269 echo "Rootfs size : $rootfs_size" |
pankso@27 | 270 echo "Packages : $pkgs_count" |
pankso@37 | 271 separator |
pankso@37 | 272 [ "$rpi" ] || newline ;; |
pankso@23 | 273 |
pankso@23 | 274 flavors) |
pankso@26 | 275 newline |
pankso@27 | 276 echo -n "$(boldify 'Flavor')" && |
pankso@27 | 277 echo -n "$(indent 12 $(boldify 'Packages'))" |
pankso@27 | 278 indent 24 $(boldify 'Description') |
pankso@23 | 279 separator |
pankso@23 | 280 for flavor in $(ls $flavors) |
pankso@23 | 281 do |
pankso@27 | 282 . $flavors/$flavor/flavor.conf |
pankso@23 | 283 pkgs=$(cat $flavors/$flavor/packages.list | wc -l) |
pankso@27 | 284 echo -n "$flavor" && |
pankso@27 | 285 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC" |
pankso@27 | 286 unset SHORT_DESC |
pankso@23 | 287 done |
pankso@26 | 288 newline ;; |
pankso@21 | 289 |
pankso@26 | 290 ckpkgs) |
pankso@26 | 291 installed="${rootfs}/var/lib/tazpkg/installed" |
pankso@25 | 292 SLITAZ_ARCH="arm" |
pankso@25 | 293 count=0 |
pankso@26 | 294 if [ ! -d "$installed" ]; then |
pankso@26 | 295 echo "Missing distro rootfs" && exit 1 |
pankso@26 | 296 fi |
pankso@25 | 297 echo "" |
pankso@26 | 298 echo -n "$(boldify 'Package name')" |
paul@29 | 299 indent 24 "$(boldify 'Missing dependencies')" |
pankso@25 | 300 separator |
pankso@25 | 301 for pkg in ${installed}/* |
pankso@25 | 302 do |
pankso@25 | 303 . $pkg/receipt |
pankso@25 | 304 for dep in $DEPENDS |
pankso@25 | 305 do |
pankso@25 | 306 if [ ! -d "${installed}/$dep" ]; then |
pankso@63 | 307 if [ ! "$raw" ]; then |
pankso@63 | 308 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep" |
pankso@63 | 309 else |
pankso@63 | 310 echo "$dep" |
pankso@63 | 311 fi |
pankso@25 | 312 count=$(($count + 1)) |
pankso@25 | 313 fi |
pankso@25 | 314 done |
pankso@25 | 315 unset DEPENDS |
pankso@25 | 316 done |
pankso@25 | 317 if [ "$count" == 0 ]; then |
pankso@25 | 318 echo "No missing dependencies" |
pankso@25 | 319 fi |
pankso@25 | 320 separator |
pankso@25 | 321 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l) |
pankso@26 | 322 newline ;; |
pankso@25 | 323 |
pankso@1 | 324 clean) |
pankso@1 | 325 check_root |
pankso@26 | 326 echo -n "Cleaning: distro" |
pankso@26 | 327 rm -rf $distro && status |
pankso@26 | 328 if [ "$spk" ]; then |
pankso@26 | 329 echo -n "Cleaning: spk" |
pankso@26 | 330 rm -rf $work/spk && status |
pankso@26 | 331 fi ;; |
pankso@21 | 332 |
pankso@1 | 333 vdisk) |
paul@17 | 334 # Lets use and HD in Qemu to store files|packages|whatever |
pankso@1 | 335 vdisk="vdisk.img" |
pankso@50 | 336 : ${size=50} |
pankso@30 | 337 newline |
pankso@28 | 338 echo "Creating virtual disk: $vdisk" |
pankso@1 | 339 cd $work |
pankso@1 | 340 dd if=/dev/zero of=$vdisk bs=1M count=$size |
pankso@28 | 341 # Partition |
pankso@50 | 342 echo "Creating a partition with: fdisk" |
pankso@30 | 343 fdisk ${vdisk} >/dev/null << EOT |
pankso@28 | 344 o |
pankso@28 | 345 n |
pankso@28 | 346 p |
pankso@28 | 347 1 |
pankso@30 | 348 w |
pankso@30 | 349 EOT |
pankso@30 | 350 newline ;; |
pankso@21 | 351 |
pankso@1 | 352 emu) |
pankso@1 | 353 cd $work |
pankso@1 | 354 [ -f "vdisk.img" ] && opts="-hda vdisk.img" |
pankso@28 | 355 [ "$append" ] && append="-append ${append}" |
pankso@28 | 356 qemu-system-arm -m 256 ${opts} \ |
pankso@1 | 357 -M versatilepb -cpu arm1176 \ |
pankso@50 | 358 -kernel ${distro}/boot/kernel.img \ |
pankso@28 | 359 -initrd ${distro}/${initramfs} ${append} ;; |
pankso@21 | 360 |
pankso@6 | 361 mirror) |
pankso@6 | 362 # |
pankso@6 | 363 # --> spk-mirror $mirror --sync --dest=/path ??? |
pankso@6 | 364 # |
pankso@6 | 365 count=0 |
pankso@26 | 366 newline && boldify "Syncing SliTaz ARM mirror" |
pankso@26 | 367 separator |
pankso@6 | 368 mkdir -p $work/mirror && cd $work/mirror |
pankso@26 | 369 |
pankso@26 | 370 echo -n "URL: " && colorize 34 "$mirror" |
pankso@6 | 371 if ! check_mirror_id; then |
pankso@50 | 372 exit 0 |
pankso@6 | 373 fi |
pankso@6 | 374 for list in packages.list packages.desc packages.md5; do |
pankso@6 | 375 echo -n "Fetching: $list" |
pankso@6 | 376 rm -f $list && wget -q ${mirror%/}/$list |
pankso@6 | 377 status |
pankso@6 | 378 done |
pankso@6 | 379 echo -n "Checking packages $SUM..." |
pankso@6 | 380 for pkg in $(cat $work/mirror/packages.list); do |
pankso@6 | 381 pkg=${pkg}.tazpkg |
pankso@7 | 382 if [ ! -f "$pkg" ]; then |
pankso@7 | 383 count=$(($count + 1)) |
pankso@7 | 384 [ "$count" == 1 ] && newline |
pankso@20 | 385 echo -n "Fetching: ${pkg}" |
pankso@7 | 386 wget -q ${mirror%/}/$pkg |
pankso@7 | 387 status |
pankso@7 | 388 fi |
pankso@6 | 389 pkgsum=$($CHECKSUM $pkg) |
pankso@6 | 390 debug "$pkgsum" |
pankso@6 | 391 [ "$pkgsum" ] || pkgsum=$$ |
pankso@6 | 392 mirsum=$(fgrep -h $pkgsum packages.$SUM) |
pankso@6 | 393 debug "$mirsum" |
pankso@7 | 394 if [ ! "$pkgsum" == "$mirsum" ]; then |
pankso@7 | 395 count=$(($count + 1)) |
pankso@6 | 396 [ "$count" == 1 ] && newline |
pankso@6 | 397 echo -n "Fetching: ${pkg}.tazpkg" |
pankso@6 | 398 rm -f $pkg |
pankso@6 | 399 wget -q ${mirror%/}/$pkg |
pankso@6 | 400 status |
pankso@6 | 401 fi |
pankso@6 | 402 done |
pankso@26 | 403 [ "$count" == 0 ] && status |
pankso@26 | 404 separator && newline ;; |
pankso@21 | 405 |
pankso@1 | 406 *) usage ;; |
pankso@1 | 407 esac |
pankso@1 | 408 exit 0 |