slitaz-arm view sat @ rev 27

Handle flavor.conf and rm old libtaz.sh from ARM rootfs
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 03 14:39:11 2014 +0100 (2014-03-03)
parents 490947b1da1a
children 15f4a6497b20
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 data="$distro/data"
22 # http://mirror.slitaz.org/packages/cooking/arm/
23 mirror="http://cook.slitaz.org/cross/arm/packages/"
25 # Help and usage
26 usage() {
27 cat << EOT
29 $(boldify "Usage:") $(basename $0) [command|--options]
31 $(boldify "Commands:")
32 gen Generate a distro cpio/gzip initramfs
33 flavors List and give info about flavors
34 ckpkgs Distro packages dependencies check
35 clean Clean up the work directory
36 vdisk Create a virtual disk to be used by Qemu
37 emu Emulate the distro with qemu-system-arm
38 mirror Download or sync the SliTaz ARM mirror
40 $(boldify "Options:")
41 --spk Clean or include Spk package manager in the distro
42 --kmap Include the system keymap config in the distro
43 --work= Path to work dir with packages and rootfs
44 --size= Specify optional vdisk size (default 20Mb)
45 --init= Specify the initramfs compression: gz bz2 xz
46 --flavor= Generate specified SliTaz ARM flavor
48 EOT
49 }
51 # --> use libpkg.sh when released (function is shared with spk)
52 # Check mirror ID: return 1 if no changes or mirror unreachable
53 check_mirror_id() {
54 [ "$forced" ] && rm -f ID
55 [ -f "ID" ] || echo $$ > ID
56 mv ID ID.bak
57 if busybox wget -qs ${mirror%/}/ID 2>/dev/null; then
58 busybox wget -q ${mirror%/}/ID
59 else
60 gettext "Mirror is unreachable"; newline
61 return 1
62 fi
63 if [ "$(cat ID)" == "$(cat ID.bak)" ]; then
64 gettext "Mirror is up-to-date"; newline
65 return 1
66 fi
67 }
69 #
70 # Commands
71 #
73 case "$1" in
74 gen)
75 time=$(date +%s)
76 check_root
77 newline && boldify "Generating SliTaz ARM distro"
78 separator
79 rm -rf $distro && mkdir -p ${rootfs} ${data}
81 # Get --flavor= packages lists
82 if [ "$flavor" ]; then
83 echo -n "Getting $flavor packages.list..."
84 cp $flavors/$flavor/packages.list ${data} 2>/dev/null &&
85 cp $flavors/$flavor/flavor.conf ${data} 2>/dev/null
86 status
87 fi
89 # Packages
90 rm -f ${data}/packages.full
91 if [ -f "${data}/packages.list" ]; then
92 for pkg in $(cat ${data}/packages.list)
93 do
94 IFS="|"
95 grep "^$pkg |" $work/mirror/packages.desc | while read pkg version desc
96 do
97 echo ${pkg}-${version}-arm.tazpkg | sed s'/ //'g \
98 >> ${data}/packages.full
99 done
100 unset IFS
101 done
102 cd ${work}/mirror
103 else
104 if [ ! -d "$packages" ]; then
105 echo "Missing distro/packages.list or packages/ directory"
106 echo "" && exit 1
107 fi
108 echo -n "Using packages directory..."
109 cd $packages && ls -1 >${data}/packages.full
110 status
111 fi
113 # Deps install is not well handled by tazpkg/spk actually.
114 # So simply install all packages and don't resolve deps.
115 for pkg in $(cat ${data}/packages.full)
116 do
117 pkgdir=$(basename $pkg .tazpkg)
118 db=${rootfs}/var/lib/tazpkg
119 echo -n "Installing: $(basename $pkg)"
120 tazpkg extract $pkg >/dev/null
121 . $pkgdir/receipt
122 mkdir -p $db/installed/$PACKAGE
123 cp $pkgdir/receipt $pkgdir/files.list \
124 $db/installed/$PACKAGE
125 cp -a $pkgdir/fs/* $distro/rootfs && rm -rf $pkgdir
126 md5sum $(basename $pkg) >> $db/installed.md5
127 status
128 done
130 # Install spk if requested. Spk multiarch support must be tested
131 if [ "$spk" ]; then
132 hg=http://hg.slitaz.org
133 echo -n "Installing: spk ($hg)"
134 cd $work
135 [ -d "spk" ] || hg clone $hg/spk >/dev/null 2>/dev/null
136 cd $work/spk
137 [ "$noup" ] || hg pull -u >/dev/null
138 make DESTDIR=${rootfs} install >/dev/null
139 status
140 fi
142 # Move kernel outside the distro
143 if [ -d "$rootfs/boot" ]; then
144 mv -f ${rootfs}/boot/linux-* ${distro}/linux-arm
145 chmod -x ${distro}/linux-arm
146 else
147 echo -n "Missing Kernel directory: rootfs/boot/"; false
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 "${data}/flavor.conf" ]; then
190 . ${data}/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 -a /etc/keymap.conf ${rootfs}
207 status
208 fi
210 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
211 echo -n "Compressing initramfs: $initramfs"
212 case "$initramfs" in
213 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
214 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
215 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma > ../$initramfs ;;
216 esac
218 # Summary
219 status
220 separator && echo ""
221 boldify "SliTaz ARM distro summary"
222 separator
223 time=$(($(date +%s) - $time))
224 initramfs_size="$(du -sh $distro/$initramfs | awk '{print $1}')"
225 rootfs_size="$(du -sh ${rootfs} | awk '{print $1}')"
226 pkgs_count="$(ls $db/installed | wc -l)"
227 [ "$FLAVOR" ] && echo "Flavor name : $FLAVOR"
228 echo "Build time : ${time}s"
229 echo "Initramfs : $initramfs"
230 echo "Initramfs size : $initramfs_size"
231 echo "Rootfs size : $rootfs_size"
232 echo "Packages : $pkgs_count"
233 separator && newline ;;
235 flavors)
236 newline
237 echo -n "$(boldify 'Flavor')" &&
238 echo -n "$(indent 12 $(boldify 'Packages'))"
239 indent 24 $(boldify 'Description')
240 separator
241 for flavor in $(ls $flavors)
242 do
243 . $flavors/$flavor/flavor.conf
244 pkgs=$(cat $flavors/$flavor/packages.list | wc -l)
245 echo -n "$flavor" &&
246 echo -n "$(indent 12 $pkgs)" && indent 24 "$SHORT_DESC"
247 unset SHORT_DESC
248 done
249 newline ;;
251 ckpkgs)
252 installed="${rootfs}/var/lib/tazpkg/installed"
253 SLITAZ_ARCH="arm"
254 count=0
255 if [ ! -d "$installed" ]; then
256 echo "Missing distro rootfs" && exit 1
257 fi
258 echo ""
259 echo -n "$(boldify 'Package name')"
260 indent 24 "$(boldify 'Missing dependencie')"
261 separator
262 for pkg in ${installed}/*
263 do
264 . $pkg/receipt
265 for dep in $DEPENDS
266 do
267 if [ ! -d "${installed}/$dep" ]; then
268 echo -n "$(colorize 34 $PACKAGE)" && indent 24 "$dep"
269 count=$(($count + 1))
270 fi
271 done
272 unset DEPENDS
273 done
274 if [ "$count" == 0 ]; then
275 echo "No missing dependencies"
276 fi
277 separator
278 echo -n "Installed packages: "; colorize 32 $(ls $installed | wc -l)
279 newline ;;
281 clean)
282 check_root
283 echo -n "Cleaning: distro"
284 rm -rf $distro && status
285 if [ "$spk" ]; then
286 echo -n "Cleaning: spk"
287 rm -rf $work/spk && status
288 fi ;;
290 vdisk)
291 # Lets use and HD in Qemu to store files|packages|whatever
292 vdisk="vdisk.img"
293 : ${size=20}
294 cd $work
295 dd if=/dev/zero of=$vdisk bs=1M count=$size
296 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;;
298 emu)
299 cd $work
300 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
301 qemu-system-arm -m 256 $opts \
302 -M versatilepb -cpu arm1176 \
303 -kernel ${distro}/linux-arm \
304 -initrd ${distro}/${initramfs} ;;
306 mirror)
307 #
308 # --> spk-mirror $mirror --sync --dest=/path ???
309 #
310 count=0
311 newline && boldify "Syncing SliTaz ARM mirror"
312 separator
313 mkdir -p $work/mirror && cd $work/mirror
315 echo -n "URL: " && colorize 34 "$mirror"
316 if ! check_mirror_id; then
317 newline && exit 0
318 fi
319 for list in packages.list packages.desc packages.md5; do
320 echo -n "Fetching: $list"
321 rm -f $list && wget -q ${mirror%/}/$list
322 status
323 done
324 echo -n "Checking packages $SUM..."
325 for pkg in $(cat $work/mirror/packages.list); do
326 pkg=${pkg}.tazpkg
327 if [ ! -f "$pkg" ]; then
328 count=$(($count + 1))
329 [ "$count" == 1 ] && newline
330 echo -n "Fetching: ${pkg}"
331 wget -q ${mirror%/}/$pkg
332 status
333 fi
334 pkgsum=$($CHECKSUM $pkg)
335 debug "$pkgsum"
336 [ "$pkgsum" ] || pkgsum=$$
337 mirsum=$(fgrep -h $pkgsum packages.$SUM)
338 debug "$mirsum"
339 if [ ! "$pkgsum" == "$mirsum" ]; then
340 count=$(($count + 1))
341 [ "$count" == 1 ] && newline
342 echo -n "Fetching: ${pkg}.tazpkg"
343 rm -f $pkg
344 wget -q ${mirror%/}/$pkg
345 status
346 fi
347 done
348 [ "$count" == 0 ] && status
349 separator && newline ;;
351 *) usage ;;
352 esac
353 exit 0