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

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