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