slitaz-arm view sat @ rev 45

merge
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 09 10:14:33 2014 +0100 (2014-03-09)
parents 7c5d5748623d
children 77d9496b62f5
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 20Mb)
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 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 # Move kernel outside the distro
152 if [ -d "$rootfs/boot" ]; then
153 mv -f ${rootfs}/boot/linux-* ${distro}/linux-arm
154 chmod -x ${distro}/linux-arm
155 else
156 # RPi uses a custom Kernel: --rpi
157 if [ ! "$rpi" ]; then
158 echo -n "Missing Kernel directory: rootfs/boot/"; false
159 status
160 fi
161 fi
163 # SLITAZ_ARCH
164 if [ -f "${rootfs}/etc/slitaz/slitaz.conf" ]; then
165 echo -n "Setting SliTaz arch to: arm"
166 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
167 ${rootfs}/etc/slitaz/slitaz.conf
168 status
169 else
170 echo -n "Missing distro: /etc/slitaz/slitaz.conf"; false
171 status && exit 1
172 fi
174 # Mirror
175 echo "$mirror" > ${rootfs}/var/lib/tazpkg/mirror
177 # /init & /run
178 cd ${rootfs}
179 rm init && ln -s /bin/busybox init
180 mkdir -p run
182 # Update modules.dep
183 if [ -f "var/lib/tazpkg/installed/linux/receipt" ]; then
184 . var/lib/tazpkg/installed/linux/receipt
185 depmod -b . ${VERSION}-slitaz
186 fi
188 # Custom rootfs: make sure all files belong to root
189 if [ -d "$work/rootfs" ]; then
190 size=$(du -sh $work/rootfs | awk '{print $1}')
191 echo -n "Copying custom ARM rootfs: $size"
192 tmp=$distro/tmp-$$
193 mkdir -p $tmp
194 cp -r $work/rootfs/* $tmp
195 chown -R root.root $tmp
196 cp -a $tmp/* ${rootfs} && rm -rf $tmp
197 status
198 fi
200 # Custom flavor rootfs
201 if [ -f "${cache}/flavor.conf" ]; then
202 . ${cache}/flavor.conf
203 fi
204 if [ -d "$flavors/${FLAVOR}/rootfs" ]; then
205 size=$(du -sh $flavors/${FLAVOR}/rootfs | awk '{print $1}')
206 echo -n "Copying ${FLAVOR} ARM rootfs: $size"
207 tmp=$distro/tmp-$$
208 mkdir -p $tmp
209 cp -r $flavors/${FLAVOR}/rootfs/* $tmp
210 chown -R root.root $tmp
211 cp -a $tmp/* ${rootfs} && rm -rf $tmp
212 status
213 fi
215 # --kmap
216 if [ "$kmap" ]; then
217 echo -n "Copying local: /etc/keymap.conf"
218 cp -f /etc/keymap.conf ${rootfs}/etc
219 status
220 fi
222 # Distro: /etc/slitaz/flavor.conf
223 if [ -f "${cache}/flavor.conf" ]; then
224 echo -n "Including $FLAVOR: flavor.conf"
225 echo "BUILD_DATE=\"$(date '+%Y%m%d')\"" >> ${cache}/flavor.conf
226 cp -f ${cache}/flavor.conf ${rootfs}/etc/slitaz
227 status
228 fi
230 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
231 if [ ! "$noinit" ]; then
232 echo -n "Compressing initramfs: $initramfs"
233 case "$initramfs" in
234 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
235 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
236 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;;
237 esac
238 status
239 fi
241 # Clean if no debug mode
242 [ "$debug" ] || rm -rf ${cache}
244 # Summary
245 separator && newline
246 boldify "SliTaz ARM distro summary"
247 separator
248 time=$(($(date +%s) - $time))
249 [ "$noinit" ] || \
250 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
251 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
252 pkgs_count="$(ls $db/installed | wc -l)"
253 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR"
254 echo "Build time : ${time}s"
255 [ "$noinit" ] || echo "Initramfs : $initramfs"
256 [ "$noinit" ] || echo "Initramfs size : $initramfs_size"
257 echo "Rootfs size : $rootfs_size"
258 echo "Packages : $pkgs_count"
259 separator
260 [ "$rpi" ] || newline ;;
262 flavors)
263 newline
264 echo -n "$(boldify 'Flavor')" &&
265 echo -n "$(indent 12 $(boldify 'Packages'))"
266 indent 24 $(boldify 'Description')
267 separator
268 for flavor in $(ls $flavors)
269 do
270 . $flavors/$flavor/flavor.conf
271 pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
272 echo -n "$flavor" &&
273 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
274 unset SHORT_DESC
275 done
276 newline ;;
278 ckpkgs)
279 installed="${rootfs}/var/lib/tazpkg/installed"
280 SLITAZ_ARCH="arm"
281 count=0
282 if [ ! -d "$installed" ]; then
283 echo "Missing distro rootfs" && exit 1
284 fi
285 echo ""
286 echo -n "$(boldify 'Package name')"
287 indent 24 "$(boldify 'Missing dependencies')"
288 separator
289 for pkg in ${installed}/*
290 do
291 . $pkg/receipt
292 for dep in $DEPENDS
293 do
294 if [ ! -d "${installed}/$dep" ]; then
295 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep"
296 count=$(($count + 1))
297 fi
298 done
299 unset DEPENDS
300 done
301 if [ "$count" == 0 ]; then
302 echo "No missing dependencies"
303 fi
304 separator
305 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l)
306 newline ;;
308 clean)
309 check_root
310 echo -n "Cleaning: distro"
311 rm -rf $distro && status
312 if [ "$spk" ]; then
313 echo -n "Cleaning: spk"
314 rm -rf $work/spk && status
315 fi ;;
317 vdisk)
318 # Lets use and HD in Qemu to store files|packages|whatever
319 vdisk="vdisk.img"
320 : ${size=20}
321 newline
322 echo "Creating virtual disk: $vdisk"
323 cd $work
324 dd if=/dev/zero of=$vdisk bs=1M count=$size
325 #mkfs.ext3 -q -T ext3 -L "SliTaz" -F $vdisk
326 # Partition
327 echo "Creating partition with: fdisk"
328 fdisk ${vdisk} >/dev/null << EOT
329 o
330 n
331 p
332 1
333 w
334 EOT
335 newline ;;
337 emu)
338 cd $work
339 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
340 [ "$append" ] && append="-append ${append}"
341 qemu-system-arm -m 256 ${opts} \
342 -M versatilepb -cpu arm1176 \
343 -kernel ${distro}/linux-arm \
344 -initrd ${distro}/${initramfs} ${append} ;;
346 mirror)
347 #
348 # --> spk-mirror $mirror --sync --dest=/path ???
349 #
350 count=0
351 newline && boldify "Syncing SliTaz ARM mirror"
352 separator
353 mkdir -p $work/mirror && cd $work/mirror
355 echo -n "URL: " && colorize 34 "$mirror"
356 if ! check_mirror_id; then
357 newline && exit 0
358 fi
359 for list in packages.list packages.desc packages.md5; do
360 echo -n "Fetching: $list"
361 rm -f $list && wget -q ${mirror%/}/$list
362 status
363 done
364 echo -n "Checking packages $SUM..."
365 for pkg in $(cat $work/mirror/packages.list); do
366 pkg=${pkg}.tazpkg
367 if [ ! -f "$pkg" ]; then
368 count=$(($count + 1))
369 [ "$count" == 1 ] && newline
370 echo -n "Fetching: ${pkg}"
371 wget -q ${mirror%/}/$pkg
372 status
373 fi
374 pkgsum=$($CHECKSUM $pkg)
375 debug "$pkgsum"
376 [ "$pkgsum" ] || pkgsum=$$
377 mirsum=$(fgrep -h $pkgsum packages.$SUM)
378 debug "$mirsum"
379 if [ ! "$pkgsum" == "$mirsum" ]; then
380 count=$(($count + 1))
381 [ "$count" == 1 ] && newline
382 echo -n "Fetching: ${pkg}.tazpkg"
383 rm -f $pkg
384 wget -q ${mirror%/}/$pkg
385 status
386 fi
387 done
388 [ "$count" == 0 ] && status
389 separator && newline ;;
391 *) usage ;;
392 esac
393 exit 0