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