slitaz-arm view sat @ rev 62
Move RPi rootfs to rpi/ (used by many flavor), add PTYS_LEGACY support to kernel (we want to open and xterm)
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat Mar 15 18:09:54 2014 +0100 (2014-03-15) |
parents | 2d1f132ea8bf |
children | c6d3db386d89 |
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 if [ "$(ls $rootfs/boot | wc -l)" != 0 ]; then
228 echo -n "Moving /boot outside the rootfs..."
229 mkdir -p ${distro}/boot
230 mv -f ${rootfs}/boot/* ${distro}/boot
231 status
233 # ! wok/linux pkg must be modified to install /boot/kernel.img
234 if ls ${distro}/boot/linux-* >/dev/null 2>/dev/null; then
235 mv ${distro}/boot/linux-* ${distro}/boot/kernel.img
236 chmod -x ${distro}/boot/kernel.img
237 fi
239 fi
241 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
242 if [ ! "$noinit" ]; then
243 echo -n "Compressing initramfs: $initramfs"
244 case "$initramfs" in
245 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
246 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
247 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;;
248 esac
249 status
250 fi
252 # Clean if no debug mode
253 [ "$debug" ] || rm -rf ${cache}
255 # Summary
256 time=$(($(date +%s) - $time))
257 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
258 pkgs_count="$(ls $db/installed | wc -l)"
259 [ "$noinit" ] || \
260 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
261 separator && newline
262 boldify "SliTaz ARM distro summary"
263 separator
264 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR"
265 echo "Build time : ${time}s"
266 [ "$noinit" ] || echo "Initramfs : $initramfs"
267 [ "$noinit" ] || echo "Initramfs size : $initramfs_size"
268 echo "Rootfs size : $rootfs_size"
269 echo "Packages : $pkgs_count"
270 separator
271 [ "$rpi" ] || newline ;;
273 flavors)
274 newline
275 echo -n "$(boldify 'Flavor')" &&
276 echo -n "$(indent 12 $(boldify 'Packages'))"
277 indent 24 $(boldify 'Description')
278 separator
279 for flavor in $(ls $flavors)
280 do
281 . $flavors/$flavor/flavor.conf
282 pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
283 echo -n "$flavor" &&
284 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
285 unset SHORT_DESC
286 done
287 newline ;;
289 ckpkgs)
290 installed="${rootfs}/var/lib/tazpkg/installed"
291 SLITAZ_ARCH="arm"
292 count=0
293 if [ ! -d "$installed" ]; then
294 echo "Missing distro rootfs" && exit 1
295 fi
296 echo ""
297 echo -n "$(boldify 'Package name')"
298 indent 24 "$(boldify 'Missing dependencies')"
299 separator
300 for pkg in ${installed}/*
301 do
302 . $pkg/receipt
303 for dep in $DEPENDS
304 do
305 if [ ! -d "${installed}/$dep" ]; then
306 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep"
307 count=$(($count + 1))
308 fi
309 done
310 unset DEPENDS
311 done
312 if [ "$count" == 0 ]; then
313 echo "No missing dependencies"
314 fi
315 separator
316 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l)
317 newline ;;
319 clean)
320 check_root
321 echo -n "Cleaning: distro"
322 rm -rf $distro && status
323 if [ "$spk" ]; then
324 echo -n "Cleaning: spk"
325 rm -rf $work/spk && status
326 fi ;;
328 vdisk)
329 # Lets use and HD in Qemu to store files|packages|whatever
330 vdisk="vdisk.img"
331 : ${size=50}
332 newline
333 echo "Creating virtual disk: $vdisk"
334 cd $work
335 dd if=/dev/zero of=$vdisk bs=1M count=$size
336 # Partition
337 echo "Creating a partition with: fdisk"
338 fdisk ${vdisk} >/dev/null << EOT
339 o
340 n
341 p
342 1
343 w
344 EOT
345 newline ;;
347 emu)
348 cd $work
349 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
350 [ "$append" ] && append="-append ${append}"
351 qemu-system-arm -m 256 ${opts} \
352 -M versatilepb -cpu arm1176 \
353 -kernel ${distro}/boot/kernel.img \
354 -initrd ${distro}/${initramfs} ${append} ;;
356 mirror)
357 #
358 # --> spk-mirror $mirror --sync --dest=/path ???
359 #
360 count=0
361 newline && boldify "Syncing SliTaz ARM mirror"
362 separator
363 mkdir -p $work/mirror && cd $work/mirror
365 echo -n "URL: " && colorize 34 "$mirror"
366 if ! check_mirror_id; then
367 exit 0
368 fi
369 for list in packages.list packages.desc packages.md5; do
370 echo -n "Fetching: $list"
371 rm -f $list && wget -q ${mirror%/}/$list
372 status
373 done
374 echo -n "Checking packages $SUM..."
375 for pkg in $(cat $work/mirror/packages.list); do
376 pkg=${pkg}.tazpkg
377 if [ ! -f "$pkg" ]; then
378 count=$(($count + 1))
379 [ "$count" == 1 ] && newline
380 echo -n "Fetching: ${pkg}"
381 wget -q ${mirror%/}/$pkg
382 status
383 fi
384 pkgsum=$($CHECKSUM $pkg)
385 debug "$pkgsum"
386 [ "$pkgsum" ] || pkgsum=$$
387 mirsum=$(fgrep -h $pkgsum packages.$SUM)
388 debug "$mirsum"
389 if [ ! "$pkgsum" == "$mirsum" ]; then
390 count=$(($count + 1))
391 [ "$count" == 1 ] && newline
392 echo -n "Fetching: ${pkg}.tazpkg"
393 rm -f $pkg
394 wget -q ${mirror%/}/$pkg
395 status
396 fi
397 done
398 [ "$count" == 0 ] && status
399 separator && newline ;;
401 *) usage ;;
402 esac
403 exit 0