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

tazdev: let use chroot pkgs version and gen chroot handle options: tazdev -gc undigest --clean
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 01 18:36:31 2012 +0200 (2012-06-01)
parents c787539dbaed
children 252fd7b50fd6
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
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 }
94 # Bind a directory into the chroot
95 bind_chroot_dir()
96 {
97 mkdir -p $1 $2
98 mount -o bind $1 $2
99 }
101 # Mount virtual Kernel file systems and chroot but check that nobody
102 # else has done mounts
103 mount_chroot()
104 {
105 if [ ! -d $rootfs/proc/1 ]; then
106 echo -ne "\nMounting virtual filesystems..."
107 mount -t proc proc $rootfs/proc
108 mount -t sysfs sysfs $rootfs/sys
109 mount -t devpts devpts $rootfs/dev/pts
110 mount -t tmpfs shm $rootfs/dev/shm
111 status
112 fi
113 # Mount source so they can be shared between cooking/stable/undigest.
114 # But do it only if it's a slitaz developement chroot.
115 fs=$rootfs/home/slitaz
116 if [ -d "$slitaz" ]; then
117 bind_chroot_dir $SLITAZ_HOME/src $fs/src
118 # Now mount package dir so they are in /home/slitaz/$version
119 # We may not mount cache wok or others it has no point and if
120 # one wants to use a shared wok he can bind it manually.
121 if [ "$arch" ]; then
122 slitaz=$slitaz/$arch
123 fi
124 [ -d "$fs/packages" ] || mkdir -p $fs/packages
125 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
126 bind_chroot_dir $slitaz/packages $fs/packages
127 fi
128 }
130 # Unmount virtual Kernel file systems.
131 umount_chroot() {
132 [ "$1" ] && rootfs=$1
133 fs=$rootfs/home/slitaz
134 echo -ne "\nUnmounting virtual filesystems..."
135 umount $rootfs/dev/shm
136 umount $rootfs/dev/pts
137 umount $rootfs/sys
138 umount $rootfs/proc
139 if mount | fgrep -q $fs/src; then
140 umount $fs/src
141 umount $fs/packages
142 fi
143 status && echo ""
144 }
146 # Get the last cooking base rootfs, extract and configure.
147 gen_chroot() {
148 echo -e "\nGenerating new chroot in: $rootfs"
149 separator
150 mkdir -p $rootfs
151 # We my gen cooking chroot from a stable version or invers
152 case "$version" in
153 cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
154 stable|4.0) url="http://$MIRROR/packages/stable/" ;;
155 esac
156 # --mirror=
157 [ "$mirror" ] && url="$mirror"
158 mpath=/var/lib/tazpkg/mirror
159 cp $mpath ${mpath}.tazdev
160 echo "$url" > $mpath
161 echo -n "Mirror URL: ${url#http://}"
162 tazpkg recharge 2>/dev/null 1>/dev/null
163 status
164 for pkg in $CHROOT_PKGS
165 do
166 echo -n "Installing: $pkg $vers"
167 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
168 status
169 done
170 echo -n "Creating resolv.conf..."
171 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
172 status
173 echo -n "Restoring host packages list..."
174 mv -f ${mpath}.tazdev $mpath
175 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
176 status
177 separator
178 case "$version" in
179 cooking) version="" ;;
180 esac
181 [ "$arch" ] && version="$version --arch=$arch"
182 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
183 newline
184 }
186 # Remove obsolate slitaz packages --> in cooker ???
187 purge_packages() {
188 arg=$1
189 tmp=/tmp/tazdev.$$
190 ls $wok| while read pkg; do
191 [ -f $wok/$pkg/taz/*/receipt ] || continue
192 unset VERSION EXTRAVERSION
193 . $wok/$pkg/taz/*/receipt
194 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
195 done > $tmp
196 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
197 case "$pkg" in
198 *.tazpkg)
199 grep -q ^$pkg$ $tmp && continue
200 echo "Removing pkg: $pkg"
201 [ "$arg" == "purge" ] &&
202 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
203 esac
204 done
205 rm -f $tmp
206 }
208 # Remove obsolete source tarballs --> in cooker ??? but we share $src
209 # between cooking and stable to we must scan all versions, all arch
210 purge_sources() {
211 arg=$1
212 wok=$slitaz/chroot/home/slitaz/wok
213 tmp=/tmp/tazdev.$$
214 ls $wok| while read pkg; do
215 [ -f $wok/$pkg/receipt ] || continue
216 TARBALL=""
217 . $wok/$pkg/receipt
218 [ -n "$TARBALL" ] && echo $TARBALL
219 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
220 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
221 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
222 sed "s|['\"/]||g" | while read file ; do
223 eval echo $file 2> /dev/null
224 done
225 done > $tmp
226 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
227 grep -q ^$pkg$ $tmp && continue
228 echo "Removing src: $pkg"
229 [ "$arg" == "purge" ] &&
230 rm -f $slitaz/chroot/home/slitaz/src/$pkg
231 done
232 rm -f $tmp
233 }
235 case "$1" in
236 stats|-s)
237 echo -e "\nStatistics for: $PROJECTS\n"
238 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
239 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
240 separator
241 cd $PROJECTS
242 for proj in *
243 do
244 rev=""
245 echo -n "$proj"
246 size=`du -sh $proj | awk '{ print $1 }'`
247 echo -ne "\033[24G $size"
248 if [ -d $proj/.hg ]; then
249 cd $proj
250 rev=`hg head --template '{rev}\n'`
251 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
252 echo -ne "\033[38G $rev"
253 echo -ne "\033[48G $vers" && cd ..
254 fi
255 files=`find $proj -type f | wc -l`
256 echo -e "\033[64G $files"
257 done
258 separator
259 echo "" ;;
260 chroot|-c)
261 # Chroot into a build env. Default to cooking configured in tazdev.conf
262 check_root
263 get_version $@
264 [ -d "$2" ] && rootfs=$2
265 mount_chroot
266 echo -e "Chrooting to: $rootfs\n"
267 chroot $rootfs /bin/sh --login
268 umount_chroot ;;
269 umount-chroot|-uc)
270 check_root
271 get_version $@
272 [ -d "$2" ] && rootfs=$2
273 umount_chroot $rootfs ;;
274 gen-chroot|-gc)
275 check_root
276 # We can use: --rootfs=/path/to/chroot
277 if [ ! "$rootfs" ]; then
278 get_version $@
279 fi
280 if [ "$clean" ] || [ "$forced" ]; then
281 $0 -cc --rootfs=$rootfs --noline
282 fi
283 # Dont break another env.
284 if [ -d $rootfs/bin ]; then
285 echo -e "\nA chroot environment already exists in : $rootfs\n"
286 exit 1
287 fi
288 gen_chroot ;;
289 clean-chroot|-cc)
290 check_root
291 # We can use: --rootfs=/path/to/chroot
292 if [ ! "$rootfs" ]; then
293 get_version $@
294 fi
295 if [ ! -d "$rootfs" ]; then
296 echo -e "\nChroot doesn't exist: $rootfs\n"
297 exit 1
298 fi
299 if [ -d $rootfs/proc/1 ]; then
300 echo -e "\nWARNING: $rootfs/proc mounted!\n"
301 exit 1
302 fi
303 cd $rootfs || exit 1
304 echo ""
305 boldify "Cleaning chroot: $rootfs"
306 separator
307 # Keep root/ and /home they may have a build wok, custom scripts, etc.
308 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
309 do
310 if [ -d "$i" ]; then
311 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
312 rm -rf $i && status
313 fi
314 done
315 rm -f init
316 separator
317 [ "$noline" ] || newline ;;
318 push|-p)
319 check_mirror $@
320 rsync -r -t -O -l -v -z --delete \
321 $local -e ssh $user@$MIRROR:$remote ;;
322 dry-push|-dp)
323 check_mirror $@
324 rsync -r -t -O -l -v -z --delete --dry-run \
325 $local -e ssh $user@$MIRROR:$remote ;;
326 pull)
327 check_mirror $@
328 rsync -r -t -l -v -z --delete \
329 -e ssh $user@$MIRROR:$remote $local ;;
330 dry-pull)
331 check_mirror $@
332 rsync -r -t -l -v -z --delete --dry-run \
333 -e ssh $user@$MIRROR:$remote $local ;;
334 purge|dry-purge)
335 check_root
336 get_version $@
337 purge_packages $1
338 purge_sources $1 ;;
339 relpkg|-rp)
340 # Release a slitaz sub-project and upload tarball to mirror
341 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
342 if [ -z $2 ] || [ -z $3 ]; then
343 echo -e "\nUsage: $0 relpkg package version\n"
344 exit 0
345 fi
346 pkg=$2
347 version=$3
348 echo "" && cd $PROJECTS/$pkg
350 # Sanity check
351 if ! grep -q $version$ .hgtags; then
352 echo "Missing Hg tag for version: $version"
353 echo -e "You may want to: hg tag $version && hg push\n"
354 exit 0
355 fi
357 # Archive
358 echo -n "Creating tarball and md5sum for: $pkg-$version... "
359 hg archive -t tgz $pkg-$version.tar.gz
360 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
361 echo "Done"
363 # Upload
364 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
365 read upload
366 if [ "$upload" = "y" ]; then
367 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
368 scp $pkg-$version.tar.gz $pkg-$version.md5 \
369 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
370 fi
372 # Update pkg in wok
373 echo -n "Do you wish to update $pkg in wok [N/y] ? "
374 read update
375 if [ "$update" = "y" ]; then
376 echo -n "Updating $pkg: $version"
377 cd $PROJECTS/wok
378 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
379 status
380 fi ;;
381 help)
382 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
383 echo ""
384 boldify "Help for: $2"
385 separator
386 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
387 less -M /usr/share/doc/slitaz/$2.txt
388 else
389 echo "No help found"
390 fi
391 separator && echo "" ;;
392 usage|*)
393 usage ;;
394 esac
396 exit 0