slitaz-arm view sat @ rev 185

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