slitaz-dev-tools view tazdev/tazdev @ rev 189

tazdev: add support for ARM packages
author Christophe Lincoln <pankso@slitaz.org>
date Tue Sep 18 22:31:55 2012 +0200 (2012-09-18)
parents 911e4e78149d
children 9da0e2756a59
line source
1 #!/bin/sh
2 #
3 # Tazdev - SliTaz developers and build host tool. System wide config
4 # file is located at: /etc/slitaz/tazdev.conf. Keep the code clear and
5 # well commented please, also: configuration variables are $UPPERCASE
6 # and variables initialized by tazdev itself are $lowerspace
7 #
8 # (c) 2011 SliTaz GNU/Linux - GNU gpl v3
9 #
10 # AUTHORS
11 # Christophe Lincoln <pankso@slitaz.org>
12 # Pascal Bellard <bellard@slitaz.org>
13 #
14 . /lib/libtaz.sh
16 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
17 [ -f tazdev.conf ] && . ./tazdev.conf
19 if [ ! "$SLITAZ_HOME" ]; then
20 echo -e "\nNo config file found\n" && exit 1
21 fi
23 usage() {
24 cat << EOT
26 $(boldify "Usage:") $(basename $0) [command] [vers|user|tool] [vers|--opts]
28 SliTaz developers and build host tool
30 $(boldify "Commands:")
31 usage Print this short usage and command list
32 help Give help on a SliTaz tool or library.
33 stats|-s Display statistics about your projects
34 chroot|-c Mount virtual fs and chroot into the build env
35 gen-chroot|-gc Generate a chroot using packages from config file
36 umount-chroot|-uc Unmount chroot specified on cmdline
37 clean-chroot|-cc Clean a chroot environment (skip root/ and home/)
38 !purge Remove obsolete packages and obsolete source tarballs
39 !dry-purge Show obsolete packages and obsolete source tarballs
40 push|-p Upload new packages to the main mirror
41 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
42 pull Download new packages from the main mirror
43 dry-pull Show what will be downloaded from the mirror. Does nothing
44 relpkg|-rp Archive and upload new package/project version
46 $(boldify "Options:")
47 --rootfs= Path to the chroot to generate or clean
48 --arch= Specify the architecture type for cross-chroot, push/pull
49 --clean Clean chroot before generation a new one
51 $(boldify "Options:")
52 $(basename $0) gen-chroot undigest --clean
53 $(basename $0) chroot stable
54 $(basename $0) -c --arch=arm
56 EOT
57 }
59 get_version() {
60 # Stable, undigest or custom.
61 if [ "$2" ] && [ ! $(echo $2 | grep "\--*") ]; then
62 version=$2
63 slitaz=$SLITAZ_HOME/$2
64 else
65 version=cooking
66 slitaz=$SLITAZ_HOME/cooking
67 fi
68 if [ "$arch" ]; then
69 rootfs=$slitaz/$arch/chroot
70 else
71 rootfs=$slitaz/chroot
72 fi
73 }
75 check_mirror() {
76 # ping -c 1 $MIRROR
77 if [ -n "$2" ]; then
78 user=$2
79 else
80 user=$user
81 fi
82 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
83 remote=$MIRROR_PKGS/stable/
84 local=$SLITAZ_HOME/stable/packages/
85 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
86 remote=$MIRROR_PKGS/undigest/
87 local=$SLITAZ_HOME/undigest/packages/
88 else
89 remote=$MIRROR_PKGS/cooking/
90 local=$SLITAZ_HOME/cooking/packages/
91 fi
92 if [ "$arch" ]; then
93 remote=${remote}$arch/
94 local=${local}$arch/
95 fi
96 }
98 # Bind a directory into the chroot
99 bind_chroot_dir()
100 {
101 mkdir -p $1 $2
102 mount -o bind $1 $2
103 }
105 # Mount virtual Kernel file systems and chroot but check that nobody
106 # else has done mounts
107 mount_chroot()
108 {
109 if [ ! -d $rootfs/proc/1 ]; then
110 echo -ne "\nMounting virtual filesystems..."
111 mount -t proc proc $rootfs/proc
112 mount -t sysfs sysfs $rootfs/sys
113 mount -t devpts devpts $rootfs/dev/pts
114 mount -t tmpfs shm $rootfs/dev/shm
115 status
116 fi
117 # Mount source so they can be shared between cooking/stable/undigest.
118 # But do it only if it's a slitaz developement chroot.
119 fs=$rootfs/home/slitaz
120 if [ -d "$slitaz" ]; then
121 bind_chroot_dir $SLITAZ_HOME/src $fs/src
122 # Now mount package dir so they are in /home/slitaz/$version
123 # We may not mount cache wok or others it has no point and if
124 # one wants to use a shared wok he can bind it manually.
125 if [ "$arch" ]; then
126 slitaz=$slitaz/$arch
127 fi
128 [ -d "$fs/packages" ] || mkdir -p $fs/packages
129 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
130 bind_chroot_dir $slitaz/packages $fs/packages
131 fi
132 }
134 # Unmount virtual Kernel file systems.
135 umount_chroot() {
136 [ "$1" ] && rootfs=$1
137 fs=$rootfs/home/slitaz
138 echo -ne "\nUnmounting virtual filesystems..."
139 umount $rootfs/dev/shm
140 umount $rootfs/dev/pts
141 umount $rootfs/sys
142 umount $rootfs/proc
143 if mount | fgrep -q $fs/src; then
144 umount $fs/src
145 umount $fs/packages
146 fi
147 status && echo ""
148 }
150 # Get the last cooking base rootfs, extract and configure.
151 gen_chroot() {
152 echo -e "\nGenerating new chroot in: $rootfs"
153 separator
154 mkdir -p $rootfs
155 # We my gen cooking chroot from a stable version or invers
156 case "$version" in
157 cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
158 stable|4.0) url="http://$MIRROR/packages/stable/" ;;
159 esac
160 # --mirror=
161 [ "$mirror" ] && url="$mirror"
162 mpath=/var/lib/tazpkg/mirror
163 cp $mpath ${mpath}.tazdev
164 echo "$url" > $mpath
165 echo -n "Mirror URL: ${url#http://}"
166 tazpkg recharge 2>/dev/null 1>/dev/null
167 status
168 for pkg in $CHROOT_PKGS
169 do
170 echo -n "Installing: $pkg $vers"
171 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
172 status
173 done
174 echo -n "Creating resolv.conf..."
175 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
176 status
177 echo -n "Restoring host packages list..."
178 mv -f ${mpath}.tazdev $mpath
179 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
180 status
181 separator
182 case "$version" in
183 cooking) version="" ;;
184 esac
185 [ "$arch" ] && version="$version --arch=$arch"
186 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
187 newline
188 }
190 # Remove obsolate slitaz packages --> in cooker ???
191 purge_packages() {
192 arg=$1
193 tmp=/tmp/tazdev.$$
194 ls $wok| while read pkg; do
195 [ -f $wok/$pkg/taz/*/receipt ] || continue
196 unset VERSION EXTRAVERSION
197 . $wok/$pkg/taz/*/receipt
198 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
199 done > $tmp
200 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
201 case "$pkg" in
202 *.tazpkg)
203 grep -q ^$pkg$ $tmp && continue
204 echo "Removing pkg: $pkg"
205 [ "$arg" == "purge" ] &&
206 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
207 esac
208 done
209 rm -f $tmp
210 }
212 # Remove obsolete source tarballs --> in cooker ??? but we share $src
213 # between cooking and stable to we must scan all versions, all arch
214 purge_sources() {
215 arg=$1
216 wok=$slitaz/chroot/home/slitaz/wok
217 tmp=/tmp/tazdev.$$
218 ls $wok| while read pkg; do
219 [ -f $wok/$pkg/receipt ] || continue
220 TARBALL=""
221 . $wok/$pkg/receipt
222 [ -n "$TARBALL" ] && echo $TARBALL
223 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
224 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
225 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
226 sed "s|['\"/]||g" | while read file ; do
227 eval echo $file 2> /dev/null
228 done
229 done > $tmp
230 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
231 grep -q ^$pkg$ $tmp && continue
232 echo "Removing src: $pkg"
233 [ "$arg" == "purge" ] &&
234 rm -f $slitaz/chroot/home/slitaz/src/$pkg
235 done
236 rm -f $tmp
237 }
239 case "$1" in
240 stats|-s)
241 echo -e "\nStatistics for: $PROJECTS\n"
242 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
243 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
244 separator
245 cd $PROJECTS
246 for proj in *
247 do
248 rev=""
249 echo -n "$proj"
250 size=`du -sh $proj | awk '{ print $1 }'`
251 echo -ne "\033[24G $size"
252 if [ -d $proj/.hg ]; then
253 cd $proj
254 rev=`hg head --template '{rev}\n'`
255 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
256 echo -ne "\033[38G $rev"
257 echo -ne "\033[48G $vers" && cd ..
258 fi
259 files=`find $proj -type f | wc -l`
260 echo -e "\033[64G $files"
261 done
262 separator
263 echo "" ;;
264 chroot|-c)
265 # Chroot into a build env. Default to cooking configured in tazdev.conf
266 check_root
267 get_version $@
268 [ -d "$2" ] && rootfs=$2
269 mount_chroot
270 echo -e "Chrooting to: $rootfs\n"
271 chroot $rootfs /bin/sh --login
272 umount_chroot ;;
273 umount-chroot|-uc)
274 check_root
275 get_version $@
276 [ -d "$2" ] && rootfs=$2
277 umount_chroot $rootfs ;;
278 gen-chroot|-gc)
279 check_root
280 # We can use: --rootfs=/path/to/chroot
281 if [ ! "$rootfs" ]; then
282 get_version $@
283 fi
284 if [ "$clean" ] || [ "$forced" ]; then
285 $0 -cc --rootfs=$rootfs --noline
286 fi
287 # Dont break another env.
288 if [ -d $rootfs/bin ]; then
289 echo -e "\nA chroot environment already exists in : $rootfs\n"
290 exit 1
291 fi
292 gen_chroot ;;
293 clean-chroot|-cc)
294 check_root
295 # We can use: --rootfs=/path/to/chroot
296 if [ ! "$rootfs" ]; then
297 get_version $@
298 fi
299 if [ ! -d "$rootfs" ]; then
300 echo -e "\nChroot doesn't exist: $rootfs\n"
301 exit 1
302 fi
303 if [ -d $rootfs/proc/1 ]; then
304 echo -e "\nWARNING: $rootfs/proc mounted!\n"
305 exit 1
306 fi
307 cd $rootfs || exit 1
308 echo ""
309 boldify "Cleaning chroot: $rootfs"
310 separator
311 # Keep root/ and /home they may have a build wok, custom scripts, etc.
312 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
313 do
314 if [ -d "$i" ]; then
315 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
316 rm -rf $i && status
317 fi
318 done
319 rm -f init
320 separator
321 [ "$noline" ] || newline ;;
322 push|-p)
323 check_mirror $@
324 rsync -r -t -O -l -v -z --delete \
325 $local -e ssh $user@$MIRROR:$remote ;;
326 dry-push|-dp)
327 check_mirror $@
328 rsync -r -t -O -l -v -z --delete --dry-run \
329 $local -e ssh $user@$MIRROR:$remote ;;
330 pull)
331 check_mirror $@
332 rsync -r -t -l -v -z --delete \
333 -e ssh $user@$MIRROR:$remote $local ;;
334 dry-pull)
335 check_mirror $@
336 rsync -r -t -l -v -z --delete --dry-run \
337 -e ssh $user@$MIRROR:$remote $local ;;
338 purge|dry-purge)
339 check_root
340 get_version $@
341 purge_packages $1
342 purge_sources $1 ;;
343 relpkg|-rp)
344 # Release a slitaz sub-project and upload tarball to mirror
345 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
346 if [ -z $2 ] || [ -z $3 ]; then
347 echo -e "\nUsage: $0 relpkg package version\n"
348 exit 0
349 fi
350 pkg=$2
351 version=$3
352 echo "" && cd $PROJECTS/$pkg
354 # Sanity check
355 if ! grep -q $version$ .hgtags; then
356 echo "Missing Hg tag for version: $version"
357 echo -e "You may want to: hg tag $version && hg push\n"
358 exit 0
359 fi
361 # Archive
362 echo -n "Creating tarball and md5sum for: $pkg-$version... "
363 hg archive -t tgz $pkg-$version.tar.gz
364 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
365 echo "Done"
367 # Upload
368 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
369 read upload
370 if [ "$upload" = "y" ]; then
371 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
372 scp $pkg-$version.tar.gz $pkg-$version.md5 \
373 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
374 fi
376 # Update pkg in wok
377 echo -n "Do you wish to update $pkg in wok [N/y] ? "
378 read update
379 if [ "$update" = "y" ]; then
380 echo -n "Updating $pkg: $version"
381 cd $PROJECTS/wok
382 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
383 status
384 fi ;;
385 help)
386 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
387 echo ""
388 boldify "Help for: $2"
389 separator
390 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
391 less -M /usr/share/doc/slitaz/$2.txt
392 else
393 echo "No help found"
394 fi
395 separator && echo "" ;;
396 usage|*)
397 usage ;;
398 esac
400 exit 0