slitaz-dev-tools view tazdev/tazdev @ rev 3

tazdev: enable undigest
author Christophe Lincoln <pankso@slitaz.org>
date Thu Feb 24 05:18:06 2011 +0100 (2011-02-24)
parents 87e9b59fc58f
children 65ae34724ae6
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|undigest|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 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
93 REMOTE_DIR=$MIRROR_PKGS/undigest/
94 LOCAL_DIR=$UNDIGEST/packages/
95 else
96 REMOTE_DIR=$MIRROR_PKGS/cooking/
97 LOCAL_DIR=$COOKING/packages/
98 fi
99 }
101 # Mount virtual Kernel file systems and chroot but check that nobody
102 # else has done mounts
103 mount_chroot()
104 {
105 if [ ! -d $ROOTFS/proc/1 ]; then
106 echo -n "Mounting virtual filesystems..."
107 mount -t proc proc $ROOTFS/proc
108 mount -t sysfs sysfs $ROOTFS/sys
109 mount -t devpts devpts $ROOTFS/dev/pts
110 mount -t tmpfs shm $ROOTFS/dev/shm
111 status
112 fi
113 }
115 # Unmount virtual Kernel file systems on exit and ensure we are the last
116 # user before unmounting !
117 umount_chroot()
118 {
119 # Not working. Buggy ps ?
120 #sleep 6
121 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
122 if [ "$ps" == "1" ]; then
123 echo -ne "\Unmounting virtual filesystems..."
124 umount $ROOTFS/dev/shm
125 umount $ROOTFS/dev/pts
126 umount $ROOTFS/sys
127 umount $ROOTFS/proc
128 status
129 else
130 echo -e "\nProcess: $ps\n"
131 ps | grep `basename $0` | grep -v grep
132 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
133 fi
134 }
136 # Get the last cooking base rootfs, extract and configure.
137 gen_new_chroot()
138 {
139 echo -e "\nGenerating new chroot in : $ROOTFS"
140 echo "================================================================================"
141 mkdir -p $ROOTFS && cd $ROOTFS
142 wget $DL_URL/boot/cooking/rootfs-base.gz
143 echo -n "Extracting the rootfs..."
144 lzma d rootfs-base.gz -so | cpio -id
145 rm rootfs-base.gz
146 echo -n "Creating resolv.conf..."
147 cat /etc/resolv.conf > etc/resolv.conf
148 status
149 echo "================================================================================"
150 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
151 echo -e "Example: tazdev chroot $ROOTFS\n"
152 }
154 # Remove obsolate slitaz packages
155 purge_packages()
156 {
157 arg=$1
158 TMP_FILE=/tmp/tazdev.$$
159 ls $BUILD_WOK | while read pkg; do
160 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
161 EXTRAVERSION=""
162 . $BUILD_WOK/$pkg/taz/*/receipt
163 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
164 done > $TMP_FILE
165 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
166 case "$pkg" in
167 *.tazpkg)
168 grep -q ^$pkg$ $TMP_FILE && continue
169 echo Remove $pkg
170 [ "$arg" == "purge" ] &&
171 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
172 esac
173 done
174 rm -f $TMP_FILE
175 }
177 # Remove obsolate source tarballs
178 purge_sources()
179 {
180 arg=$1
181 TMP_FILE=/tmp/tazdev.$$
182 ls $BUILD_WOK | while read pkg; do
183 [ -f $BUILD_WOK/$pkg/receipt ] || continue
184 TARBALL=""
185 . $BUILD_WOK/$pkg/receipt
186 [ -n "$TARBALL" ] && echo $TARBALL
187 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
188 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
189 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
190 sed "s|['\"/]||g" | while read file ; do
191 eval echo $file 2> /dev/null
192 done
193 done > $TMP_FILE
194 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
195 grep -q ^$pkg$ $TMP_FILE && continue
196 echo Remove $pkg
197 [ "$arg" == "purge" ] &&
198 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
199 done
200 rm -f $TMP_FILE
201 }
203 case "$1" in
204 cmplog)
205 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
206 check_root
207 echo -e "Starting 'tazwok cmp' (can be long)...\n"
208 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
209 echo "Date: `date`" >> $CMP_LOG ;;
210 '-ps'|projects-stats)
211 echo -e "\nStatistics for: $PROJECTS\n"
212 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
213 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
214 echo "================================================================================"
215 cd $PROJECTS
216 for proj in *
217 do
218 rev=""
219 echo -n "$proj"
220 size=`du -sh $proj | awk '{ print $1 }'`
221 echo -ne "\033[24G $size"
222 if [ -d $proj/.hg ]; then
223 cd $proj
224 rev=`hg head --template '{rev}\n'`
225 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
226 echo -ne "\033[38G $rev"
227 echo -ne "\033[48G $vers" && cd ..
228 fi
229 files=`find $proj -type f | wc -l`
230 echo -e "\033[64G $files"
231 done
232 echo "================================================================================"
233 echo "" ;;
234 update-wok)
235 # Update the Hg wok and copy it to the chroot env. Hg wok is
236 # copied to the chroot wok to avoid messing with build result
237 # file and so we can also modify receipt directly without affecting
238 # the Hg wok.
239 check_root
240 get_version $@
241 echo ""
242 echo "Hg wok : $HG_WOK"
243 echo "Build wok : $BUILD_WOK"
244 cd $HG_WOK
245 hg pull && hg update
246 echo -n "Copying Hg wok to the build wok... "
247 cp -a $HG_WOK/* $BUILD_WOK
248 cp -a $HG_WOK/.hg $BUILD_WOK
249 status && echo "" ;;
250 update-www)
251 # Update website from repo.
252 echo ""
253 cd $WEBSITE && hg pull && hg update
254 echo "" ;;
255 chroot)
256 # Chroot into a build env. Default to cooking configured in
257 # tazdev.conf
258 check_root
259 get_version $@
260 mount_chroot
261 echo -e "\nChrooting in $ROOTFS...\n"
262 chroot $ROOTFS /bin/sh --login
263 umount_chroot
264 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
265 gen-chroot)
266 check_root
267 get_version $@
268 # Dont break another env.
269 if [ -d $ROOTFS/bin ]; then
270 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
271 exit 1
272 fi
273 gen_new_chroot ;;
274 clean-chroot)
275 # Keep root/ and /home they may have a build wok, custom scripts, etc.
276 check_root
277 if [ -z "$2" ]; then
278 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
279 exit 0
280 else
281 ROOTFS=$2
282 if [ ! -d "$ROOTFS" ]; then
283 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
284 exit 1
285 fi
286 fi
287 if [ -d $ROOTFS/proc/1 ]; then
288 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
289 exit 1
290 fi
291 cd $ROOTFS || exit 1
292 echo -e "\nCleaning chroot in: $ROOTFS"
293 echo "================================================================================"
294 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
295 do
296 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
297 rm -rf $i
298 status
299 done
300 echo "================================================================================"
301 echo "" ;;
302 '-p'|push)
303 check_mirror $@
304 rsync -r -t -l -v -z --delete \
305 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
306 '-dp'|dry-push)
307 check_mirror $@
308 rsync -r -t -l -v -z --delete --dry-run \
309 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
310 pull)
311 check_mirror $@
312 rsync -r -t -l -v -z --delete \
313 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
314 dry-pull)
315 check_mirror $@
316 rsync -r -t -l -v -z --delete --dry-run \
317 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
318 purge|dry-purge)
319 check_root
320 get_version $@
321 purge_packages $1
322 purge_sources $1 ;;
323 relpkg)
324 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
325 if [ -z $2 ] || [ -z $3 ]; then
326 echo -e "\nUsage: $0 relpkg package version\n"
327 exit 0
328 fi
329 PACKAGE=$2
330 VERSION=$3
331 echo ""
332 cd $PROJECTS/$PACKAGE
333 # Sanity check
334 if ! grep -q $VERSION$ .hgtags; then
335 echo "Missing Hg tag for version: $VERSION"
336 echo -e "You may want to: hg tag $VERSION && hg push\n"
337 exit 0
338 fi
339 # Archive
340 echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... "
341 hg archive -t tgz $PACKAGE-$VERSION.tar.gz
342 md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5
343 echo "Done"
344 # Upload
345 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
346 read upload
347 if [ "$upload" = "y" ]; then
348 echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}"
349 scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \
350 $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-}
351 fi ;;
352 usage|*)
353 usage ;;
354 esac
356 exit 0