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

tazdev: add reliso (I use it to rel official isos)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 12 19:57:29 2011 +0200 (2011-04-12)
parents 68cd24d0e743
children 50ae560e2993
line source
1 #!/bin/sh
2 #
3 # Tazdev - SliTaz developers and build host tool. System wide config
4 # file is located at: /etc/slitaz/tazdev.conf
5 #
6 # (c) 2011 SliTaz GNU/Linux - GNU gpl v3
7 #
8 # AUTHORS
9 # Christophe Lincoln <pankso@slitaz.org>
10 # Pascal Bellard <bellard@slitaz.org>
11 #
13 if [ -f /etc/slitaz/tazdev.conf ]; then
14 CONFIG=/etc/slitaz/tazdev.conf
15 else [ -f $PWD/tazdev.conf ]
16 CONFIG=$PWD/tazdev.conf
17 fi
18 if ! [ "$CONFIG" ]; then
19 echo -e "\nNo config file found in /etc/slitaz or the current dir...\n"
20 exit 0
21 else
22 . $CONFIG
23 fi
25 usage()
26 {
27 echo -e "\nSliTaz developers and build host tool\n
28 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|undigest|path]
29 \033[1mCommands: \033[0m\n
30 usage Print this short usage and command list
31 projects-stats|-ps Display statistics about your projects
32 cmplog Log 'tazwok cmp' result (or use tazbb)
33 update-wok Update Hg wok and copy it to the chroot wok
34 chroot Mount virtual fs if needed and chroot into the build env
35 gen-chroot Generate a chroot using the last cooking base rootfs
36 clean-chroot Clean a chroot environment (skip root/ and home/)
37 purge Remove obsolete packages and obsolete source tarballs
38 dry-purge Show obsolete packages and obsolete source tarballs
39 push|-p Upload new packages to the main mirror.
40 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
41 pull Download new packages from the main mirror.
42 dry-pull Show what will be downloaded from the mirror. Does nothing
43 relpkg|-rp Archive and upload new package/project version
44 reliso|-ri Create all main flavors (not loram)\n"
45 }
47 # Exit if user is not root.
48 check_root()
49 {
50 if test $(id -u) != 0 ; then
51 echo -e "\nThis program requires being run as root.\n"
52 exit 0
53 fi
54 }
56 status()
57 {
58 local CHECK=$?
59 echo -en "\033[70G"
60 if [ $CHECK = 0 ]; then
61 echo "Done"
62 else
63 echo "Failed"
64 fi
65 return $CHECK
66 }
68 get_version()
69 {
70 if [ "$2" = "stable" ]; then
71 VERSION=stable
72 SLITAZ=$STABLE
73 elif [ -n "$2" ]; then
74 # Undigest - custom ?
75 VERSION=$2
76 SLITAZ=/home/slitaz/$2
77 else
78 VERSION=cooking
79 SLITAZ=$COOKING
80 fi
81 ROOTFS=$SLITAZ/chroot
82 HG_WOK=$SLITAZ/wok
83 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok
84 }
86 check_mirror()
87 {
88 # ping -c 1 $MIRROR
89 if [ -n "$2" ]; then
90 USER=$2
91 else
92 USER=$USER
93 fi
94 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
95 REMOTE_DIR=$MIRROR_PKGS/stable/
96 LOCAL_DIR=$STABLE/packages/
97 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
98 REMOTE_DIR=$MIRROR_PKGS/undigest/
99 LOCAL_DIR=$UNDIGEST/packages/
100 else
101 REMOTE_DIR=$MIRROR_PKGS/cooking/
102 LOCAL_DIR=$COOKING/packages/
103 fi
104 }
106 # Mount virtual Kernel file systems and chroot but check that nobody
107 # else has done mounts
108 mount_chroot()
109 {
110 if [ ! -d $ROOTFS/proc/1 ]; then
111 echo -n "Mounting virtual filesystems..."
112 mount -t proc proc $ROOTFS/proc
113 mount -t sysfs sysfs $ROOTFS/sys
114 mount -t devpts devpts $ROOTFS/dev/pts
115 mount -t tmpfs shm $ROOTFS/dev/shm
116 status
117 fi
118 }
120 # Unmount virtual Kernel file systems on exit and ensure we are the last
121 # user before unmounting !
122 umount_chroot()
123 {
124 # Not working. Buggy ps ?
125 #sleep 6
126 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
127 if [ "$ps" == "1" ]; then
128 echo -ne "\Unmounting virtual filesystems..."
129 umount $ROOTFS/dev/shm
130 umount $ROOTFS/dev/pts
131 umount $ROOTFS/sys
132 umount $ROOTFS/proc
133 status
134 else
135 echo -e "\nProcess: $ps\n"
136 ps | grep `basename $0` | grep -v grep
137 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
138 fi
139 }
141 # Get the last cooking base rootfs, extract and configure.
142 gen_new_chroot()
143 {
144 echo -e "\nGenerating new chroot in : $ROOTFS"
145 echo "================================================================================"
146 mkdir -p $ROOTFS && cd $ROOTFS
147 wget $DL_URL/boot/cooking/rootfs-base.gz
148 echo -n "Extracting the rootfs..."
149 lzma d rootfs-base.gz -so | cpio -id
150 rm rootfs-base.gz
151 echo -n "Creating resolv.conf..."
152 cat /etc/resolv.conf > etc/resolv.conf
153 status
154 echo "================================================================================"
155 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
156 echo -e "Example: tazdev chroot $ROOTFS\n"
157 }
159 # Remove obsolate slitaz packages
160 purge_packages()
161 {
162 arg=$1
163 TMP_FILE=/tmp/tazdev.$$
164 ls $BUILD_WOK | while read pkg; do
165 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
166 EXTRAVERSION=""
167 . $BUILD_WOK/$pkg/taz/*/receipt
168 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
169 done > $TMP_FILE
170 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
171 case "$pkg" in
172 *.tazpkg)
173 grep -q ^$pkg$ $TMP_FILE && continue
174 echo Remove $pkg
175 [ "$arg" == "purge" ] &&
176 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
177 esac
178 done
179 rm -f $TMP_FILE
180 }
182 # Remove obsolate source tarballs
183 purge_sources()
184 {
185 arg=$1
186 TMP_FILE=/tmp/tazdev.$$
187 ls $BUILD_WOK | while read pkg; do
188 [ -f $BUILD_WOK/$pkg/receipt ] || continue
189 TARBALL=""
190 . $BUILD_WOK/$pkg/receipt
191 [ -n "$TARBALL" ] && echo $TARBALL
192 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
193 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
194 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
195 sed "s|['\"/]||g" | while read file ; do
196 eval echo $file 2> /dev/null
197 done
198 done > $TMP_FILE
199 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
200 grep -q ^$pkg$ $TMP_FILE && continue
201 echo Remove $pkg
202 [ "$arg" == "purge" ] &&
203 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
204 done
205 rm -f $TMP_FILE
206 }
208 case "$1" in
209 cmplog)
210 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
211 check_root
212 echo -e "Starting 'tazwok cmp' (can be long)...\n"
213 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
214 echo "Date: `date`" >> $CMP_LOG ;;
215 projects-stats|-ps)
216 echo -e "\nStatistics for: $PROJECTS\n"
217 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
218 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
219 echo "================================================================================"
220 cd $PROJECTS
221 for proj in *
222 do
223 rev=""
224 echo -n "$proj"
225 size=`du -sh $proj | awk '{ print $1 }'`
226 echo -ne "\033[24G $size"
227 if [ -d $proj/.hg ]; then
228 cd $proj
229 rev=`hg head --template '{rev}\n'`
230 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
231 echo -ne "\033[38G $rev"
232 echo -ne "\033[48G $vers" && cd ..
233 fi
234 files=`find $proj -type f | wc -l`
235 echo -e "\033[64G $files"
236 done
237 echo "================================================================================"
238 echo "" ;;
239 update-wok)
240 # Update the Hg wok and copy it to the chroot env. Hg wok is
241 # copied to the chroot wok to avoid messing with build result
242 # file and so we can also modify receipt directly without affecting
243 # the Hg wok.
244 check_root
245 get_version $@
246 echo ""
247 echo "Hg wok : $HG_WOK"
248 echo "Build wok : $BUILD_WOK"
249 cd $HG_WOK
250 hg pull && hg update
251 echo -n "Copying Hg wok to the build wok... "
252 cp -a $HG_WOK/* $BUILD_WOK
253 cp -a $HG_WOK/.hg $BUILD_WOK
254 status && 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 push|-p)
303 check_mirror $@
304 rsync -r -t -l -v -z --delete \
305 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
306 dry-push|-dp)
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|-rp)
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 reliso|-ri)
353 # Generate all official images iso at once.
354 version=$2
355 mkdir -p $ISO
356 for flavor in base core justx firefox
357 do
358 cd /home/slitaz/$version
359 tazlito pack-flavor $flavor
360 tazlito get-flavor $flavor
361 tazlito gen-distro
362 if [ "$flavor" == "core" ]; then
363 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
364 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
365 else
366 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
367 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
368 fi
369 done ;;
370 usage|*)
371 usage ;;
372 esac
374 exit 0