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