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

tazdev: small clean and fixes
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 07 00:34:28 2011 +0200 (2011-05-07)
parents 03279ff7b32b
children 6aa7281d0969
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. Keep the code clear and
5 # well commented please, also: configuration variablea are $UPERCASE
6 # and variables initialized by tazdev itself are $lowersace
7 #
8 # (c) 2011 SliTaz GNU/Linux - GNU gpl v3
9 #
10 # AUTHORS
11 # Christophe Lincoln <pankso@slitaz.org>
12 # Pascal Bellard <bellard@slitaz.org>
13 #
15 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
16 [ -f tazdev.conf ] && . ./tazdev.conf
18 if [ -z "$SLITAZ" ]; then
19 echo -e "\nNo config file found\n" && exit 1
20 fi
22 usage()
23 {
24 echo -e "\nSliTaz developers and build host tool\n
25 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|undigest|path]
26 \033[1mCommands: \033[0m\n
27 usage Print this short usage and command list
28 projects-stats|-ps Display statistics about your projects
29 chroot Mount virtual fs if needed and chroot into the build env
30 gen-chroot|-gs Generate a chroot using the last cooking base rootfs
31 umount-chroot|-uc Unmount chroot specified on cmdline (--forced to force)
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|-p Upload new packages to the main mirror.
36 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
37 pull Download new packages from the main mirror.
38 dry-pull Show what will be downloaded from the mirror. Does nothing
39 relpkg|-rp Archive and upload new package/project version
40 reliso|-ri Create all main flavors (not loram)\n"
41 }
43 # Be sure we root.
44 check_root() {
45 [ $(id -u) != 0 ] && \
46 echo -e "\nYou must be root to use: $(basename $0) $@\n" && exit 0
47 }
49 separator() {
50 echo "================================================================================"
51 }
53 status() {
54 echo -en "\\033[70G[ "
55 if [ $? = 0 ]; then
56 echo -en "\\033[1;32mOK"
57 else
58 echo -en "\\033[1;31mFailed"
59 fi
60 echo -e "\\033[0;39m ]"
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=$SLITAZ/$2
72 else
73 version=cooking
74 slitaz=$COOKING
75 fi
76 rootfs=$slitaz/chroot
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=$MIRROR_PKGS/stable/
89 local=$STABLE/packages/
90 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
91 remote=$MIRROR_PKGS/undigest/
92 local=$UNDIGEST/packages/
93 else
94 remote=$MIRROR_PKGS/cooking/
95 local=$COOKING/packages/
96 fi
97 }
99 # Mount virtual Kernel file systems and chroot but check that nobody
100 # else has done mounts
101 mount_chroot()
102 {
103 if [ ! -d $rootfs/proc/1 ]; then
104 echo -ne "\nMounting virtual filesystems..."
105 mount -t proc proc $rootfs/proc
106 mount -t sysfs sysfs $rootfs/sys
107 mount -t devpts devpts $rootfs/dev/pts
108 mount -t tmpfs shm $rootfs/dev/shm
109 status
110 fi
111 # Mount source so they can be shared between cooking/stable/undigest.
112 # But do it only if it's a slitaz developement chroot.
113 fs=$rootfs/home/slitaz
114 if [ -d "$slitaz" ]; then
115 mkdir -p $slitaz/src $fs/src
116 mount -o bind $slitaz/src $fs/src
117 # Now mount package dir so they are in /home/slitaz/$version
118 # We may not mount cache wok or others it has no point and if
119 # one want to use a shared wok he can bind it manually.
120 mkdir -p $slitaz/$version/packages $fs/packages
121 mount -o bind $slitaz/$version/packages $fs/packages
122 fi
123 }
125 # Unmount virtual Kernel file systems on exit and ensure we are the last
126 # user before unmounting !
127 umount_chroot()
128 {
129 [ "$1" ] && ROOTF=$1
130 fs=$rootfs/home/slitaz
131 echo -ne "\nUnmounting virtual filesystems..."
132 umount $rootfs/dev/shm
133 umount $rootfs/dev/pts
134 umount $rootfs/sys
135 umount $rootfs/proc
136 umount $fs/src
137 umount $fs/packages
138 status && echo ""
139 #echo -e "\nProcess: $ps\n"
140 #ps | grep `basename $0` | grep -v grep
141 #echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
142 }
144 # Get the last cooking base rootfs, extract and configure.
145 gen_new_chroot()
146 {
147 echo -e "\nGenerating new chroot in : $rootfs"
148 separator
149 mkdir -p $rootfs
150 for pkg in busybox libtaz tazwok tazchroot \
151 tazpkg slitaz-base-files
152 do
153 tazpkg get-install $pkg --root=$rootfs
154 done
155 echo -n "Creating resolv.conf..."
156 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
157 status
158 separator
159 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
160 echo -e "Example: tazdev chroot $rootfs\n"
161 }
163 # Remove obsolate slitaz packages
164 purge_packages()
165 {
166 arg=$1
167 tmp=/tmp/tazdev.$$
168 ls $BUILD_WOK | while read pkg; do
169 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
170 EXTRAversion=""
171 . $BUILD_WOK/$pkg/taz/*/receipt
172 echo $pkg-$version$EXTRAversion.tazpkg
173 done > $tmp
174 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
175 case "$pkg" in
176 *.tazpkg)
177 grep -q ^$pkg$ $tmp && continue
178 echo Remove $pkg
179 [ "$arg" == "purge" ] &&
180 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
181 esac
182 done
183 rm -f $tmp
184 }
186 # Remove obsolate source tarballs
187 purge_sources()
188 {
189 arg=$1
190 tmp=/tmp/tazdev.$$
191 ls $BUILD_WOK | while read pkg; do
192 [ -f $BUILD_WOK/$pkg/receipt ] || continue
193 TARBALL=""
194 . $BUILD_WOK/$pkg/receipt
195 [ -n "$TARBALL" ] && echo $TARBALL
196 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
197 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
198 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
199 sed "s|['\"/]||g" | while read file ; do
200 eval echo $file 2> /dev/null
201 done
202 done > $tmp
203 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
204 grep -q ^$pkg$ $tmp && continue
205 echo Remove $pkg
206 [ "$arg" == "purge" ] &&
207 rm -f $slitaz/chroot/home/slitaz/src/$pkg
208 done
209 rm -f $tmp
210 }
212 case "$1" in
213 projects-stats|-ps)
214 echo -e "\nStatistics for: $PROJECTS\n"
215 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
216 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
217 separator
218 cd $PROJECTS
219 for proj in *
220 do
221 rev=""
222 echo -n "$proj"
223 size=`du -sh $proj | awk '{ print $1 }'`
224 echo -ne "\033[24G $size"
225 if [ -d $proj/.hg ]; then
226 cd $proj
227 rev=`hg head --template '{rev}\n'`
228 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
229 echo -ne "\033[38G $rev"
230 echo -ne "\033[48G $vers" && cd ..
231 fi
232 files=`find $proj -type f | wc -l`
233 echo -e "\033[64G $files"
234 done
235 separator
236 echo "" ;;
237 chroot)
238 # Chroot into a build env. Default to cooking configured in tazdev.conf
239 check_root
240 get_version $@
241 [ -d "$2" ] && rootfs=$2
242 mount_chroot
243 echo -e "Chrooting to: $rootfs\n"
244 chroot $rootfs /bin/sh --login
245 umount_chroot ;;
246 umount-chroot|-uc)
247 check_root
248 get_version $@
249 [ "$2" ] && rootfs=$2
250 umount_chroot $rootfs ;;
251 gen-chroot|-gc)
252 check_root
253 get_version $@
254 [ -d "$2" ] && rootfs=$2
255 # Dont break another env.
256 if [ -d $rootfs/bin ]; then
257 echo -e "\nA chroot environment already exists in : $rootfs\n"
258 exit 1
259 fi
260 gen_new_chroot ;;
261 clean-chroot)
262 # Keep root/ and /home they may have a build wok, custom scripts, etc.
263 check_root
264 if [ -z "$2" ]; then
265 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
266 exit 0
267 else
268 rootfs=$2
269 if [ ! -d "$rootfs" ]; then
270 echo -e "\nWarning : $rootfs doesn't exist!\n"
271 exit 1
272 fi
273 fi
274 if [ -d $rootfs/proc/1 ]; then
275 echo -e "\nWarning : $rootfs/proc mounted!\n"
276 exit 1
277 fi
278 cd $rootfs || exit 1
279 echo -e "\nCleaning chroot in: $rootfs"
280 separator
281 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
282 do
283 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
284 rm -rf $i
285 status
286 done
287 separator && echo "" ;;
288 push|-p)
289 check_mirror $@
290 rsync -r -t -l -v -z --delete \
291 $local -e ssh $user@$MIRROR:$remote ;;
292 dry-push|-dp)
293 check_mirror $@
294 rsync -r -t -l -v -z --delete --dry-run \
295 $local -e ssh $user@$MIRROR:$remote ;;
296 pull)
297 check_mirror $@
298 rsync -r -t -l -v -z --delete \
299 -e ssh $user@$MIRROR:$remote $local ;;
300 dry-pull)
301 check_mirror $@
302 rsync -r -t -l -v -z --delete --dry-run \
303 -e ssh $user@$MIRROR:$remote $local ;;
304 purge|dry-purge)
305 check_root
306 get_version $@
307 purge_packages $1
308 purge_sources $1 ;;
309 relpkg|-rp)
310 # Release a slitaz sub-project and upload tarball to mirror
311 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
312 if [ -z $2 ] || [ -z $3 ]; then
313 echo -e "\nUsage: $0 relpkg package version\n"
314 exit 0
315 fi
316 pkg=$2
317 version=$3
318 echo "" && cd $PROJECTS/$pkg
320 # Sanity check
321 if ! grep -q $version$ .hgtags; then
322 echo "Missing Hg tag for version: $version"
323 echo -e "You may want to: hg tag $version && hg push\n"
324 exit 0
325 fi
327 # Archive
328 echo -n "Creating tarball and md5sum for: $pkg-$version... "
329 hg archive -t tgz $pkg-$version.tar.gz
330 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
331 echo "Done"
333 # Upload
334 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
335 read upload
336 if [ "$upload" = "y" ]; then
337 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
338 scp $pkg-$version.tar.gz $pkg-$version.md5 \
339 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
340 fi ;;
341 reliso|-ri)
342 # Generate all official images iso at once for a specific version.
343 get_version $@
344 iso=$slitaz/iso
345 mkdir -p $iso
346 for flavor in base core justx firefox
347 do
348 cd $slitaz
349 tazlito pack-flavor $flavor
350 tazlito get-flavor $flavor
351 tazlito gen-distro
352 if [ "$flavor" == "core" ]; then
353 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
354 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
355 else
356 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
357 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
358 fi
359 done
360 # Clean up slitaz working directory.
361 rm *.flavor tazlito.conf ;;
362 usage|*)
363 usage ;;
364 esac
366 exit 0