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

tazdev: handle --arch= for chroot, fixes and clean up
author Christophe Lincoln <pankso@slitaz.org>
date Sat May 05 02:33:39 2012 +0200 (2012-05-05)
parents 41cb24a627b0
children 227a8a6ba4d7
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 echo -e "\nSliTaz developers and build host tool\n
25 $(boldify "Usage:") $(basename $0) [command] [user|tool] [release|path]
26 $(boldify "Commands:")
27 usage Print this short usage and command list
28 help Give help on a SliTaz tool or library.
29 projects-stats|-ps Display statistics about your projects
30 chroot|-c Mount virtual fs if needed and chroot into the build env
31 gen-chroot|-gc Generate a chroot using packages from config file
32 umount-chroot|-uc Unmount chroot specified on cmdline
33 clean-chroot Clean a chroot environment (skip root/ and home/)
34 purge Remove obsolete packages and obsolete source tarballs
35 dry-purge Show obsolete packages and obsolete source tarballs
36 push|-p Upload new packages to the main mirror
37 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
38 pull Download new packages from the main mirror
39 dry-pull Show what will be downloaded from the mirror. Does nothing
40 relpkg|-rp Archive and upload new package/project version\n"
41 }
43 get_version() {
44 # Stable, undigest or custom.
45 if [ "$2" ] && [ ! $(echo $2 | grep "\--*") ]; then
46 version=$2
47 slitaz=$SLITAZ_HOME/$2
48 else
49 version=cooking
50 slitaz=$COOKING
51 fi
52 if [ "$arch" ]; then
53 rootfs=$slitaz/$arch/chroot
54 else
55 rootfs=$slitaz/chroot
56 fi
57 }
59 check_mirror() {
60 # ping -c 1 $MIRROR
61 if [ -n "$2" ]; then
62 user=$2
63 else
64 user=$user
65 fi
66 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
67 remote=$MIRROR_PKGS/stable/
68 local=$STABLE/packages/
69 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
70 remote=$MIRROR_PKGS/undigest/
71 local=$UNDIGEST/packages/
72 else
73 remote=$MIRROR_PKGS/cooking/
74 local=$COOKING/packages/
75 fi
76 }
78 # Bind a directory into the chroot
79 bind_chroot_dir()
80 {
81 mkdir -p $1 $2
82 mount -o bind $1 $2
83 }
85 # Mount virtual Kernel file systems and chroot but check that nobody
86 # else has done mounts
87 mount_chroot()
88 {
89 if [ ! -d $rootfs/proc/1 ]; then
90 echo -ne "\nMounting virtual filesystems..."
91 mount -t proc proc $rootfs/proc
92 mount -t sysfs sysfs $rootfs/sys
93 mount -t devpts devpts $rootfs/dev/pts
94 mount -t tmpfs shm $rootfs/dev/shm
95 status
96 fi
97 # Mount source so they can be shared between cooking/stable/undigest.
98 # But do it only if it's a slitaz developement chroot.
99 fs=$rootfs/home/slitaz
100 if [ -d "$slitaz" ]; then
101 bind_chroot_dir $SLITAZ_HOME/src $fs/src
102 # Now mount package dir so they are in /home/slitaz/$version
103 # We may not mount cache wok or others it has no point and if
104 # one wants to use a shared wok he can bind it manually.
105 bind_chroot_dir $slitaz/packages $fs/packages
106 fi
107 }
109 # Unmount virtual Kernel file systems.
110 umount_chroot() {
111 [ "$1" ] && rootfs=$1
112 fs=$rootfs/home/slitaz
113 echo -ne "\nUnmounting virtual filesystems..."
114 umount $rootfs/dev/shm
115 umount $rootfs/dev/pts
116 umount $rootfs/sys
117 umount $rootfs/proc
118 if mount | fgrep -q $fs/src; then
119 umount $fs/src
120 umount $fs/packages
121 fi
122 status && echo ""
123 }
125 # Get the last cooking base rootfs, extract and configure.
126 gen_chroot() {
127 echo -e "\nGenerating new chroot in: $rootfs"
128 separator
129 mkdir -p $rootfs
130 for pkg in $CHROOT_PKGS
131 do
132 tazpkg get-install $pkg --root=$rootfs
133 done
134 echo -n "Creating resolv.conf..."
135 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
136 status
137 separator
138 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
139 echo -e "Example: tazdev chroot $rootfs\n"
140 }
142 # Remove obsolate slitaz packages
143 purge_packages() {
144 arg=$1
145 tmp=/tmp/tazdev.$$
146 ls $wok| while read pkg; do
147 [ -f $wok/$pkg/taz/*/receipt ] || continue
148 unset VERSION EXTRAVERSION
149 . $wok/$pkg/taz/*/receipt
150 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
151 done > $tmp
152 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
153 case "$pkg" in
154 *.tazpkg)
155 grep -q ^$pkg$ $tmp && continue
156 echo "Removing pkg: $pkg"
157 [ "$arg" == "purge" ] &&
158 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
159 esac
160 done
161 rm -f $tmp
162 }
164 # Remove obsolete source tarballs
165 purge_sources() {
166 arg=$1
167 wok=$slitaz/chroot/home/slitaz/wok
168 tmp=/tmp/tazdev.$$
169 ls $wok| while read pkg; do
170 [ -f $wok/$pkg/receipt ] || continue
171 TARBALL=""
172 . $wok/$pkg/receipt
173 [ -n "$TARBALL" ] && echo $TARBALL
174 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
175 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
176 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
177 sed "s|['\"/]||g" | while read file ; do
178 eval echo $file 2> /dev/null
179 done
180 done > $tmp
181 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
182 grep -q ^$pkg$ $tmp && continue
183 echo "Removing src: $pkg"
184 [ "$arg" == "purge" ] &&
185 rm -f $slitaz/chroot/home/slitaz/src/$pkg
186 done
187 rm -f $tmp
188 }
190 case "$1" in
191 info)
192 get_version $@
193 echo ""
194 echo "Version: $version"
195 [ "$arch" ] && echo "Arch : $arch"
196 echo "Chroot : $rootfs"
197 echo "" ;;
198 projects-stats|-ps)
199 echo -e "\nStatistics for: $PROJECTS\n"
200 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
201 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
202 separator
203 cd $PROJECTS
204 for proj in *
205 do
206 rev=""
207 echo -n "$proj"
208 size=`du -sh $proj | awk '{ print $1 }'`
209 echo -ne "\033[24G $size"
210 if [ -d $proj/.hg ]; then
211 cd $proj
212 rev=`hg head --template '{rev}\n'`
213 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
214 echo -ne "\033[38G $rev"
215 echo -ne "\033[48G $vers" && cd ..
216 fi
217 files=`find $proj -type f | wc -l`
218 echo -e "\033[64G $files"
219 done
220 separator
221 echo "" ;;
222 chroot|-c)
223 # Chroot into a build env. Default to cooking configured in tazdev.conf
224 check_root
225 get_version $@
226 [ -d "$2" ] && rootfs=$2
227 mount_chroot
228 echo -e "Chrooting to: $rootfs\n"
229 chroot $rootfs /bin/sh --login
230 umount_chroot ;;
231 umount-chroot|-uc)
232 check_root
233 get_version $@
234 [ "$2" ] && rootfs=$2
235 umount_chroot $rootfs ;;
236 gen-chroot|-gc)
237 check_root
238 # We can use: --rootfs=/path/to/chroot
239 if [ "$rootfs" ]; then
240 continue
241 else
242 get_version $@
243 fi
244 # Dont break another env.
245 if [ -d $rootfs/bin ]; then
246 echo -e "\nA chroot environment already exists in : $rootfs\n"
247 exit 1
248 fi
249 gen_chroot ;;
250 clean-chroot)
251 # Keep root/ and /home they may have a build wok, custom scripts, etc.
252 check_root
253 if [ -z "$2" ]; then
254 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
255 exit 0
256 else
257 rootfs=$2
258 if [ ! -d "$rootfs" ]; then
259 echo -e "\nWarning : $rootfs doesn't exist!\n"
260 exit 1
261 fi
262 fi
263 if [ -d $rootfs/proc/1 ]; then
264 echo -e "\nWarning : $rootfs/proc mounted!\n"
265 exit 1
266 fi
267 cd $rootfs || exit 1
268 echo ""
269 boldify "Cleaning chroot: $rootfs"
270 separator
271 for i in bin dev etc lib media mnt proc sbin sys tmp usr var run
272 do
273 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
274 rm -rf $i && status
275 done
276 separator && echo "" ;;
277 push|-p)
278 check_mirror $@
279 rsync -r -t -O -l -v -z --delete \
280 $local -e ssh $user@$MIRROR:$remote ;;
281 dry-push|-dp)
282 check_mirror $@
283 rsync -r -t -O -l -v -z --delete --dry-run \
284 $local -e ssh $user@$MIRROR:$remote ;;
285 pull)
286 check_mirror $@
287 rsync -r -t -l -v -z --delete \
288 -e ssh $user@$MIRROR:$remote $local ;;
289 dry-pull)
290 check_mirror $@
291 rsync -r -t -l -v -z --delete --dry-run \
292 -e ssh $user@$MIRROR:$remote $local ;;
293 purge|dry-purge)
294 check_root
295 get_version $@
296 purge_packages $1
297 purge_sources $1 ;;
298 relpkg|-rp)
299 # Release a slitaz sub-project and upload tarball to mirror
300 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
301 if [ -z $2 ] || [ -z $3 ]; then
302 echo -e "\nUsage: $0 relpkg package version\n"
303 exit 0
304 fi
305 pkg=$2
306 version=$3
307 echo "" && cd $PROJECTS/$pkg
309 # Sanity check
310 if ! grep -q $version$ .hgtags; then
311 echo "Missing Hg tag for version: $version"
312 echo -e "You may want to: hg tag $version && hg push\n"
313 exit 0
314 fi
316 # Archive
317 echo -n "Creating tarball and md5sum for: $pkg-$version... "
318 hg archive -t tgz $pkg-$version.tar.gz
319 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
320 echo "Done"
322 # Upload
323 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
324 read upload
325 if [ "$upload" = "y" ]; then
326 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
327 scp $pkg-$version.tar.gz $pkg-$version.md5 \
328 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
329 fi
331 # Update pkg in wok
332 echo -n "Do you wish to update $pkg in wok [N/y] ? "
333 read update
334 if [ "$update" = "y" ]; then
335 echo -n "Updating $pkg: $version"
336 cd $PROJECTS/wok
337 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
338 status
339 fi ;;
340 help)
341 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
342 echo ""
343 boldify "Help for: $2"
344 separator
345 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
346 less -M /usr/share/doc/slitaz/$2.txt
347 else
348 echo "No help found"
349 fi
350 separator && echo "" ;;
351 usage|*)
352 usage ;;
353 esac
355 exit 0