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

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