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