slitaz-arm annotate sat @ rev 6
sat: add mirror command
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 25 00:27:28 2012 +0200 (2012-05-25) |
parents | 571517abb48e |
children | 41bdd0275ceb |
rev | line source |
---|---|
pankso@1 | 1 #!/bin/sh |
pankso@1 | 2 # |
pankso@1 | 3 # Sat - SliTaz ARM Tool |
pankso@1 | 4 # |
pankso@1 | 5 # Copyright (C) 2012 SliTaz GNU/Linux - 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@1 | 12 # Internal variables. |
pankso@1 | 13 : ${work=$(pwd)} |
pankso@1 | 14 packages=$work/packages |
pankso@1 | 15 distro=$work/distro |
pankso@6 | 16 # http://mirror.slitaz.org/packages/cooking/arm/ |
pankso@6 | 17 mirror="http://cook.slitaz.org/cross/arm/packages/" |
pankso@1 | 18 |
pankso@1 | 19 # Help and usage |
pankso@1 | 20 usage() { |
pankso@1 | 21 cat << EOT |
pankso@1 | 22 |
pankso@1 | 23 $(boldify "Usage:") $(basename $0) [command|--options] |
pankso@1 | 24 |
pankso@1 | 25 $(boldify "Commands:") |
pankso@1 | 26 gen Generate a disto cpio/gzip initramfs |
pankso@1 | 27 clean Clean up the work directory |
pankso@1 | 28 vdisk Create a virtual disk to be used by Qemu |
pankso@1 | 29 emu Emulate the distro with qemu-system-arm |
pankso@6 | 30 mirror Download or sync the SliTaz ARM mirror |
pankso@1 | 31 |
pankso@1 | 32 $(boldify "Options:") |
pankso@1 | 33 --kmap Dump current keymap and include it in distro |
pankso@1 | 34 --spk Include Spk package manager in the distro |
pankso@1 | 35 --work= Path to work dir with packages and rootfs |
pankso@1 | 36 --size= Specify optional vdisk size (default 20Mb) |
pankso@1 | 37 |
pankso@1 | 38 EOT |
pankso@1 | 39 } |
pankso@1 | 40 |
pankso@6 | 41 # --> use libpkg.sh when release (function is shared with spk) |
pankso@6 | 42 # Check mirror ID: return 1 if no changes or mirror unreachable |
pankso@6 | 43 check_mirror_id() { |
pankso@6 | 44 [ "$forced" ] && rm -f ID |
pankso@6 | 45 [ -f "ID" ] || echo $$ > ID |
pankso@6 | 46 mv ID ID.bak |
pankso@6 | 47 if wget -qs ${mirror%/}/ID; then |
pankso@6 | 48 wget -q ${mirror%/}/ID |
pankso@6 | 49 else |
pankso@6 | 50 gettext "Mirror is unreachable"; false |
pankso@6 | 51 status && return 1 |
pankso@6 | 52 fi |
pankso@6 | 53 if [ "$(cat ID)" == "$(cat ID.bak)" ]; then |
pankso@6 | 54 gettext "Mirror is up-to-date"; true |
pankso@6 | 55 status && return 1 |
pankso@6 | 56 fi |
pankso@6 | 57 } |
pankso@6 | 58 |
pankso@1 | 59 # |
pankso@1 | 60 # Commands |
pankso@1 | 61 # |
pankso@1 | 62 |
pankso@1 | 63 case "$1" in |
pankso@1 | 64 gen) |
pankso@1 | 65 time=$(date +%s) |
pankso@1 | 66 check_root |
pankso@1 | 67 rm -rf $distro distro-arm.gz |
pankso@1 | 68 mkdir -p $distro |
pankso@1 | 69 |
pankso@1 | 70 # Packages. Dep install it not well handled by tazpkg/spk actually |
pankso@1 | 71 # so simply install all packages and dont resolv deps or use equiv. |
pankso@1 | 72 cd $packages |
pankso@1 | 73 for pkg in $packages/*.tazpkg |
pankso@1 | 74 do |
pankso@1 | 75 pkgdir=$(basename $pkg .tazpkg) |
pankso@6 | 76 db=$distro/var/lib/tazpkg |
pankso@1 | 77 echo -n "Installing: $(basename $pkg)" |
pankso@1 | 78 tazpkg extract $pkg >/dev/null |
pankso@1 | 79 . $pkgdir/receipt |
pankso@6 | 80 mkdir -p $db/installed/$PACKAGE |
pankso@1 | 81 cp $pkgdir/receipt $pkgdir/files.list \ |
pankso@6 | 82 $db/installed/$PACKAGE |
pankso@1 | 83 cp -a $pkgdir/fs/* $distro && rm -rf $pkgdir |
pankso@6 | 84 md5sum $(basename $pkg) >> $db/installed.md5 |
pankso@1 | 85 status |
pankso@1 | 86 done |
pankso@1 | 87 |
pankso@1 | 88 # Install spk if requested. Spk multiarch support must be tested |
pankso@1 | 89 if [ "$spk" ]; then |
pankso@1 | 90 hg=http://hg.slitaz.org |
pankso@1 | 91 echo -n "Installing: spk ($hg)" |
pankso@1 | 92 cd $work |
pankso@1 | 93 [ -d "spk" ] || hg clone $hg/spk >/dev/null |
pankso@1 | 94 cd spk |
pankso@1 | 95 [ "$noup" ] || hg pull -u >/dev/null |
pankso@1 | 96 make DESTDIR=$distro install >/dev/null |
pankso@1 | 97 status |
pankso@1 | 98 fi |
pankso@1 | 99 |
pankso@1 | 100 # Move kernel outside the distro |
pankso@1 | 101 cd $work && mv -f $distro/boot/linux-* linux-arm |
pankso@1 | 102 |
pankso@1 | 103 # Get a default kmap |
pankso@1 | 104 if [ "$kmap" ]; then |
pankso@1 | 105 echo -n "Dumping current keymap..." |
pankso@1 | 106 mkdir $distro/usr/share/kmap |
pankso@1 | 107 /bin/busybox dumpkmap > $distro/usr/share/kmap/default.kmap |
pankso@1 | 108 status |
pankso@1 | 109 fi |
pankso@1 | 110 |
pankso@1 | 111 # Fixes: udev not yet cross-compiled |
pankso@1 | 112 echo -n "Applying SliTaz ARM fixes..." |
pankso@1 | 113 sed -i s"/UDEV=.*/UDEV=\"\"/" $distro/etc/rcS.conf |
pankso@1 | 114 status |
pankso@1 | 115 |
pankso@1 | 116 # SLITAZ_ARCH |
pankso@1 | 117 echo -n "Setting SliTaz arch to: arm" |
pankso@1 | 118 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \ |
pankso@1 | 119 $distro/etc/slitaz/slitaz.conf |
pankso@1 | 120 status |
pankso@1 | 121 |
pankso@6 | 122 # Mirror |
pankso@6 | 123 echo "$mirror" > $distro/var/lib/tazpkg/mirror |
pankso@1 | 124 |
pankso@1 | 125 # /usr/cross/arm/lib: Must be FIXED when cross-compiling |
pankso@1 | 126 # Only used by Busybox before LD_LIBRARY_PATH is set. |
pankso@1 | 127 mkdir -p $distro/usr/cross/arm/lib |
pankso@1 | 128 cd $distro/usr/cross/arm/lib |
pankso@1 | 129 ln -s /lib/libc-2.13.so libc.so.6 |
pankso@1 | 130 ln -s /lib/ld-2.13.so ld-linux.so.3 |
pankso@1 | 131 cd $distro |
pankso@1 | 132 |
pankso@1 | 133 # /init |
pankso@1 | 134 rm init && ln -s /bin/busybox init |
pankso@1 | 135 |
pankso@1 | 136 # Update modules.dep |
pankso@1 | 137 depmod -b . 3.2.14-slitaz |
pankso@1 | 138 |
pankso@1 | 139 # Custom rootfs |
pankso@1 | 140 if [ -d "$work/rootfs" ]; then |
pankso@1 | 141 echo -n "Copying custom ARM rootfs..." |
pankso@1 | 142 cp -r $work/rootfs/* $distro |
pankso@1 | 143 status |
pankso@1 | 144 fi |
pankso@1 | 145 |
pankso@1 | 146 # Rootfs cpio/gzip |
pankso@1 | 147 echo -n "Compressing initramfs: cpio/gzip" |
pankso@1 | 148 find . -print | cpio -o -H newc | gzip -9 > ../distro-arm.gz |
pankso@1 | 149 status |
pankso@1 | 150 time=$(($(date +%s) - $time)) |
pankso@1 | 151 echo "Build time : ${time}s" |
pankso@1 | 152 echo -n "Distro size : " |
pankso@1 | 153 cd $work && du -sh distro-arm.gz | awk '{print $1}';; |
pankso@1 | 154 clean) |
pankso@1 | 155 check_root |
pankso@1 | 156 echo -n "Cleaning: $work" |
pankso@1 | 157 rm -rf distro linux-arm distro-arm.gz spk |
pankso@1 | 158 status ;; |
pankso@1 | 159 vdisk) |
pankso@1 | 160 # Let use and HD in Qemu to store files|packages|whatever |
pankso@1 | 161 vdisk="vdisk.img" |
pankso@1 | 162 : ${size=20} |
pankso@1 | 163 cd $work |
pankso@1 | 164 dd if=/dev/zero of=$vdisk bs=1M count=$size |
pankso@1 | 165 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;; |
pankso@1 | 166 emu) |
pankso@1 | 167 : ${mem=256} |
pankso@1 | 168 cd $work |
pankso@1 | 169 [ -f "vdisk.img" ] && opts="-hda vdisk.img" |
pankso@1 | 170 qemu-system-arm -m $mem $opts \ |
pankso@1 | 171 -M versatilepb -cpu arm1176 \ |
pankso@1 | 172 -kernel linux-arm \ |
pankso@1 | 173 -initrd distro-arm.gz ;; |
pankso@6 | 174 mirror) |
pankso@6 | 175 # |
pankso@6 | 176 # --> spk-mirror $mirror --sync --dest=/path ??? |
pankso@6 | 177 # |
pankso@6 | 178 # Just dl lists/packages for now, we can add a --rsync option to |
pankso@6 | 179 # have all mirrored packages locally to build distro's. |
pankso@6 | 180 count=0 |
pankso@6 | 181 mkdir -p $work/mirror && cd $work/mirror |
pankso@6 | 182 if ! check_mirror_id; then |
pankso@6 | 183 exit 0 |
pankso@6 | 184 fi |
pankso@6 | 185 for list in packages.list packages.desc packages.md5; do |
pankso@6 | 186 echo -n "Fetching: $list" |
pankso@6 | 187 rm -f $list && wget -q ${mirror%/}/$list |
pankso@6 | 188 status |
pankso@6 | 189 done |
pankso@6 | 190 echo -n "Checking packages $SUM..." |
pankso@6 | 191 for pkg in $(cat $work/mirror/packages.list); do |
pankso@6 | 192 pkg=${pkg}.tazpkg |
pankso@6 | 193 pkgsum=$($CHECKSUM $pkg) |
pankso@6 | 194 debug "$pkgsum" |
pankso@6 | 195 [ "$pkgsum" ] || pkgsum=$$ |
pankso@6 | 196 mirsum=$(fgrep -h $pkgsum packages.$SUM) |
pankso@6 | 197 debug "$mirsum" |
pankso@6 | 198 if [ ! "$pkgsum" == "$mirsum" ] || [ ! -f "$pkg" ] ; then |
pankso@6 | 199 count=$($count + 1) |
pankso@6 | 200 [ "$count" == 1 ] && newline |
pankso@6 | 201 echo -n "Fetching: ${pkg}.tazpkg" |
pankso@6 | 202 rm -f $pkg |
pankso@6 | 203 wget -q ${mirror%/}/$pkg |
pankso@6 | 204 status |
pankso@6 | 205 fi |
pankso@6 | 206 done |
pankso@6 | 207 [ "$count" == 0 ] && status |
pankso@6 | 208 ;; |
pankso@1 | 209 *) usage ;; |
pankso@1 | 210 esac |
pankso@1 | 211 exit 0 |