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

tazdev: Made tazdev use packages instead of rootfs-base.gz files.
author Christopher Rogers <slaxemulator@gmail.com>
date Fri May 06 16:53:43 2011 +0000 (2011-05-06)
parents bfce85497514
children 2940ea5fe229
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 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
14 [ -f $PWD/tazdev.conf ] && . $PWD/tazdev.conf
16 if [ -z "$SLITAZ" ]; then
17 echo -e "\nNo config file found\n" && exit 1
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|-ps Display statistics about your projects
27 update-wok Update Hg wok and copy it to the chroot wok
28 chroot Mount virtual fs if needed and chroot into the build env
29 gen-chroot|-gs Generate a chroot using the last cooking base rootfs
30 umount-chroot|-uc Unmount chroot specified on cmdline (--forced to force)
31 clean-chroot Clean a chroot environment (skip root/ and home/)
32 purge Remove obsolete packages and obsolete source tarballs
33 dry-purge Show obsolete packages and obsolete source tarballs
34 push|-p Upload new packages to the main mirror.
35 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
36 pull Download new packages from the main mirror.
37 dry-pull Show what will be downloaded from the mirror. Does nothing
38 relpkg|-rp Archive and upload new package/project version
39 reliso|-ri Create all main flavors (not loram)\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" ] || [ "$2" == "--forced" ]; then
123 [ "$1" ] && ROOTF=$1
124 echo -e "\nUnmounting virtual filesystems...\n"
125 umount $ROOTFS/dev/shm
126 umount $ROOTFS/dev/pts
127 umount $ROOTFS/sys
128 umount $ROOTFS/proc
129 echo ""
130 else
131 echo -e "\nProcess: $ps\n"
132 ps | grep `basename $0` | grep -v grep
133 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
134 fi
135 }
137 # Get the last cooking base rootfs, extract and configure.
138 gen_new_chroot()
139 {
140 echo -e "\nGenerating new chroot in : $ROOTFS"
141 echo "================================================================================"
142 mkdir -p $ROOTFS
143 for pkg in busybox libtaz tazwok tazchroot \
144 tazpkg slitaz-base-files
145 do
146 tazpkg get-install $pkg --root=$ROOTFS
147 done
148 echo -n "Creating resolv.conf..."
149 cat /etc/resolv.conf > $ROOTFS/etc/resolv.conf
150 status
151 echo "================================================================================"
152 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
153 echo -e "Example: tazdev chroot $ROOTFS\n"
154 }
156 # Remove obsolate slitaz packages
157 purge_packages()
158 {
159 arg=$1
160 TMP_FILE=/tmp/tazdev.$$
161 ls $BUILD_WOK | while read pkg; do
162 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
163 EXTRAVERSION=""
164 . $BUILD_WOK/$pkg/taz/*/receipt
165 echo $PACKAGE-$VERSION$EXTRAVERSION.tazpkg
166 done > $TMP_FILE
167 ls $SLITAZ/chroot/home/slitaz/packages | while read pkg; do
168 case "$pkg" in
169 *.tazpkg)
170 grep -q ^$pkg$ $TMP_FILE && continue
171 echo Remove $pkg
172 [ "$arg" == "purge" ] &&
173 rm -f $SLITAZ/chroot/home/slitaz/packages/$pkg ;;
174 esac
175 done
176 rm -f $TMP_FILE
177 }
179 # Remove obsolate source tarballs
180 purge_sources()
181 {
182 arg=$1
183 TMP_FILE=/tmp/tazdev.$$
184 ls $BUILD_WOK | while read pkg; do
185 [ -f $BUILD_WOK/$pkg/receipt ] || continue
186 TARBALL=""
187 . $BUILD_WOK/$pkg/receipt
188 [ -n "$TARBALL" ] && echo $TARBALL
189 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
190 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
191 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
192 sed "s|['\"/]||g" | while read file ; do
193 eval echo $file 2> /dev/null
194 done
195 done > $TMP_FILE
196 ls $SLITAZ/chroot/home/slitaz/src | while read pkg; do
197 grep -q ^$pkg$ $TMP_FILE && continue
198 echo Remove $pkg
199 [ "$arg" == "purge" ] &&
200 rm -f $SLITAZ/chroot/home/slitaz/src/$pkg
201 done
202 rm -f $TMP_FILE
203 }
205 case "$1" in
206 projects-stats|-ps)
207 echo -e "\nStatistics for: $PROJECTS\n"
208 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
209 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
210 echo "================================================================================"
211 cd $PROJECTS
212 for proj in *
213 do
214 rev=""
215 echo -n "$proj"
216 size=`du -sh $proj | awk '{ print $1 }'`
217 echo -ne "\033[24G $size"
218 if [ -d $proj/.hg ]; then
219 cd $proj
220 rev=`hg head --template '{rev}\n'`
221 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
222 echo -ne "\033[38G $rev"
223 echo -ne "\033[48G $vers" && cd ..
224 fi
225 files=`find $proj -type f | wc -l`
226 echo -e "\033[64G $files"
227 done
228 echo "================================================================================"
229 echo "" ;;
230 update-wok)
231 # Update the Hg wok and copy it to the chroot env. Hg wok is
232 # copied to the chroot wok to avoid messing with build result
233 # file and so we can also modify receipt directly without affecting
234 # the Hg wok.
235 check_root
236 get_version $@
237 echo ""
238 echo "Hg wok : $HG_WOK"
239 echo "Build wok : $BUILD_WOK"
240 cd $HG_WOK
241 hg pull && hg update
242 echo -n "Copying Hg wok to the build wok... "
243 cp -a $HG_WOK/* $BUILD_WOK
244 cp -a $HG_WOK/.hg $BUILD_WOK
245 status && echo "" ;;
246 chroot)
247 # Chroot into a build env. Default to cooking configured in
248 # tazdev.conf
249 check_root
250 get_version $@
251 [ -d "$2" ] && ROOTFS=$2
252 mount_chroot
253 echo -e "\nChrooting in $ROOTFS...\n"
254 chroot $ROOTFS /bin/sh --login
255 umount_chroot
256 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
257 umount-chroot|-uc)
258 check_root
259 [ "$2" ] && ROOTFS=$2
260 [ "$3" ] && opt=$3
261 umount_chroot $ROOTFS $opt ;;
262 gen-chroot|-gc)
263 check_root
264 get_version $@
265 [ -d "$2" ] && ROOTFS=$2
266 # Dont break another env.
267 if [ -d $ROOTFS/bin ]; then
268 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
269 exit 1
270 fi
271 gen_new_chroot ;;
272 clean-chroot)
273 # Keep root/ and /home they may have a build wok, custom scripts, etc.
274 check_root
275 if [ -z "$2" ]; then
276 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
277 exit 0
278 else
279 ROOTFS=$2
280 if [ ! -d "$ROOTFS" ]; then
281 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
282 exit 1
283 fi
284 fi
285 if [ -d $ROOTFS/proc/1 ]; then
286 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
287 exit 1
288 fi
289 cd $ROOTFS || exit 1
290 echo -e "\nCleaning chroot in: $ROOTFS"
291 echo "================================================================================"
292 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
293 do
294 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
295 rm -rf $i
296 status
297 done
298 echo "================================================================================"
299 echo "" ;;
300 push|-p)
301 check_mirror $@
302 rsync -r -t -l -v -z --delete \
303 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
304 dry-push|-dp)
305 check_mirror $@
306 rsync -r -t -l -v -z --delete --dry-run \
307 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
308 pull)
309 check_mirror $@
310 rsync -r -t -l -v -z --delete \
311 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
312 dry-pull)
313 check_mirror $@
314 rsync -r -t -l -v -z --delete --dry-run \
315 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
316 purge|dry-purge)
317 check_root
318 get_version $@
319 purge_packages $1
320 purge_sources $1 ;;
321 relpkg|-rp)
322 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
323 if [ -z $2 ] || [ -z $3 ]; then
324 echo -e "\nUsage: $0 relpkg package version\n"
325 exit 0
326 fi
327 PACKAGE=$2
328 VERSION=$3
329 echo ""
330 cd $PROJECTS/$PACKAGE
331 # Sanity check
332 if ! grep -q $VERSION$ .hgtags; then
333 echo "Missing Hg tag for version: $VERSION"
334 echo -e "You may want to: hg tag $VERSION && hg push\n"
335 exit 0
336 fi
337 # Archive
338 echo -n "Creating tarball and md5sum for: $PACKAGE-$VERSION... "
339 hg archive -t tgz $PACKAGE-$VERSION.tar.gz
340 md5sum $PACKAGE-$VERSION.tar.gz > $PACKAGE-$VERSION.md5
341 echo "Done"
342 # Upload
343 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
344 read upload
345 if [ "$upload" = "y" ]; then
346 echo "Uploading to: $MIRROR/sources/${PACKAGE#slitaz-}"
347 scp $PACKAGE-$VERSION.tar.gz $PACKAGE-$VERSION.md5 \
348 $USER@$MIRROR:$MIRROR_SOURCES/${PACKAGE#slitaz-}
349 fi ;;
350 reliso|-ri)
351 # Generate all official images iso at once.
352 version=$2
353 mkdir -p $ISO
354 for flavor in base core justx firefox
355 do
356 cd /home/slitaz/$version
357 tazlito pack-flavor $flavor
358 tazlito get-flavor $flavor
359 tazlito gen-distro
360 if [ "$flavor" == "core" ]; then
361 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
362 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
363 else
364 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
365 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
366 fi
367 done ;;
368 usage|*)
369 usage ;;
370 esac
372 exit 0