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