slitaz-arm view sat @ rev 219

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