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

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