slitaz-arm view sat @ rev 21

sat: some fixes and improvments
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 23 16:27:57 2014 +0100 (2014-02-23)
parents 432ac2334e26
children 6d8bc047addb
line source
1 #!/bin/sh
2 #
3 # Sat - SliTaz ARM Tool
4 #
5 # Copyright (C) 2012 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 # http://mirror.slitaz.org/packages/cooking/arm/
19 mirror="http://cook.slitaz.org/cross/arm/packages/"
21 # Help and usage
22 usage() {
23 cat << EOT
25 $(boldify "Usage:") $(basename $0) [command|--options]
27 $(boldify "Commands:")
28 gen Generate a distro cpio/gzip initramfs
29 clean Clean up the work directory
30 vdisk Create a virtual disk to be used by Qemu
31 emu Emulate the distro with qemu-system-arm
32 mirror Download or sync the SliTaz ARM mirror
34 $(boldify "Options:")
35 --spk Include Spk package manager in the distro
36 --kmap Include the system keymap config in the distro
37 --work= Path to work dir with packages and rootfs
38 --size= Specify optional vdisk size (default 20Mb)
39 --init= Specify the initramfs compression: gz bz2 xz
41 EOT
42 }
44 # --> use libpkg.sh when released (function is shared with spk)
45 # Check mirror ID: return 1 if no changes or mirror unreachable
46 check_mirror_id() {
47 [ "$forced" ] && rm -f ID
48 [ -f "ID" ] || echo $$ > ID
49 mv ID ID.bak
50 if busybox wget -qs ${mirror%/}/ID 2>/dev/null; then
51 busybox wget -q ${mirror%/}/ID
52 else
53 gettext "Mirror is unreachable"; false
54 status && return 1
55 fi
56 if [ "$(cat ID)" == "$(cat ID.bak)" ]; then
57 gettext "Mirror is up-to-date"; true
58 status && return 1
59 fi
60 }
62 #
63 # Commands
64 #
66 case "$1" in
67 gen)
68 time=$(date +%s)
69 check_root
70 rm -rf $distro slitaz-arm.xz
71 mkdir -p $distro
73 # Packages. Dep install is not well handled by tazpkg/spk actually.
74 # So simply install all packages and don't resolve deps.
75 if [ -f "packages.list" ]; then
76 for pkg in $(cat $packages.list)
77 do
78 IFS="|"
79 grep "^$pkg |" $work/mirror/packages.desc | while read pkg version desc
80 do
81 echo ${pkg}-${version}.tazpkg | sed s'/ //'g
82 done
83 unset IFS
84 done
85 exit 0
86 else
87 [ ! -d "$packages" ] && echo "Missing: $packages" && exit 1
88 cd $packages
89 for pkg in $packages/*.tazpkg
90 do
91 pkgdir=$(basename $pkg .tazpkg)
92 db=$distro/var/lib/tazpkg
93 echo -n "Installing: $(basename $pkg)"
94 tazpkg extract $pkg >/dev/null
95 . $pkgdir/receipt
96 mkdir -p $db/installed/$PACKAGE
97 cp $pkgdir/receipt $pkgdir/files.list \
98 $db/installed/$PACKAGE
99 cp -a $pkgdir/fs/* $distro && rm -rf $pkgdir
100 md5sum $(basename $pkg) >> $db/installed.md5
101 status
102 done
103 fi
105 # Install spk if requested. Spk multiarch support must be tested
106 if [ "$spk" ]; then
107 hg=http://hg.slitaz.org
108 echo -n "Installing: spk ($hg)"
109 cd $work
110 [ -d "spk" ] || hg clone $hg/spk >/dev/null
111 cd $work/spk
112 [ "$noup" ] || hg pull -u >/dev/null
113 make DESTDIR=$distro install >/dev/null
114 status
115 fi
117 # Move kernel outside the distro
118 if [ -d "$distro/boot" ]; then
119 cd $work && mv -f $distro/boot/linux-* linux-arm
120 else
121 echo -n "Missing: $distro/boot"; false
122 status && exit 1
123 fi
125 # SLITAZ_ARCH
126 echo -n "Setting SliTaz arch to: arm"
127 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
128 $distro/etc/slitaz/slitaz.conf
129 status
131 # Mirror
132 echo "$mirror" > $distro/var/lib/tazpkg/mirror
134 # /init & /run
135 cd $distro
136 rm init && ln -s /bin/busybox init
137 mkdir -p run
139 # Update modules.dep
140 . var/lib/tazpkg/installed/linux/receipt
141 depmod -b . ${VERSION}-slitaz
143 # Custom rootfs: make sure all files belong to root.
144 if [ -d "$work/rootfs" ]; then
145 echo -n "Copying custom ARM rootfs..."
146 tmp=$work/tmp-$$
147 mkdir -p $tmp
148 cp -r $work/rootfs/* $tmp
149 if [ "$kmap" ]; then
150 cp /etc/keymap.conf $tmp/etc
151 fi
152 chown -R root.root $tmp
153 cp -a $tmp/* $distro && rm -rf $tmp
154 status
155 fi
157 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
158 echo -n "Compressing initramfs: $initramfs"
159 case $initramfs in
160 *.bz2) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
161 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
162 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma \
163 > ../$initramfs ;;
164 esac
165 status
166 time=$(($(date +%s) - $time))
167 echo "Build time : ${time}s"
168 echo -n "Distro size : "
169 cd $work && du -sh $initramfs | awk '{print $1}' ;;
171 clean)
172 check_root
173 for r in distro linux-arm *.*z spk; do
174 echo -n "Cleaning: $r"
175 rm -rf $work/$r && status
176 done ;;
178 vdisk)
179 # Lets use and HD in Qemu to store files|packages|whatever
180 vdisk="vdisk.img"
181 : ${size=20}
182 cd $work
183 dd if=/dev/zero of=$vdisk bs=1M count=$size
184 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;;
186 emu)
187 cd $work
188 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
189 qemu-system-arm -m 256 $opts \
190 -M versatilepb -cpu arm1176 \
191 -kernel linux-arm \
192 -initrd $initramfs ;;
194 mirror)
195 #
196 # --> spk-mirror $mirror --sync --dest=/path ???
197 #
198 count=0
199 mkdir -p $work/mirror && cd $work/mirror
200 if ! check_mirror_id; then
201 exit 0
202 fi
203 for list in packages.list packages.desc packages.md5; do
204 echo -n "Fetching: $list"
205 rm -f $list && wget -q ${mirror%/}/$list
206 status
207 done
208 echo -n "Checking packages $SUM..."
209 for pkg in $(cat $work/mirror/packages.list); do
210 pkg=${pkg}.tazpkg
211 if [ ! -f "$pkg" ]; then
212 count=$(($count + 1))
213 [ "$count" == 1 ] && newline
214 echo -n "Fetching: ${pkg}"
215 wget -q ${mirror%/}/$pkg
216 status
217 fi
218 pkgsum=$($CHECKSUM $pkg)
219 debug "$pkgsum"
220 [ "$pkgsum" ] || pkgsum=$$
221 mirsum=$(fgrep -h $pkgsum packages.$SUM)
222 debug "$mirsum"
223 if [ ! "$pkgsum" == "$mirsum" ]; then
224 count=$(($count + 1))
225 [ "$count" == 1 ] && newline
226 echo -n "Fetching: ${pkg}.tazpkg"
227 rm -f $pkg
228 wget -q ${mirror%/}/$pkg
229 status
230 fi
231 done
232 [ "$count" == 0 ] && status ;;
234 *) usage ;;
235 esac
236 exit 0