wok-6.x view slitaz-dev-tools/stuff/tazdev @ rev 3500

tazdev: Add command projects-stats (-ps)
author Christophe Lincoln <pankso@slitaz.org>
date Fri Jun 19 05:11:41 2009 +0200 (2009-06-19)
parents 3934f2921b68
children fbc02747724c
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 push Upload new packages to the main mirror (-p).
34 dry-push Show what will be uploaded to the mirror. Does nothing (-dp).
35 pull Download new packages from the main mirror.
36 dry-pull Show what will be downloaded from the mirror. Does nothing.\n"
37 }
39 # Exit if user is not root.
40 check_root()
41 {
42 if test $(id -u) != 0 ; then
43 echo -e "\nThis program requires being run as root.\n"
44 exit 0
45 fi
46 }
48 status()
49 {
50 local CHECK=$?
51 echo -en "\033[70G"
52 if [ $CHECK = 0 ]; then
53 echo "Done"
54 else
55 echo "Failed"
56 fi
57 return $CHECK
58 }
60 get_version()
61 {
62 if [ "$2" = "stable" ]; then
63 VERSION=stable
64 ROOTFS=$STABLE/chroot
65 elif [ -n "$2" ]; then
66 ROOTFS=$2
67 else
68 VERSION=cooking
69 ROOTFS=$COOKING/chroot
70 fi
71 }
73 check_mirror()
74 {
75 # ping -c 1 $MIRROR
76 if [ -n "$2" ]; then
77 USER=$2
78 else
79 echo -e "\nPlease specify a user.\n" && exit 0
80 fi
81 if [ "$3" = "stable" ]; then
82 REMOTE_DIR=$MIRROR_DIR/stable/
83 LOCAL_DIR=$STABLE/packages/
84 else
85 REMOTE_DIR=$MIRROR_DIR/cooking/
86 LOCAL_DIR=$COOKING/packages/
87 fi
88 }
90 # Mount virtual Kernel file systems and chroot but check that nobody
91 # else has done mounts
92 mount_chroot()
93 {
94 if [ ! -d $ROOTFS/proc/1 ]; then
95 echo -n "Mounting virtual filesystem..."
96 mount -t proc proc $ROOTFS/proc
97 mount -t sysfs sysfs $ROOTFS/sys
98 mount -t devpts devpts $ROOTFS/dev/pts
99 mount -t tmpfs shm $ROOTFS/dev/shm
100 status
101 fi
102 }
104 # Unmount virtual Kernel file systems on exit and ensure we are the last
105 # user before unmounting !
106 umount_chroot()
107 {
108 # Not working. Buggy ps ?
109 #sleep 6
110 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
111 if [ "$ps" == "1" ]; then
112 echo -ne "\Unmounting virtual filesystem..."
113 umount $ROOTFS/dev/shm
114 umount $ROOTFS/dev/pts
115 umount $ROOTFS/sys
116 umount $ROOTFS/proc
117 status
118 else
119 echo -e "\nProcess: $ps\n"
120 ps | grep `basename $0` | grep -v grep
121 echo -e "\nLeaving virtual filesystem unmounted (`pidof tazdev`)...\n"
122 fi
123 }
125 # Get the last cooking base rootfs, extract and configure.
126 gen_new_chroot()
127 {
128 echo -e "\nGenerating new chroot in : $ROOTFS"
129 echo "================================================================================"
130 mkdir -p $ROOTFS && cd $ROOTFS
131 wget $DL_URL/boot/cooking/rootfs-base.gz
132 echo -n "Extracting the rootfs..."
133 lzma d rootfs-base.gz -so | cpio -id
134 rm rootfs-base.gz
135 echo -n "Creating resolv.conf..."
136 cat /etc/resolv.conf > etc/resolv.conf
137 status
138 echo "================================================================================"
139 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
140 echo -e "Example: tazdev chroot $ROOTFS\n"
141 }
143 case "$1" in
144 cmplog)
145 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
146 check_root
147 echo -e "Starting 'tazwok cmp' (can be long)...\n"
148 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
149 echo "Date: `date`" >> $CMP_LOG ;;
150 '-ps'|projects-stats)
151 echo -e "\nStatistics for: $PROJECTS\n"
152 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
153 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
154 echo "================================================================================"
155 cd $PROJECTS
156 for proj in *
157 do
158 rev=""
159 echo -n "$proj"
160 size=`du -sh $proj | awk '{ print $1 }'`
161 echo -ne "\033[24G $size"
162 if [ -d $proj/.hg ]; then
163 cd $proj
164 rev=`hg head --template '{rev}\n'`
165 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
166 echo -ne "\033[38G $rev"
167 echo -ne "\033[48G $vers" && cd ..
168 fi
169 files=`find $proj -type f | wc -l`
170 echo -e "\033[64G $files"
171 done
172 echo "================================================================================"
173 echo "" ;;
174 update-wok)
175 # Update the Hg wok and copy it to the chroot env. Hg wok is
176 # copied to the chroot wok to avoid messing with build result
177 # file and so we can also modify receipt directly without affecting
178 # the Hg wok.
179 check_root
180 if [ "$2" = "stable" ]; then
181 HG_WOK=$STABLE/wok
182 BUILD_WOK=$STABLE/chroot/home/slitaz
183 else
184 HG_WOK=$COOKING/wok
185 BUILD_WOK=$COOKING/chroot/home/slitaz
186 fi
187 echo ""
188 echo "Hg wok : $HG_WOK"
189 echo "Build wok : $BUILD_WOK"
190 cd $HG_WOK
191 hg pull && hg update
192 echo -n "Copying Hg wok to the build wok... "
193 cp -a $HG_WOK/* $BUILD_WOK
194 cp -a $HG_WOK/.hg $BUILD_WOK
195 status && echo "" ;;
196 update-www)
197 # Update website from repo.
198 echo ""
199 cd $WEBSITE && hg pull && hg update
200 echo "" ;;
201 chroot)
202 # Chroot into a build env. Default to cooking configured in
203 # tazdev.conf
204 check_root
205 get_version
206 mount_chroot
207 echo -e "\nChrooting in $ROOTFS...\n"
208 chroot $ROOTFS /bin/sh --login
209 umount_chroot
210 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
211 gen-chroot)
212 check_root
213 get_version
214 # Dont break another env.
215 if [ -d $ROOTFS/bin ]; then
216 echo -e "\nA chroot environment already exist in : $ROOTFS\n"
217 exit 1
218 fi
219 gen_new_chroot ;;
220 clean-chroot)
221 # Keep root/ and /home they may have a build wok, custom scripts, etc.
222 check_root
223 if [ -z "$2" ]; then
224 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
225 exit 0
226 else
227 ROOTFS=$2
228 if [ ! -d "$ROOTFS" ]; then
229 echo -e "\nWarning : $ROOTFS dont exit!\n"
230 exit 1
231 fi
232 fi
233 if [ -d $ROOTFS/proc/1 ]; then
234 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
235 exit 1
236 fi
237 cd $ROOTFS || exit 1
238 echo -e "\nCleaning chroot in: $ROOTFS"
239 echo "================================================================================"
240 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
241 do
242 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
243 rm -rf $i
244 status
245 done
246 echo "================================================================================"
247 echo "" ;;
248 '-p'|push)
249 check_mirror
250 rsync -r -t -l -v -z --delete \
251 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
252 '-dp'|dry-push)
253 check_mirror
254 rsync -r -t -l -v -z --delete --dry-run \
255 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
256 pull)
257 check_mirror
258 rsync -r -t -l -v -z --delete \
259 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
260 dry-pull)
261 check_mirror
262 rsync -r -t -l -v -z --delete --dry-run \
263 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
264 usage|*)
265 usage ;;
266 esac
268 exit 0