wok-4.x view slitaz-dev-tools/stuff/tazdev @ rev 6087
Add: clucene clucene-dev (0.9.21b)
author | Dominique Corbex <domcox@slitaz.org> |
---|---|
date | Sun Aug 29 21:24:52 2010 +0200 (2010-08-29) |
parents | d26b0b60ce2e |
children | 4249e7ca9034 |
line source
1 #!/bin/sh
2 # Tazdev - SliTaz developers and build host tool.
3 # System wide config file: /etc/slitaz/tazdev.conf
4 #
5 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3
6 #
7 # Authors : Christophe Lincoln (Pankso) <pankso@slitaz.org>
8 #
10 if [ -f /etc/slitaz/tazdev.conf ]; then
11 . /etc/slitaz/tazdev.conf
12 if [ -f $PWD/tazdev.conf ]; then
13 . $PWD/tazdev.conf
14 fi
15 else
16 echo -e "\nNo config file found in /etc/slitaz or the current dir...\n"
17 exit 0
18 fi
20 usage()
21 {
22 echo -e "\nSliTaz developers and build host tool\n
23 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|path]
24 \033[1mCommands: \033[0m\n
25 usage Print this short usage and command list.
26 projects-stats Display statistics about your projects (-ps).
27 cmplog Log 'tazwok cmp' result (or use tazbb).
28 update-wok Update Hg wok and copy it to the chroot wok.
29 update-www Update SliTaz Website repo from Hg.
30 chroot Mount virtual fs if needed and chroot into the build env.
31 gen-chroot Generate a chroot using the last cooking base rootfs.
32 clean-chroot Clean a chroot environment (skip root/ and home/).
33 purge Remove obsolete packages and obsolete source tarballs.
34 dry-purge Show obsolete packages and obsolete source tarballs.
35 push Upload new packages to the main mirror (-p).
36 dry-push Show what will be uploaded to the mirror. Does nothing (-dp).
37 pull Download new packages from the main mirror.
38 dry-pull Show what will be downloaded from the mirror. Does nothing.
39 relpkg Archive and upload new package/project version.\n"
40 }
42 # Exit if user is not root.
43 check_root()
44 {
45 if test $(id -u) != 0 ; then
46 echo -e "\nThis program requires being run as root.\n"
47 exit 0
48 fi
49 }
51 status()
52 {
53 local CHECK=$?
54 echo -en "\033[70G"
55 if [ $CHECK = 0 ]; then
56 echo "Done"
57 else
58 echo "Failed"
59 fi
60 return $CHECK
61 }
63 get_version()
64 {
65 if [ "$2" = "stable" ]; then
66 VERSION=stable
67 SLITAZ=$STABLE
68 elif [ -n "$2" ]; then
69 # Undigest - custom ?
70 VERSION=$2
71 SLITAZ=/home/slitaz/$2
72 else
73 VERSION=cooking
74 SLITAZ=$COOKING
75 fi
76 ROOTFS=$SLITAZ/chroot
77 HG_WOK=$SLITAZ/wok
78 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok
79 }
81 check_mirror()
82 {
83 # ping -c 1 $MIRROR
84 if [ -n "$2" ]; then
85 USER=$2
86 else
87 USER=$USER
88 fi
89 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
90 REMOTE_DIR=$MIRROR_PKGS/stable/
91 LOCAL_DIR=$STABLE/packages/
92 else
93 REMOTE_DIR=$MIRROR_PKGS/cooking/
94 LOCAL_DIR=$COOKING/packages/
95 fi
96 }
98 # Mount virtual Kernel file systems and chroot but check that nobody
99 # else has done mounts
100 mount_chroot()
101 {
102 if [ ! -d $ROOTFS/proc/1 ]; then
103 echo -n "Mounting virtual filesystems..."
104 mount -t proc proc $ROOTFS/proc
105 mount -t sysfs sysfs $ROOTFS/sys
106 mount -t devpts devpts $ROOTFS/dev/pts
107 mount -t tmpfs shm $ROOTFS/dev/shm
108 status
109 fi
110 }
112 # Unmount virtual Kernel file systems on exit and ensure we are the last
113 # user before unmounting !
114 umount_chroot()
115 {
116 # Not working. Buggy ps ?
117 #sleep 6
118 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
119 if [ "$ps" == "1" ]; then
120 echo -ne "\Unmounting virtual filesystems..."
121 umount $ROOTFS/dev/shm
122 umount $ROOTFS/dev/pts
123 umount $ROOTFS/sys
124 umount $ROOTFS/proc
125 status
126 else
127 echo -e "\nProcess: $ps\n"
128 ps | grep `basename $0` | grep -v grep
129 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
130 fi
131 }
133 # Get the last cooking base rootfs, extract and configure.
134 gen_new_chroot()
135 {
136 echo -e "\nGenerating new chroot in : $ROOTFS"
137 echo "================================================================================"
138 mkdir -p $ROOTFS && cd $ROOTFS
139 wget $DL_URL/boot/cooking/rootfs-base.gz
140 echo -n "Extracting the rootfs..."
141 lzma d rootfs-base.gz -so | cpio -id
142 rm rootfs-base.gz
143 echo -n "Creating resolv.conf..."
144 cat /etc/resolv.conf > etc/resolv.conf
145 status
146 echo "================================================================================"
147 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
148 echo -e "Example: tazdev chroot $ROOTFS\n"
149 }
151 # Remove obsolate slitaz packages
152 purge_packages()
153 {
154 arg=$1
155 TMP_FILE=/tmp/tazdev.$$
156 ls $BUILD_WOK | while read pkg; do
157 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
158 EXTRAVERSION=""
159 . $BUILD_WOK/$pkg/taz/*/receipt
160 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
161 done > $TMP_FILE
162 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
163 case "$pkg" in
164 *.tazpkg)
165 grep -q ^$pkg$ $TMP_FILE && continue
166 echo Remove $pkg
167 [ "$arg" == "purge" ] &&
168 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
169 esac
170 done
171 rm -f $TMP_FILE
172 }
174 # Remove obsolate source tarballs
175 purge_sources()
176 {
177 arg=$1
178 TMP_FILE=/tmp/tazdev.$$
179 ls $BUILD_WOK | while read pkg; do
180 [ -f $BUILD_WOK/$pkg/receipt ] || continue
181 TARBALL=""
182 . $BUILD_WOK/$pkg/receipt
183 [ -n "$TARBALL" ] && echo $TARBALL
184 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
185 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
186 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
187 sed "s|['\"/]||g" | while read file ; do
188 eval echo $file 2> /dev/null
189 done
190 done > $TMP_FILE
191 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
192 grep -q ^$pkg$ $TMP_FILE && continue
193 echo Remove $pkg
194 [ "$arg" == "purge" ] &&
195 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
196 done
197 rm -f $TMP_FILE
198 }
200 case "$1" in
201 cmplog)
202 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
203 check_root
204 echo -e "Starting 'tazwok cmp' (can be long)...\n"
205 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
206 echo "Date: `date`" >> $CMP_LOG ;;
207 '-ps'|projects-stats)
208 echo -e "\nStatistics for: $PROJECTS\n"
209 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
210 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
211 echo "================================================================================"
212 cd $PROJECTS
213 for proj in *
214 do
215 rev=""
216 echo -n "$proj"
217 size=`du -sh $proj | awk '{ print $1 }'`
218 echo -ne "\033[24G $size"
219 if [ -d $proj/.hg ]; then
220 cd $proj
221 rev=`hg head --template '{rev}\n'`
222 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
223 echo -ne "\033[38G $rev"
224 echo -ne "\033[48G $vers" && cd ..
225 fi
226 files=`find $proj -type f | wc -l`
227 echo -e "\033[64G $files"
228 done
229 echo "================================================================================"
230 echo "" ;;
231 update-wok)
232 # Update the Hg wok and copy it to the chroot env. Hg wok is
233 # copied to the chroot wok to avoid messing with build result
234 # file and so we can also modify receipt directly without affecting
235 # the Hg wok.
236 check_root
237 get_version $@
238 echo ""
239 echo "Hg wok : $HG_WOK"
240 echo "Build wok : $BUILD_WOK"
241 cd $HG_WOK
242 hg pull && hg update
243 echo -n "Copying Hg wok to the build wok... "
244 cp -a $HG_WOK/* $BUILD_WOK
245 cp -a $HG_WOK/.hg $BUILD_WOK
246 status && echo "" ;;
247 update-www)
248 # Update website from repo.
249 echo ""
250 cd $WEBSITE && hg pull && hg update
251 echo "" ;;
252 chroot)
253 # Chroot into a build env. Default to cooking configured in
254 # tazdev.conf
255 check_root
256 get_version $@
257 mount_chroot
258 echo -e "\nChrooting in $ROOTFS...\n"
259 chroot $ROOTFS /bin/sh --login
260 umount_chroot
261 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
262 gen-chroot)
263 check_root
264 get_version $@
265 # Dont break another env.
266 if [ -d $ROOTFS/bin ]; then
267 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
268 exit 1
269 fi
270 gen_new_chroot ;;
271 clean-chroot)
272 # Keep root/ and /home they may have a build wok, custom scripts, etc.
273 check_root
274 if [ -z "$2" ]; then
275 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
276 exit 0
277 else
278 ROOTFS=$2
279 if [ ! -d "$ROOTFS" ]; then
280 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
281 exit 1
282 fi
283 fi
284 if [ -d $ROOTFS/proc/1 ]; then
285 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
286 exit 1
287 fi
288 cd $ROOTFS || exit 1
289 echo -e "\nCleaning chroot in: $ROOTFS"
290 echo "================================================================================"
291 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
292 do
293 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
294 rm -rf $i
295 status
296 done
297 echo "================================================================================"
298 echo "" ;;
299 '-p'|push)
300 check_mirror $@
301 rsync -r -t -l -v -z --delete \
302 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
303 '-dp'|dry-push)
304 check_mirror $@
305 rsync -r -t -l -v -z --delete --dry-run \
306 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
307 pull)
308 check_mirror $@
309 rsync -r -t -l -v -z --delete \
310 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
311 dry-pull)
312 check_mirror $@
313 rsync -r -t -l -v -z --delete --dry-run \
314 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
315 purge|dry-purge)
316 check_root
317 get_version $@
318 purge_packages $1
319 purge_sources $1 ;;
320 relpkg)
321 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
322 if [ -z $2 ] || [ -z $3 ]; then
323 echo -e "\nUsage: $0 relpkg package version\n"
324 exit 0
325 fi
326 PACKAGE=$2
327 VERSION=$3
328 echo ""
329 cd $PROJECTS/$PACKAGE
330 # Sanity check
331 if ! grep -q $VERSION$ .hgtags; then
332 echo "Missing Hg tag for version: $VERSION"
333 echo -e "You may want to: hg tag $VERSION && hg push\n"
334 exit 0
335 fi
336 # Archive
337 echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... "
338 hg archive -t tgz $PACKAGE-$VERSION.tar.gz
339 md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5
340 echo "Done"
341 # Upload
342 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
343 read upload
344 if [ "$upload" = "y" ]; then
345 echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}"
346 scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \
347 $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-}
348 fi ;;
349 usage|*)
350 usage ;;
351 esac
353 exit 0