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

Add help command to tazdev
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 24 00:07:57 2012 +0200 (2012-04-24)
parents 116c7b18fea2
children cab409f94b91
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 variables are $UPPERCASE
6 # and variables initialized by tazdev itself are $lowerspace
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 #
14 . /lib/libtaz.sh
16 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
17 [ -f tazdev.conf ] && . ./tazdev.conf
19 if [ -z "$SLITAZ_HOME" ]; then
20 echo -e "\nNo config file found\n" && exit 1
21 fi
23 usage()
24 {
25 echo -e "\nSliTaz developers and build host tool\n
26 $(boldify "Usage:") $(basename $0) [command] [user|tool] [release|path]
27 $(boldify "Commands:")
28 usage Print this short usage and command list
29 help Give help on a SliTaz tool or library.
30 projects-stats|-ps Display statistics about your projects
31 chroot Mount virtual fs if needed and chroot into the build env
32 gen-chroot|-gs Generate a chroot using the last cooking base rootfs
33 umount-chroot|-uc Unmount chroot specified on cmdline (--forced to force)
34 clean-chroot Clean a chroot environment (skip root/ and home/)
35 purge Remove obsolete packages and obsolete source tarballs
36 dry-purge Show obsolete packages and obsolete source tarballs
37 push|-p Upload new packages to the main mirror
38 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
39 pull Download new packages from the main mirror
40 dry-pull Show what will be downloaded from the mirror. Does nothing
41 pack-flavors Pack all SliTaz Live flavors at once
42 relpkg|-rp Archive and upload new package/project version
43 reliso|-ri Create all main flavors (not loram)\n"
44 }
46 get_version()
47 {
48 if [ "$2" = "stable" ]; then
49 version=stable
50 slitaz=$STABLE
51 elif [ -n "$2" ]; then
52 # Undigest - custom ?
53 version=$2
54 slitaz=$SLITAZ_HOME/$2
55 else
56 version=cooking
57 slitaz=$COOKING
58 fi
59 rootfs=$slitaz/chroot
60 }
62 check_mirror()
63 {
64 # ping -c 1 $MIRROR
65 if [ -n "$2" ]; then
66 user=$2
67 else
68 user=$user
69 fi
70 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
71 remote=$MIRROR_PKGS/stable/
72 local=$STABLE/packages/
73 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
74 remote=$MIRROR_PKGS/undigest/
75 local=$UNDIGEST/packages/
76 else
77 remote=$MIRROR_PKGS/cooking/
78 local=$COOKING/packages/
79 fi
80 }
82 # Bind a directory into the chroot
83 bind_chroot_dir()
84 {
85 mkdir -p $1 $2
86 mount -o bind $1 $2
88 # Update aufs jail configuration
89 # BUGGY
90 #if [ "${2#*/home}" != "$2" ] &&
91 #grep -s ^AUFS_MOUNTS= ${2%/home/*}/etc/slitaz/cook.conf &&
92 #! grep -q /home${2#*/home} ${2%/home/*}/etc/slitaz/cook.conf; then
93 #sed -i "s|^AUFS_MOUNTS=\"|&/home${2#*/home}|" \
94 #${2%/home/*}/etc/slitaz/cook.conf
95 #fi
96 }
98 # Mount virtual Kernel file systems and chroot but check that nobody
99 # else has done mounts
100 mount_chroot()
101 {
102 if [ ! -d $rootfs/proc/1 ]; then
103 echo -ne "\nMounting virtual filesystems..."
104 mount -t proc proc $rootfs/proc
105 mount -t sysfs sysfs $rootfs/sys
106 mount -t devpts devpts $rootfs/dev/pts
107 mount -t tmpfs shm $rootfs/dev/shm
108 status
109 fi
110 # Mount source so they can be shared between cooking/stable/undigest.
111 # But do it only if it's a slitaz developement chroot.
112 fs=$rootfs/home/slitaz
113 if [ -d "$slitaz" ]; then
114 bind_chroot_dir $SLITAZ_HOME/src $fs/src
115 # Now mount package dir so they are in /home/slitaz/$version
116 # We may not mount cache wok or others it has no point and if
117 # one wants to use a shared wok he can bind it manually.
118 bind_chroot_dir $slitaz/packages $fs/packages
119 fi
120 }
122 # Unmount virtual Kernel file systems on exit and ensure we are the last
123 # user before unmounting !
124 umount_chroot()
125 {
126 [ "$1" ] && ROOTF=$1
127 fs=$rootfs/home/slitaz
128 echo -ne "\nUnmounting virtual filesystems..."
129 umount $rootfs/dev/shm
130 umount $rootfs/dev/pts
131 umount $rootfs/sys
132 umount $rootfs/proc
133 umount $fs/src
134 umount $fs/packages
135 status && echo ""
136 #echo -e "\nProcess: $ps\n"
137 #ps | grep `basename $0` | grep -v grep
138 #echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
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 separator
146 mkdir -p $rootfs
147 if [ "$ROOTFS_PKG" == "yes" ]; then
148 for pkg in $CHROOT_PKGS
149 do
150 tazpkg get-install $pkg --root=$rootfs
151 done
152 elif [ "$ROOTFS_PKG" == "no" ]; then
153 cd $rootfs
154 wget $DL_URL/boot/cooking/rootfs-base.gz
155 echo -n "Extracting the rootfs..."
156 lzma d rootfs-base.gz -so | cpio -id
157 rm rootfs-base.gz
158 fi
159 echo -n "Creating resolv.conf..."
160 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
161 status
162 separator
163 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
164 echo -e "Example: tazdev chroot $rootfs\n"
165 }
167 # Remove obsolate slitaz packages
168 purge_packages()
169 {
170 arg=$1
171 tmp=/tmp/tazdev.$$
172 ls $BUILD_WOK | while read pkg; do
173 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
174 EXTRAversion=""
175 . $BUILD_WOK/$pkg/taz/*/receipt
176 echo $pkg-$version$EXTRAversion.tazpkg
177 done > $tmp
178 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
179 case "$pkg" in
180 *.tazpkg)
181 grep -q ^$pkg$ $tmp && continue
182 echo Remove $pkg
183 [ "$arg" == "purge" ] &&
184 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
185 esac
186 done
187 rm -f $tmp
188 }
190 # Remove obsolete source tarballs
191 purge_sources()
192 {
193 arg=$1
194 tmp=/tmp/tazdev.$$
195 ls $BUILD_WOK | while read pkg; do
196 [ -f $BUILD_WOK/$pkg/receipt ] || continue
197 TARBALL=""
198 . $BUILD_WOK/$pkg/receipt
199 [ -n "$TARBALL" ] && echo $TARBALL
200 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
201 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
202 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
203 sed "s|['\"/]||g" | while read file ; do
204 eval echo $file 2> /dev/null
205 done
206 done > $tmp
207 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
208 grep -q ^$pkg$ $tmp && continue
209 echo Remove $pkg
210 [ "$arg" == "purge" ] &&
211 rm -f $slitaz/chroot/home/slitaz/src/$pkg
212 done
213 rm -f $tmp
214 }
216 case "$1" in
217 projects-stats|-ps)
218 echo -e "\nStatistics for: $PROJECTS\n"
219 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
220 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
221 separator
222 cd $PROJECTS
223 for proj in *
224 do
225 rev=""
226 echo -n "$proj"
227 size=`du -sh $proj | awk '{ print $1 }'`
228 echo -ne "\033[24G $size"
229 if [ -d $proj/.hg ]; then
230 cd $proj
231 rev=`hg head --template '{rev}\n'`
232 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
233 echo -ne "\033[38G $rev"
234 echo -ne "\033[48G $vers" && cd ..
235 fi
236 files=`find $proj -type f | wc -l`
237 echo -e "\033[64G $files"
238 done
239 separator
240 echo "" ;;
241 chroot)
242 # Chroot into a build env. Default to cooking configured in tazdev.conf
243 check_root
244 get_version $@
245 [ -d "$2" ] && rootfs=$2
246 mount_chroot
247 echo -e "Chrooting to: $rootfs\n"
248 chroot $rootfs /bin/sh --login
249 umount_chroot ;;
250 umount-chroot|-uc)
251 check_root
252 get_version $@
253 [ "$2" ] && rootfs=$2
254 umount_chroot $rootfs ;;
255 gen-chroot|-gc)
256 check_root
257 get_version $@
258 [ -d "$2" ] && rootfs=$2
259 # Dont break another env.
260 if [ -d $rootfs/bin ]; then
261 echo -e "\nA chroot environment already exists in : $rootfs\n"
262 exit 1
263 fi
264 gen_new_chroot ;;
265 clean-chroot)
266 # Keep root/ and /home they may have a build wok, custom scripts, etc.
267 check_root
268 if [ -z "$2" ]; then
269 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
270 exit 0
271 else
272 rootfs=$2
273 if [ ! -d "$rootfs" ]; then
274 echo -e "\nWarning : $rootfs doesn't exist!\n"
275 exit 1
276 fi
277 fi
278 if [ -d $rootfs/proc/1 ]; then
279 echo -e "\nWarning : $rootfs/proc mounted!\n"
280 exit 1
281 fi
282 cd $rootfs || exit 1
283 echo -e "\nCleaning chroot in: $rootfs"
284 separator
285 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
286 do
287 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
288 rm -rf $i
289 status
290 done
291 separator && echo "" ;;
292 push|-p)
293 check_mirror $@
294 rsync -r -t -O -l -v -z --delete \
295 $local -e ssh $user@$MIRROR:$remote ;;
296 dry-push|-dp)
297 check_mirror $@
298 rsync -r -t -O -l -v -z --delete --dry-run \
299 $local -e ssh $user@$MIRROR:$remote ;;
300 pull)
301 check_mirror $@
302 rsync -r -t -l -v -z --delete \
303 -e ssh $user@$MIRROR:$remote $local ;;
304 dry-pull)
305 check_mirror $@
306 rsync -r -t -l -v -z --delete --dry-run \
307 -e ssh $user@$MIRROR:$remote $local ;;
308 purge|dry-purge)
309 check_root
310 get_version $@
311 purge_packages $1
312 purge_sources $1 ;;
313 relpkg|-rp)
314 # Release a slitaz sub-project and upload tarball to mirror
315 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
316 if [ -z $2 ] || [ -z $3 ]; then
317 echo -e "\nUsage: $0 relpkg package version\n"
318 exit 0
319 fi
320 pkg=$2
321 version=$3
322 echo "" && cd $PROJECTS/$pkg
324 # Sanity check
325 if ! grep -q $version$ .hgtags; then
326 echo "Missing Hg tag for version: $version"
327 echo -e "You may want to: hg tag $version && hg push\n"
328 exit 0
329 fi
331 # Archive
332 echo -n "Creating tarball and md5sum for: $pkg-$version... "
333 hg archive -t tgz $pkg-$version.tar.gz
334 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
335 echo "Done"
337 # Upload
338 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
339 read upload
340 if [ "$upload" = "y" ]; then
341 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
342 scp $pkg-$version.tar.gz $pkg-$version.md5 \
343 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
344 fi
346 # Update pkg in wok
347 echo -n "Do you wish to update $pkg in wok [N/y] ? "
348 read update
349 if [ "$update" = "y" ]; then
350 echo "Updating $pkg: $version"
351 cd $PROJECTS/wok
352 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
353 status
354 fi ;;
355 reliso|-ri)
356 # Generate all official images iso at once for a specific version.
357 get_version $@
358 iso=$slitaz/iso
359 mkdir -p $iso
360 for flavor in base core gtkonly firefox
361 do
362 cd $slitaz
363 tazlito pack-flavor $flavor
364 tazlito get-flavor $flavor
365 tazlito gen-distro
366 if [ "$flavor" == "core" ]; then
367 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
368 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
369 else
370 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
371 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
372 fi
373 done
374 # Clean up slitaz working directory.
375 rm *.flavor tazlito.conf ;;
376 help)
377 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
378 echo ""
379 boldify "Help for: $2"
380 separator
381 case $2 in
382 libtaz.sh) libtaz ;;
383 httphelper.sh)
384 . /usr/lib/slitaz/httphelper.sh
385 httphelper ;;
386 *) echo "No help found" ;;
387 esac
388 separator && echo "" ;;
389 usage|*)
390 usage ;;
391 esac
393 exit 0