wok-stable view slitaz-dev-tools/stuff/tazdev @ rev 5160
tazdev: add new cmd in usage
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Wed Mar 24 21:48:38 2010 +0100 (2010-03-24) |
parents | 8399ea7a8262 |
children | d26b0b60ce2e |
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 obsolate packages and obsolate source tarballs.
34 dry-purge Show obsolate packages and obsolate 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 uploade 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/taz/*/receipt ] || continue
181 TARBALL=""
182 . $BUILD_WOK/$pkg/taz/*/receipt
183 [ -n "$TARBALL" ] && echo $TARBALL
184 done > $TMP_FILE
185 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
186 grep -q ^$pkg$ $TMP_FILE && continue
187 echo Remove $pkg
188 [ "$arg" == "purge" ] &&
189 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
190 done
191 rm -f $TMP_FILE
192 }
194 case "$1" in
195 cmplog)
196 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
197 check_root
198 echo -e "Starting 'tazwok cmp' (can be long)...\n"
199 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
200 echo "Date: `date`" >> $CMP_LOG ;;
201 '-ps'|projects-stats)
202 echo -e "\nStatistics for: $PROJECTS\n"
203 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
204 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
205 echo "================================================================================"
206 cd $PROJECTS
207 for proj in *
208 do
209 rev=""
210 echo -n "$proj"
211 size=`du -sh $proj | awk '{ print $1 }'`
212 echo -ne "\033[24G $size"
213 if [ -d $proj/.hg ]; then
214 cd $proj
215 rev=`hg head --template '{rev}\n'`
216 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
217 echo -ne "\033[38G $rev"
218 echo -ne "\033[48G $vers" && cd ..
219 fi
220 files=`find $proj -type f | wc -l`
221 echo -e "\033[64G $files"
222 done
223 echo "================================================================================"
224 echo "" ;;
225 update-wok)
226 # Update the Hg wok and copy it to the chroot env. Hg wok is
227 # copied to the chroot wok to avoid messing with build result
228 # file and so we can also modify receipt directly without affecting
229 # the Hg wok.
230 check_root
231 get_version $@
232 echo ""
233 echo "Hg wok : $HG_WOK"
234 echo "Build wok : $BUILD_WOK"
235 cd $HG_WOK
236 hg pull && hg update
237 echo -n "Copying Hg wok to the build wok... "
238 cp -a $HG_WOK/* $BUILD_WOK
239 cp -a $HG_WOK/.hg $BUILD_WOK
240 status && echo "" ;;
241 update-www)
242 # Update website from repo.
243 echo ""
244 cd $WEBSITE && hg pull && hg update
245 echo "" ;;
246 chroot)
247 # Chroot into a build env. Default to cooking configured in
248 # tazdev.conf
249 check_root
250 get_version $@
251 mount_chroot
252 echo -e "\nChrooting in $ROOTFS...\n"
253 chroot $ROOTFS /bin/sh --login
254 umount_chroot
255 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
256 gen-chroot)
257 check_root
258 get_version $@
259 # Dont break another env.
260 if [ -d $ROOTFS/bin ]; then
261 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
262 exit 1
263 fi
264 gen_new_chroot ;;
265 clean-chroot)
266 # Keep root/ and /home they may have a build wok, custom scripts, etc.
267 check_root
268 if [ -z "$2" ]; then
269 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
270 exit 0
271 else
272 ROOTFS=$2
273 if [ ! -d "$ROOTFS" ]; then
274 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
275 exit 1
276 fi
277 fi
278 if [ -d $ROOTFS/proc/1 ]; then
279 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
280 exit 1
281 fi
282 cd $ROOTFS || exit 1
283 echo -e "\nCleaning chroot in: $ROOTFS"
284 echo "================================================================================"
285 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
286 do
287 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
288 rm -rf $i
289 status
290 done
291 echo "================================================================================"
292 echo "" ;;
293 '-p'|push)
294 check_mirror $@
295 rsync -r -t -l -v -z --delete \
296 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
297 '-dp'|dry-push)
298 check_mirror $@
299 rsync -r -t -l -v -z --delete --dry-run \
300 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
301 pull)
302 check_mirror $@
303 rsync -r -t -l -v -z --delete \
304 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
305 dry-pull)
306 check_mirror $@
307 rsync -r -t -l -v -z --delete --dry-run \
308 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
309 purge|dry-purge)
310 check_root
311 get_version $@
312 purge_packages $1
313 purge_sources $1 ;;
314 relpkg)
315 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
316 if [ -z $2 ] || [ -z $3 ]; then
317 echo -e "\nUsage: $0 relpkg package version\n"
318 exit 0
319 fi
320 PACKAGE=$2
321 VERSION=$3
322 echo ""
323 cd $PROJECTS/$PACKAGE
324 # Sanity check
325 if ! grep -q $VERSION$ .hgtags; then
326 echo "Missing Hg tag for version: $VERSION"
327 echo -e "You may want to: hg tag $VERSION && hg push\n"
328 exit 0
329 fi
330 # Archive
331 echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... "
332 hg archive -t tgz $PACKAGE-$VERSION.tar.gz
333 md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5
334 echo "Done"
335 # Upload
336 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
337 read upload
338 if [ "$upload" = "y" ]; then
339 echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}"
340 scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \
341 $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-}
342 fi ;;
343 usage|*)
344 usage ;;
345 esac
347 exit 0