slitaz-arm view sat @ rev 14
sync date in rcS
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat May 26 12:10:08 2012 +0200 (2012-05-26) |
parents | f915047f70ad |
children | 68f82e46d19b |
line source
1 #!/bin/sh
2 #
3 # Sat - SliTaz ARM Tool
4 #
5 # Copyright (C) 2012 SliTaz ARM - 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 --kmap Include the system keymap config 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 # Fixes: udev not yet cross-compiled
107 echo -n "Applying SliTaz ARM fixes..."
108 sed -i s"/UDEV=.*/UDEV=\"\"/" $distro/etc/rcS.conf
109 status
111 # SLITAZ_ARCH
112 echo -n "Setting SliTaz arch to: arm"
113 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
114 $distro/etc/slitaz/slitaz.conf
115 status
117 # Mirror
118 echo "$mirror" > $distro/var/lib/tazpkg/mirror
120 # /usr/cross/arm/lib: Must be FIXED when cross-compiling
121 # Only used by Busybox before LD_LIBRARY_PATH is set.
122 mkdir -p $distro/usr/cross/arm/lib
123 cd $distro/usr/cross/arm/lib
124 ln -s /lib/libc-2.13.so libc.so.6
125 ln -s /lib/ld-2.13.so ld-linux.so.3
126 cd $distro
128 # /init
129 rm init && ln -s /bin/busybox init
131 # Update modules.dep
132 depmod -b . 3.2.14-slitaz
134 # Custom rootfs: make sure all files belong to root.
135 if [ -d "$work/rootfs" ]; then
136 echo -n "Copying custom ARM rootfs..."
137 tmp=$work/tmp-$$
138 mkdir -p $tmp
139 cp -r $work/rootfs/* $tmp
140 if [ "$kmap" ]; then
141 cp /etc/keymap.conf $tmp/etc
142 fi
143 chown -R root.root $tmp
144 cp -a $tmp/* $distro && rm -rf $tmp
145 status
146 fi
148 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
149 echo -n "Compressing initramfs: $initramfs"
150 case $initramfs in
151 *.bz) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
152 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
153 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma \
154 > ../$initramfs ;;
155 esac
156 status
157 time=$(($(date +%s) - $time))
158 echo "Build time : ${time}s"
159 echo -n "Distro size : "
160 cd $work && du -sh $initramfs | awk '{print $1}' ;;
161 clean)
162 check_root
163 for r in distro linux-arm *.*z spk; do
164 echo -n "Cleaning: $r"
165 rm -rf $work/$r && status
166 done ;;
167 vdisk)
168 # Let use and HD in Qemu to store files|packages|whatever
169 vdisk="vdisk.img"
170 : ${size=20}
171 cd $work
172 dd if=/dev/zero of=$vdisk bs=1M count=$size
173 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;;
174 emu)
175 cd $work
176 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
177 qemu-system-arm -m 256 $opts \
178 -M versatilepb -cpu arm1176 \
179 -kernel linux-arm \
180 -initrd $initramfs ;;
181 mirror)
182 #
183 # --> spk-mirror $mirror --sync --dest=/path ???
184 #
185 count=0
186 mkdir -p $work/mirror && cd $work/mirror
187 if ! check_mirror_id; then
188 exit 0
189 fi
190 for list in packages.list packages.desc packages.md5; do
191 echo -n "Fetching: $list"
192 rm -f $list && wget -q ${mirror%/}/$list
193 status
194 done
195 echo -n "Checking packages $SUM..."
196 for pkg in $(cat $work/mirror/packages.list); do
197 pkg=${pkg}.tazpkg
198 if [ ! -f "$pkg" ]; then
199 count=$(($count + 1))
200 [ "$count" == 1 ] && newline
201 echo -n "Fetching: ${pkg}.tazpkg"
202 wget -q ${mirror%/}/$pkg
203 status
204 fi
205 pkgsum=$($CHECKSUM $pkg)
206 debug "$pkgsum"
207 [ "$pkgsum" ] || pkgsum=$$
208 mirsum=$(fgrep -h $pkgsum packages.$SUM)
209 debug "$mirsum"
210 if [ ! "$pkgsum" == "$mirsum" ]; then
211 count=$(($count + 1))
212 [ "$count" == 1 ] && newline
213 echo -n "Fetching: ${pkg}.tazpkg"
214 rm -f $pkg
215 wget -q ${mirror%/}/$pkg
216 status
217 fi
218 done
219 [ "$count" == 0 ] && status
220 ;;
221 *) usage ;;
222 esac
223 exit 0