slitaz-arm view sat @ rev 19

mount /run as tmpfs (less disk acess and faster)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jun 02 12:48:53 2012 +0200 (2012-06-02)
parents 4dcfb253c8f7
children 432ac2334e26
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 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 wget -qs ${mirror%/}/ID; then
51 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 or use equiv.
75 cd $packages
76 for pkg in $packages/*.tazpkg
77 do
78 pkgdir=$(basename $pkg .tazpkg)
79 db=$distro/var/lib/tazpkg
80 echo -n "Installing: $(basename $pkg)"
81 tazpkg extract $pkg >/dev/null
82 . $pkgdir/receipt
83 mkdir -p $db/installed/$PACKAGE
84 cp $pkgdir/receipt $pkgdir/files.list \
85 $db/installed/$PACKAGE
86 cp -a $pkgdir/fs/* $distro && rm -rf $pkgdir
87 md5sum $(basename $pkg) >> $db/installed.md5
88 status
89 done
91 # Install spk if requested. Spk multiarch support must be tested
92 if [ "$spk" ]; then
93 hg=http://hg.slitaz.org
94 echo -n "Installing: spk ($hg)"
95 cd $work
96 [ -d "spk" ] || hg clone $hg/spk >/dev/null
97 cd $work/spk
98 [ "$noup" ] || hg pull -u >/dev/null
99 make DESTDIR=$distro install >/dev/null
100 status
101 fi
103 # Move kernel outside the distro
104 cd $work && mv -f $distro/boot/linux-* linux-arm
106 # SLITAZ_ARCH
107 echo -n "Setting SliTaz arch to: arm"
108 sed -i s"/SLITAZ_ARCH=.*/SLITAZ_ARCH=\"arm\"/" \
109 $distro/etc/slitaz/slitaz.conf
110 status
112 # Mirror
113 echo "$mirror" > $distro/var/lib/tazpkg/mirror
115 # /init & /run
116 cd $distro
117 rm init && ln -s /bin/busybox init
118 mkdir run
120 # Update modules.dep
121 depmod -b . 3.2.14-slitaz
123 # Custom rootfs: make sure all files belong to root.
124 if [ -d "$work/rootfs" ]; then
125 echo -n "Copying custom ARM rootfs..."
126 tmp=$work/tmp-$$
127 mkdir -p $tmp
128 cp -r $work/rootfs/* $tmp
129 if [ "$kmap" ]; then
130 cp /etc/keymap.conf $tmp/etc
131 fi
132 chown -R root.root $tmp
133 cp -a $tmp/* $distro && rm -rf $tmp
134 status
135 fi
137 # Rootfs cpio: gzip xz --> /usr/lib/slitaz/liblive.sh ???
138 echo -n "Compressing initramfs: $initramfs"
139 case $initramfs in
140 *.bz) find . | cpio -o -H newc | bzip2 > ../$initramfs ;;
141 *.gz) find . | cpio -o -H newc | gzip -9 > ../$initramfs ;;
142 *.xz) find . | cpio -o -H newc | xz -9 --format=lzma \
143 > ../$initramfs ;;
144 esac
145 status
146 time=$(($(date +%s) - $time))
147 echo "Build time : ${time}s"
148 echo -n "Distro size : "
149 cd $work && du -sh $initramfs | awk '{print $1}' ;;
150 clean)
151 check_root
152 for r in distro linux-arm *.*z spk; do
153 echo -n "Cleaning: $r"
154 rm -rf $work/$r && status
155 done ;;
156 vdisk)
157 # Lets use and HD in Qemu to store files|packages|whatever
158 vdisk="vdisk.img"
159 : ${size=20}
160 cd $work
161 dd if=/dev/zero of=$vdisk bs=1M count=$size
162 mkfs.ext4 -q -T ext4 -L "SliTaz" -F $vdisk ;;
163 emu)
164 cd $work
165 [ -f "vdisk.img" ] && opts="-hda vdisk.img"
166 qemu-system-arm -m 256 $opts \
167 -M versatilepb -cpu arm1176 \
168 -kernel linux-arm \
169 -initrd $initramfs ;;
170 mirror)
171 #
172 # --> spk-mirror $mirror --sync --dest=/path ???
173 #
174 count=0
175 mkdir -p $work/mirror && cd $work/mirror
176 if ! check_mirror_id; then
177 exit 0
178 fi
179 for list in packages.list packages.desc packages.md5; do
180 echo -n "Fetching: $list"
181 rm -f $list && wget -q ${mirror%/}/$list
182 status
183 done
184 echo -n "Checking packages $SUM..."
185 for pkg in $(cat $work/mirror/packages.list); do
186 pkg=${pkg}.tazpkg
187 if [ ! -f "$pkg" ]; then
188 count=$(($count + 1))
189 [ "$count" == 1 ] && newline
190 echo -n "Fetching: ${pkg}.tazpkg"
191 wget -q ${mirror%/}/$pkg
192 status
193 fi
194 pkgsum=$($CHECKSUM $pkg)
195 debug "$pkgsum"
196 [ "$pkgsum" ] || pkgsum=$$
197 mirsum=$(fgrep -h $pkgsum packages.$SUM)
198 debug "$mirsum"
199 if [ ! "$pkgsum" == "$mirsum" ]; then
200 count=$(($count + 1))
201 [ "$count" == 1 ] && newline
202 echo -n "Fetching: ${pkg}.tazpkg"
203 rm -f $pkg
204 wget -q ${mirror%/}/$pkg
205 status
206 fi
207 done
208 [ "$count" == 0 ] && status
209 ;;
210 *) usage ;;
211 esac
212 exit 0