slitaz-arm view sat @ rev 55
Finish sat-rpi release, some clean up and add suport for cgi-adm
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Mar 14 00:00:28 2014 +0100 (2014-03-14) |
parents | 77d9496b62f5 |
children | 2d1f132ea8bf |
line source
1 #!/bin/sh
2 #
3 # Sat - SliTaz ARM Tool
4 #
5 # Copyright (C) 2012-2014 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 flavors="$work/flavors"
19 rootfs="$distro/rootfs"
20 cache="$distro/cache"
22 # http://mirror.slitaz.org/packages/cooking/arm/
23 mirror="http://cook.slitaz.org/cross/arm/packages/"
25 #
26 # Functions
27 #
29 # Help and usage
30 usage() {
31 cat << EOT
33 $(boldify "Usage:") $(basename $0) [command|--options]
35 SliTaz ARM Tool - http://arm.slitaz.org
37 $(boldify "Commands:")
38 gen Generate a distro cpio/gzip initramfs
39 flavors List and give info about flavors
40 ckpkgs Distro packages dependencies check
41 clean Clean up the work directory
42 vdisk Create a virtual disk to be used by Qemu
43 emu Emulate the distro with qemu-system-arm
44 mirror Download or sync the SliTaz ARM mirror
46 $(boldify "Options:")
47 --kmap Include the system keymap config in the distro
48 --spk Clean or include Spk package manager in the distro
49 --noinit Don't create the compressed initramfs
50 --work= Path to work dir with packages and rootfs
51 --size= Specify optional vdisk size (default 50Mb)
52 --init= Specify the initramfs compression: gz bz2 xz
53 --flavor= Generate specific SliTaz ARM flavor
54 --append= SliTaz and Kernel bootime arguments for Qemu
55 --debug Keep cache dir and display debugging info
57 EOT
58 }
60 # --> use libpkg.sh when released (function is shared with spk)
61 # Check mirror ID: return 1 if no changes or mirror unreachable
62 check_mirror_id() {
63 [ "$forced" ] && rm -f ID
64 [ -f "ID" ] || echo $$ > ID
65 mv ID ID.bak
66 if busybox wget -qs ${mirror%/}/ID 2>/dev/null; then
67 busybox wget -q ${mirror%/}/ID
68 else
69 echo "Mirror is unreachable"; newline
70 return 1
71 fi
72 if [ "$(cat ID)" == "$(cat ID.bak)" ]; then
73 echo "Mirror is up-to-date"; newline
74 return 1
75 fi
76 }
78 #
79 # Commands
80 #
82 case "$1" in
83 gen)
84 time=$(date +%s)
85 check_root
86 newline && boldify "Generating SliTaz ARM distro"
87 separator
88 rm -rf ${distro} && mkdir -p ${rootfs} ${cache}
90 # Get --flavor= packages lists
91 if [ "$flavor" ]; then
92 echo -n "Getting $flavor packages.list..."
93 cp -f $flavors/$flavor/packages.list ${cache} 2>/dev/null &&
94 cp -f $flavors/$flavor/flavor.conf ${cache} 2>/dev/null
95 status
96 fi
98 # Packages
99 rm -f ${cache}/packages.full
100 if [ -f "${cache}/packages.list" ]; then
101 for pkg in $(cat ${cache}/packages.list)
102 do
103 IFS="|"
104 grep "^$pkg |" $work/mirror/packages.desc | while read pkg version desc
105 do
106 echo ${pkg}-${version}-arm.tazpkg | sed s'/ //'g \
107 >> ${cache}/packages.full
108 done
109 unset IFS
110 done
111 cd ${work}/mirror
112 else
113 if [ ! -d "$packages" ]; then
114 echo "Missing distro/packages.list or packages/ directory"
115 echo "" && exit 1
116 fi
117 echo -n "Using packages directory..."
118 cd $packages && ls -1 >${cache}/packages.full
119 status
120 fi
122 # Deps install is not well handled by tazpkg/spk actually.
123 # So simply install all packages and don't resolve deps.
124 for pkg in $(cat ${cache}/packages.full)
125 do
126 pkgdir=$(basename $pkg .tazpkg)
127 db=${rootfs}/var/lib/tazpkg
128 echo -n "Installing: $(basename $pkg)"
129 tazpkg extract $pkg >/dev/null
130 . $pkgdir/receipt
131 mkdir -p $db/installed/$PACKAGE
132 cp $pkgdir/receipt $pkgdir/files.list \
133 $db/installed/$PACKAGE
134 cp -a $pkgdir/fs/* $distro/rootfs && rm -rf $pkgdir
135 md5sum $(basename $pkg) >> $db/installed.md5
136 status
137 done
139 # Install spk Hg if requested. Spk multiarch support must be tested
140 if [ "$spk" ]; then
141 hg=http://hg.slitaz.org
142 echo -n "Installing: spk ($hg)"
143 cd $work
144 [ -d "spk" ] || hg clone $hg/spk >/dev/null 2>/dev/null
145 cd $work/spk
146 [ "$noup" ] || hg pull -u >/dev/null
147 make DESTDIR=${rootfs} install >/dev/null
148 status
149 fi
151 # SLITAZ_ARCH
152 if [ -f "${rootfs}/etc/slitaz/slitaz.conf" ]; then
153 echo -n "Setting SliTaz arch to: arm"
154 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
155 ${rootfs}/etc/slitaz/slitaz.conf
156 status
157 else
158 echo -n "Missing distro: /etc/slitaz/slitaz.conf"; false
159 status && exit 1
160 fi
162 # Mirror
163 echo "$mirror" > ${rootfs}/var/lib/tazpkg/mirror
165 # /init & /run
166 cd ${rootfs}
167 rm init && ln -s /bin/busybox init
168 mkdir -p run
170 # Update modules.dep
171 if [ -f "var/lib/tazpkg/installed/linux/receipt" ]; then
172 . var/lib/tazpkg/installed/linux/receipt
173 depmod -b . ${VERSION}-slitaz
174 fi
176 # CGI Admin
177 if [ -d "$work/cgi-adm" ]; then
178 echo -n "Installing SliTaz ARM CGI Admin interface..."
179 cp -a ${rpi}/cgi-adm/* ${rootfs}/var/www/adm
180 status
181 fi
183 # Custom rootfs: make sure all files belong to root
184 if [ -d "$work/rootfs" ]; then
185 size=$(du -sh $work/rootfs | awk '{print $1}')
186 echo -n "Copying custom ARM rootfs: $size"
187 tmp=$distro/tmp-$$
188 mkdir -p $tmp
189 cp -r $work/rootfs/* $tmp
190 chown -R root.root $tmp
191 cp -a $tmp/* ${rootfs} && rm -rf $tmp
192 status
193 fi
195 # Custom flavor rootfs
196 if [ -f "${cache}/flavor.conf" ]; then
197 . ${cache}/flavor.conf
198 fi
199 if [ -d "$flavors/${FLAVOR}/rootfs" ]; then
200 size=$(du -sh $flavors/${FLAVOR}/rootfs | awk '{print $1}')
201 echo -n "Copying ${FLAVOR} ARM rootfs: $size"
202 tmp=$distro/tmp-$$
203 mkdir -p $tmp
204 cp -r $flavors/${FLAVOR}/rootfs/* $tmp
205 chown -R root.root $tmp
206 cp -a $tmp/* ${rootfs} && rm -rf $tmp
207 status
208 fi
210 # --kmap
211 if [ "$kmap" ]; then
212 echo -n "Copying local: /etc/keymap.conf"
213 cp -f /etc/keymap.conf ${rootfs}/etc
214 status
215 fi
217 # Distro: /etc/slitaz/flavor.conf
218 if [ -f "${cache}/flavor.conf" ]; then
219 echo -n "Including $FLAVOR: flavor.conf"
220 echo "BUILD_DATE=\"$(date '+%Y%m%d')\"" >> ${cache}/flavor.conf
221 cp -f ${cache}/flavor.conf ${rootfs}/etc/slitaz
222 status
223 fi
225 # Move /boot outside the rootfs
226 if [ "$(ls $rootfs/boot | wc -l)" != 0 ]; then
227 echo -n "Moving /boot outside the rootfs..."
228 mkdir -p ${distro}/boot
229 mv -f ${rootfs}/boot/* ${distro}/boot
230 status
232 # ! wok/linux pkg must be modified to install /boot/kernel.img
233 if ls ${distro}/boot/linux-* >/dev/null 2>/dev/null; then
234 mv ${distro}/boot/linux-* ${distro}/boot/kernel.img
235 chmod -x ${distro}/boot/kernel.img
236 fi
238 fi
240 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
241 if [ ! "$noinit" ]; then
242 echo -n "Compressing initramfs: $initramfs"
243 case "$initramfs" in
244 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
245 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
246 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;;
247 esac
248 status
249 fi
251 # Clean if no debug mode
252 [ "$debug" ] || rm -rf ${cache}
254 # Summary
255 time=$(($(date +%s) - $time))
256 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
257 pkgs_count="$(ls $db/installed | wc -l)"
258 [ "$noinit" ] || \
259 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
260 separator && newline
261 boldify "SliTaz ARM distro summary"
262 separator
263 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR"
264 echo "Build time : ${time}s"
265 [ "$noinit" ] || echo "Initramfs : $initramfs"
266 [ "$noinit" ] || echo "Initramfs size : $initramfs_size"
267 echo "Rootfs size : $rootfs_size"
268 echo "Packages : $pkgs_count"
269 separator
270 [ "$rpi" ] || newline ;;
272 flavors)
273 newline
274 echo -n "$(boldify 'Flavor')" &&
275 echo -n "$(indent 12 $(boldify 'Packages'))"
276 indent 24 $(boldify 'Description')
277 separator
278 for flavor in $(ls $flavors)
279 do
280 . $flavors/$flavor/flavor.conf
281 pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
282 echo -n "$flavor" &&
283 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
284 unset SHORT_DESC
285 done
286 newline ;;
288 ckpkgs)
289 installed="${rootfs}/var/lib/tazpkg/installed"
290 SLITAZ_ARCH="arm"
291 count=0
292 if [ ! -d "$installed" ]; then
293 echo "Missing distro rootfs" && exit 1
294 fi
295 echo ""
296 echo -n "$(boldify 'Package name')"
297 indent 24 "$(boldify 'Missing dependencies')"
298 separator
299 for pkg in ${installed}/*
300 do
301 . $pkg/receipt
302 for dep in $DEPENDS
303 do
304 if [ ! -d "${installed}/$dep" ]; then
305 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep"
306 count=$(($count + 1))
307 fi
308 done
309 unset DEPENDS
310 done
311 if [ "$count" == 0 ]; then
312 echo "No missing dependencies"
313 fi
314 separator
315 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l)
316 newline ;;
318 clean)
319 check_root
320 echo -n "Cleaning: distro"
321 rm -rf $distro && status
322 if [ "$spk" ]; then
323 echo -n "Cleaning: spk"
324 rm -rf $work/spk && status
325 fi ;;
327 vdisk)
328 # Lets use and HD in Qemu to store files|packages|whatever
329 vdisk="vdisk.img"
330 : ${size=50}
331 newline
332 echo "Creating virtual disk: $vdisk"
333 cd $work
334 dd if=/dev/zero of=$vdisk bs=1M count=$size
335 # Partition
336 echo "Creating a partition with: fdisk"
337 fdisk ${vdisk} >/dev/null << EOT
338 o
339 n
340 p
341 1
342 w
343 EOT
344 newline ;;
346 emu)
347 cd $work
348 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
349 [ "$append" ] && append="-append ${append}"
350 qemu-system-arm -m 256 ${opts} \
351 -M versatilepb -cpu arm1176 \
352 -kernel ${distro}/boot/kernel.img \
353 -initrd ${distro}/${initramfs} ${append} ;;
355 mirror)
356 #
357 # --> spk-mirror $mirror --sync --dest=/path ???
358 #
359 count=0
360 newline && boldify "Syncing SliTaz ARM mirror"
361 separator
362 mkdir -p $work/mirror && cd $work/mirror
364 echo -n "URL: " && colorize 34 "$mirror"
365 if ! check_mirror_id; then
366 exit 0
367 fi
368 for list in packages.list packages.desc packages.md5; do
369 echo -n "Fetching: $list"
370 rm -f $list && wget -q ${mirror%/}/$list
371 status
372 done
373 echo -n "Checking packages $SUM..."
374 for pkg in $(cat $work/mirror/packages.list); do
375 pkg=${pkg}.tazpkg
376 if [ ! -f "$pkg" ]; then
377 count=$(($count + 1))
378 [ "$count" == 1 ] && newline
379 echo -n "Fetching: ${pkg}"
380 wget -q ${mirror%/}/$pkg
381 status
382 fi
383 pkgsum=$($CHECKSUM $pkg)
384 debug "$pkgsum"
385 [ "$pkgsum" ] || pkgsum=$$
386 mirsum=$(fgrep -h $pkgsum packages.$SUM)
387 debug "$mirsum"
388 if [ ! "$pkgsum" == "$mirsum" ]; then
389 count=$(($count + 1))
390 [ "$count" == 1 ] && newline
391 echo -n "Fetching: ${pkg}.tazpkg"
392 rm -f $pkg
393 wget -q ${mirror%/}/$pkg
394 status
395 fi
396 done
397 [ "$count" == 0 ] && status
398 separator && newline ;;
400 *) usage ;;
401 esac
402 exit 0