wok view slitaz-dev-tools/stuff/tazdev @ rev 4902

Typo in tazbb
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 11 17:28:21 2010 +0100 (2010-02-11)
parents 031f6e973842
children 8399ea7a8262
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.\n"
39 }
41 # Exit if user is not root.
42 check_root()
43 {
44 if test $(id -u) != 0 ; then
45 echo -e "\nThis program requires being run as root.\n"
46 exit 0
47 fi
48 }
50 status()
51 {
52 local CHECK=$?
53 echo -en "\033[70G"
54 if [ $CHECK = 0 ]; then
55 echo "Done"
56 else
57 echo "Failed"
58 fi
59 return $CHECK
60 }
62 get_version()
63 {
64 if [ "$2" = "stable" ]; then
65 VERSION=stable
66 SLITAZ=$STABLE
67 elif [ -n "$2" ]; then
68 # Undigest - custom ?
69 VERSION=$2
70 SLITAZ=/home/slitaz/$2
71 else
72 VERSION=cooking
73 SLITAZ=$COOKING
74 fi
75 ROOTFS=$SLITAZ/chroot
76 HG_WOK=$SLITAZ/wok
77 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok
78 }
80 check_mirror()
81 {
82 # ping -c 1 $MIRROR
83 if [ -n "$2" ]; then
84 USER=$2
85 else
86 USER=$USER
87 fi
88 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
89 REMOTE_DIR=$MIRROR_DIR/stable/
90 LOCAL_DIR=$STABLE/packages/
91 else
92 REMOTE_DIR=$MIRROR_DIR/cooking/
93 LOCAL_DIR=$COOKING/packages/
94 fi
95 }
97 # Mount virtual Kernel file systems and chroot but check that nobody
98 # else has done mounts
99 mount_chroot()
100 {
101 if [ ! -d $ROOTFS/proc/1 ]; then
102 echo -n "Mounting virtual filesystems..."
103 mount -t proc proc $ROOTFS/proc
104 mount -t sysfs sysfs $ROOTFS/sys
105 mount -t devpts devpts $ROOTFS/dev/pts
106 mount -t tmpfs shm $ROOTFS/dev/shm
107 status
108 fi
109 }
111 # Unmount virtual Kernel file systems on exit and ensure we are the last
112 # user before unmounting !
113 umount_chroot()
114 {
115 # Not working. Buggy ps ?
116 #sleep 6
117 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
118 if [ "$ps" == "1" ]; then
119 echo -ne "\Unmounting virtual filesystems..."
120 umount $ROOTFS/dev/shm
121 umount $ROOTFS/dev/pts
122 umount $ROOTFS/sys
123 umount $ROOTFS/proc
124 status
125 else
126 echo -e "\nProcess: $ps\n"
127 ps | grep `basename $0` | grep -v grep
128 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
129 fi
130 }
132 # Get the last cooking base rootfs, extract and configure.
133 gen_new_chroot()
134 {
135 echo -e "\nGenerating new chroot in : $ROOTFS"
136 echo "================================================================================"
137 mkdir -p $ROOTFS && cd $ROOTFS
138 wget $DL_URL/boot/cooking/rootfs-base.gz
139 echo -n "Extracting the rootfs..."
140 lzma d rootfs-base.gz -so | cpio -id
141 rm rootfs-base.gz
142 echo -n "Creating resolv.conf..."
143 cat /etc/resolv.conf > etc/resolv.conf
144 status
145 echo "================================================================================"
146 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
147 echo -e "Example: tazdev chroot $ROOTFS\n"
148 }
150 # Remove obsolate slitaz packages
151 purge_packages()
152 {
153 arg=$1
154 TMP_FILE=/tmp/tazdev.$$
155 ls $BUILD_WOK | while read pkg; do
156 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
157 EXTRAVERSION=""
158 . $BUILD_WOK/$pkg/taz/*/receipt
159 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
160 done > $TMP_FILE
161 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
162 case "$pkg" in
163 *.tazpkg)
164 grep -q ^$pkg$ $TMP_FILE && continue
165 echo Remove $pkg
166 [ "$arg" == "purge" ] &&
167 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
168 esac
169 done
170 rm -f $TMP_FILE
171 }
173 # Remove obsolate source tarballs
174 purge_sources()
175 {
176 arg=$1
177 TMP_FILE=/tmp/tazdev.$$
178 ls $BUILD_WOK | while read pkg; do
179 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
180 TARBALL=""
181 . $BUILD_WOK/$pkg/taz/*/receipt
182 [ -n "$TARBALL" ] && echo $TARBALL
183 done > $TMP_FILE
184 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
185 grep -q ^$pkg$ $TMP_FILE && continue
186 echo Remove $pkg
187 [ "$arg" == "purge" ] &&
188 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
189 done
190 rm -f $TMP_FILE
191 }
193 case "$1" in
194 cmplog)
195 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
196 check_root
197 echo -e "Starting 'tazwok cmp' (can be long)...\n"
198 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
199 echo "Date: `date`" >> $CMP_LOG ;;
200 '-ps'|projects-stats)
201 echo -e "\nStatistics for: $PROJECTS\n"
202 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
203 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
204 echo "================================================================================"
205 cd $PROJECTS
206 for proj in *
207 do
208 rev=""
209 echo -n "$proj"
210 size=`du -sh $proj | awk '{ print $1 }'`
211 echo -ne "\033[24G $size"
212 if [ -d $proj/.hg ]; then
213 cd $proj
214 rev=`hg head --template '{rev}\n'`
215 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
216 echo -ne "\033[38G $rev"
217 echo -ne "\033[48G $vers" && cd ..
218 fi
219 files=`find $proj -type f | wc -l`
220 echo -e "\033[64G $files"
221 done
222 echo "================================================================================"
223 echo "" ;;
224 update-wok)
225 # Update the Hg wok and copy it to the chroot env. Hg wok is
226 # copied to the chroot wok to avoid messing with build result
227 # file and so we can also modify receipt directly without affecting
228 # the Hg wok.
229 check_root
230 get_version $@
231 echo ""
232 echo "Hg wok : $HG_WOK"
233 echo "Build wok : $BUILD_WOK"
234 cd $HG_WOK
235 hg pull && hg update
236 echo -n "Copying Hg wok to the build wok... "
237 cp -a $HG_WOK/* $BUILD_WOK
238 cp -a $HG_WOK/.hg $BUILD_WOK
239 status && echo "" ;;
240 update-www)
241 # Update website from repo.
242 echo ""
243 cd $WEBSITE && hg pull && hg update
244 echo "" ;;
245 chroot)
246 # Chroot into a build env. Default to cooking configured in
247 # tazdev.conf
248 check_root
249 get_version $@
250 mount_chroot
251 echo -e "\nChrooting in $ROOTFS...\n"
252 chroot $ROOTFS /bin/sh --login
253 umount_chroot
254 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
255 gen-chroot)
256 check_root
257 get_version $@
258 # Dont break another env.
259 if [ -d $ROOTFS/bin ]; then
260 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
261 exit 1
262 fi
263 gen_new_chroot ;;
264 clean-chroot)
265 # Keep root/ and /home they may have a build wok, custom scripts, etc.
266 check_root
267 if [ -z "$2" ]; then
268 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
269 exit 0
270 else
271 ROOTFS=$2
272 if [ ! -d "$ROOTFS" ]; then
273 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
274 exit 1
275 fi
276 fi
277 if [ -d $ROOTFS/proc/1 ]; then
278 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
279 exit 1
280 fi
281 cd $ROOTFS || exit 1
282 echo -e "\nCleaning chroot in: $ROOTFS"
283 echo "================================================================================"
284 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
285 do
286 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
287 rm -rf $i
288 status
289 done
290 echo "================================================================================"
291 echo "" ;;
292 '-p'|push)
293 check_mirror $@
294 rsync -r -t -l -v -z --delete \
295 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
296 '-dp'|dry-push)
297 check_mirror $@
298 rsync -r -t -l -v -z --delete --dry-run \
299 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
300 pull)
301 check_mirror $@
302 rsync -r -t -l -v -z --delete \
303 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
304 dry-pull)
305 check_mirror $@
306 rsync -r -t -l -v -z --delete --dry-run \
307 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
308 purge|dry-purge)
309 check_root
310 get_version $@
311 purge_packages $1
312 purge_sources $1
313 ;;
314 usage|*)
315 usage ;;
316 esac
318 exit 0