# HG changeset patch # User Christophe Lincoln # Date 1337898448 -7200 # Node ID e885f2eb3b08b145a59a56b67c2e0b53f9cac598 # Parent 44ff1bd1fa6d4d61c76c0a48cf8a4af8a1153b86 sat: add mirror command diff -r 44ff1bd1fa6d -r e885f2eb3b08 .hgignore --- a/.hgignore Thu May 24 22:33:13 2012 +0200 +++ b/.hgignore Fri May 25 00:27:28 2012 +0200 @@ -1,3 +1,4 @@ +mirror/ packages/ spk/ linux-arm diff -r 44ff1bd1fa6d -r e885f2eb3b08 sat --- a/sat Thu May 24 22:33:13 2012 +0200 +++ b/sat Fri May 25 00:27:28 2012 +0200 @@ -6,11 +6,15 @@ # Author: Christophe Lincoln # . /lib/libtaz.sh +#. /usr/lib/slitaz/libpkg.sh +. /etc/slitaz/slitaz.conf # Internal variables. : ${work=$(pwd)} packages=$work/packages distro=$work/distro +# http://mirror.slitaz.org/packages/cooking/arm/ +mirror="http://cook.slitaz.org/cross/arm/packages/" # Help and usage usage() { @@ -23,6 +27,7 @@ clean Clean up the work directory vdisk Create a virtual disk to be used by Qemu emu Emulate the distro with qemu-system-arm + mirror Download or sync the SliTaz ARM mirror $(boldify "Options:") --kmap Dump current keymap and include it in distro @@ -33,6 +38,24 @@ EOT } +# --> use libpkg.sh when release (function is shared with spk) +# Check mirror ID: return 1 if no changes or mirror unreachable +check_mirror_id() { + [ "$forced" ] && rm -f ID + [ -f "ID" ] || echo $$ > ID + mv ID ID.bak + if wget -qs ${mirror%/}/ID; then + wget -q ${mirror%/}/ID + else + gettext "Mirror is unreachable"; false + status && return 1 + fi + if [ "$(cat ID)" == "$(cat ID.bak)" ]; then + gettext "Mirror is up-to-date"; true + status && return 1 + fi +} + # # Commands # @@ -50,13 +73,15 @@ for pkg in $packages/*.tazpkg do pkgdir=$(basename $pkg .tazpkg) + db=$distro/var/lib/tazpkg echo -n "Installing: $(basename $pkg)" tazpkg extract $pkg >/dev/null . $pkgdir/receipt - mkdir -p $distro/var/lib/tazpkg/installed/$PACKAGE + mkdir -p $db/installed/$PACKAGE cp $pkgdir/receipt $pkgdir/files.list \ - $distro/var/lib/tazpkg/installed/$PACKAGE + $db/installed/$PACKAGE cp -a $pkgdir/fs/* $distro && rm -rf $pkgdir + md5sum $(basename $pkg) >> $db/installed.md5 status done @@ -94,11 +119,8 @@ $distro/etc/slitaz/slitaz.conf status - # Mirror --> http://mirror.slitaz.org/packages/cooking/arm/ - echo 'http://cook.slitaz.org/cross/arm/packages/' \ - > $distro/var/lib/tazpkg/mirror - #wget -q http://cook.slitaz.org/cross/arm/packages/packages.desc \ - #-O $distro/var/lib/tazpkg/packages.desc + # Mirror + echo "$mirror" > $distro/var/lib/tazpkg/mirror # /usr/cross/arm/lib: Must be FIXED when cross-compiling # Only used by Busybox before LD_LIBRARY_PATH is set. @@ -149,6 +171,41 @@ -M versatilepb -cpu arm1176 \ -kernel linux-arm \ -initrd distro-arm.gz ;; + mirror) + # + # --> spk-mirror $mirror --sync --dest=/path ??? + # + # Just dl lists/packages for now, we can add a --rsync option to + # have all mirrored packages locally to build distro's. + count=0 + mkdir -p $work/mirror && cd $work/mirror + if ! check_mirror_id; then + exit 0 + fi + for list in packages.list packages.desc packages.md5; do + echo -n "Fetching: $list" + rm -f $list && wget -q ${mirror%/}/$list + status + done + echo -n "Checking packages $SUM..." + for pkg in $(cat $work/mirror/packages.list); do + pkg=${pkg}.tazpkg + pkgsum=$($CHECKSUM $pkg) + debug "$pkgsum" + [ "$pkgsum" ] || pkgsum=$$ + mirsum=$(fgrep -h $pkgsum packages.$SUM) + debug "$mirsum" + if [ ! "$pkgsum" == "$mirsum" ] || [ ! -f "$pkg" ] ; then + count=$($count + 1) + [ "$count" == 1 ] && newline + echo -n "Fetching: ${pkg}.tazpkg" + rm -f $pkg + wget -q ${mirror%/}/$pkg + status + fi + done + [ "$count" == 0 ] && status + ;; *) usage ;; esac exit 0