slitaz-arm view sat @ rev 75
Add slim support and custom rpi theme
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 23 14:37:38 2014 +0100 (2014-03-23) |
parents | f74a9206fdd0 |
children | 7f8c51f837a5 |
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 & /var/run
166 cd ${rootfs}
167 rm init var/run && ln -s /bin/busybox init
168 mkdir -p run var/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 mkdir -p ${rootfs}/var/www/adm
180 cp -a ${work}/cgi-adm/* ${rootfs}/var/www/adm
181 status
182 fi
184 # Custom rootfs: make sure all files belong to root
185 if [ -d "$work/rootfs" ]; then
186 size=$(du -sh $work/rootfs | awk '{print $1}')
187 echo -n "Copying custom ARM rootfs: $size"
188 tmp=$distro/tmp-$$
189 mkdir -p $tmp
190 cp -r $work/rootfs/* $tmp
191 chown -R root.root $tmp
192 cp -a $tmp/* ${rootfs} && rm -rf $tmp
193 status
194 fi
196 # Custom flavor rootfs
197 if [ -f "${cache}/flavor.conf" ]; then
198 . ${cache}/flavor.conf
199 fi
200 if [ -d "$flavors/${FLAVOR}/rootfs" ]; then
201 size=$(du -sh $flavors/${FLAVOR}/rootfs | awk '{print $1}')
202 echo -n "Copying ${FLAVOR} ARM rootfs: $size"
203 tmp=$distro/tmp-$$
204 mkdir -p $tmp
205 cp -r $flavors/${FLAVOR}/rootfs/* $tmp
206 chown -R root.root $tmp
207 cp -a $tmp/* ${rootfs} && rm -rf $tmp
208 status
209 fi
211 # --kmap
212 if [ "$kmap" ]; then
213 echo -n "Copying local: /etc/keymap.conf"
214 cp -f /etc/keymap.conf ${rootfs}/etc
215 status
216 fi
218 # Distro: /etc/slitaz/flavor.conf
219 if [ -f "${cache}/flavor.conf" ]; then
220 echo -n "Including $FLAVOR: flavor.conf"
221 echo "BUILD_DATE=\"$(date '+%Y%m%d')\"" >> ${cache}/flavor.conf
222 cp -f ${cache}/flavor.conf ${rootfs}/etc/slitaz
223 status
224 fi
226 # Move /boot outside the rootfs
227 mkdir -p ${rootfs}/boot
228 if [ "$(ls $rootfs/boot | wc -l)" != 0 ]; then
229 echo -n "Moving /boot outside the rootfs..."
230 mkdir -p ${distro}/boot
231 mv -f ${rootfs}/boot/* ${distro}/boot
232 status
234 # ! wok/linux pkg must be modified to install /boot/kernel.img
235 if ls ${distro}/boot/linux-* >/dev/null 2>/dev/null; then
236 mv ${distro}/boot/linux-* ${distro}/boot/kernel.img
237 chmod -x ${distro}/boot/kernel.img
238 fi
240 fi
242 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
243 if [ ! "$noinit" ]; then
244 echo -n "Compressing initramfs: $initramfs"
245 case "$initramfs" in
246 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
247 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
248 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;;
249 esac
250 status
251 fi
253 # Clean if no debug mode
254 [ "$debug" ] || rm -rf ${cache}
256 # Summary
257 time=$(($(date +%s) - $time))
258 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
259 pkgs_count="$(ls $db/installed | wc -l)"
260 [ "$noinit" ] || \
261 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
262 separator && newline
263 boldify "SliTaz ARM distro summary"
264 separator
265 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR"
266 echo "Build time : ${time}s"
267 [ "$noinit" ] || echo "Initramfs : $initramfs"
268 [ "$noinit" ] || echo "Initramfs size : $initramfs_size"
269 echo "Rootfs size : $rootfs_size"
270 echo "Packages : $pkgs_count"
271 separator
272 [ "$rpi" ] || newline ;;
274 flavors)
275 newline
276 echo -n "$(boldify 'Flavor')" &&
277 echo -n "$(indent 12 $(boldify 'Packages'))"
278 indent 24 $(boldify 'Description')
279 separator
280 for flavor in $(ls $flavors)
281 do
282 . $flavors/$flavor/flavor.conf
283 pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
284 echo -n "$flavor" &&
285 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
286 unset SHORT_DESC
287 done
288 newline ;;
290 ckpkgs)
291 installed="${rootfs}/var/lib/tazpkg/installed"
292 SLITAZ_ARCH="arm"
293 count=0
294 if [ ! -d "$installed" ]; then
295 echo "Missing distro rootfs" && exit 1
296 fi
297 echo ""
298 echo -n "$(boldify 'Package name')"
299 indent 24 "$(boldify 'Missing dependencies')"
300 separator
301 for pkg in ${installed}/*
302 do
303 . $pkg/receipt
304 for dep in $DEPENDS
305 do
306 if [ ! -d "${installed}/$dep" ]; then
307 if [ ! "$raw" ]; then
308 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep"
309 else
310 echo "$dep"
311 fi
312 count=$(($count + 1))
313 fi
314 done
315 unset DEPENDS
316 done
317 if [ "$count" == 0 ]; then
318 echo "No missing dependencies"
319 fi
320 separator
321 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l)
322 newline ;;
324 clean)
325 check_root
326 echo -n "Cleaning: distro"
327 rm -rf $distro && status
328 if [ "$spk" ]; then
329 echo -n "Cleaning: spk"
330 rm -rf $work/spk && status
331 fi ;;
333 vdisk)
334 # Lets use and HD in Qemu to store files|packages|whatever
335 vdisk="vdisk.img"
336 : ${size=50}
337 newline
338 echo "Creating virtual disk: $vdisk"
339 cd $work
340 dd if=/dev/zero of=$vdisk bs=1M count=$size
341 # Partition
342 echo "Creating a partition with: fdisk"
343 fdisk ${vdisk} >/dev/null << EOT
344 o
345 n
346 p
347 1
348 w
349 EOT
350 newline ;;
352 emu)
353 cd $work
354 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
355 [ "$append" ] && append="-append ${append}"
356 qemu-system-arm -m 256 ${opts} \
357 -M versatilepb -cpu arm1176 \
358 -kernel ${distro}/boot/kernel.img \
359 -initrd ${distro}/${initramfs} ${append} ;;
361 mirror)
362 #
363 # --> spk-mirror $mirror --sync --dest=/path ???
364 #
365 count=0
366 newline && boldify "Syncing SliTaz ARM mirror"
367 separator
368 mkdir -p $work/mirror && cd $work/mirror
370 echo -n "URL: " && colorize 34 "$mirror"
371 if ! check_mirror_id; then
372 exit 0
373 fi
374 for list in packages.list packages.desc packages.md5; do
375 echo -n "Fetching: $list"
376 rm -f $list && wget -q ${mirror%/}/$list
377 status
378 done
379 echo -n "Checking packages $SUM..."
380 for pkg in $(cat $work/mirror/packages.list); do
381 pkg=${pkg}.tazpkg
382 if [ ! -f "$pkg" ]; then
383 count=$(($count + 1))
384 [ "$count" == 1 ] && newline
385 echo -n "Fetching: ${pkg}"
386 wget -q ${mirror%/}/$pkg
387 status
388 fi
389 pkgsum=$($CHECKSUM $pkg)
390 debug "$pkgsum"
391 [ "$pkgsum" ] || pkgsum=$$
392 mirsum=$(fgrep -h $pkgsum packages.$SUM)
393 debug "$mirsum"
394 if [ ! "$pkgsum" == "$mirsum" ]; then
395 count=$(($count + 1))
396 [ "$count" == 1 ] && newline
397 echo -n "Fetching: ${pkg}.tazpkg"
398 rm -f $pkg
399 wget -q ${mirror%/}/$pkg
400 status
401 fi
402 done
403 [ "$count" == 0 ] && status
404 separator && newline ;;
406 *) usage ;;
407 esac
408 exit 0