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

tazdev: ins cross chroot we still have /home/slitaz/packages
author Christophe Lincoln <pankso@slitaz.org>
date Wed May 09 19:34:56 2012 +0200 (2012-05-09)
parents 227a8a6ba4d7
children 911e4e78149d
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 if [ "$arch" ]; then
106 slitaz=$slitaz/$arch
107 fi
108 [ -d "$fs/packages" ] || mkdir -p $fs/packages
109 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
110 bind_chroot_dir $slitaz/packages $fs/packages
111 fi
112 }
114 # Unmount virtual Kernel file systems.
115 umount_chroot() {
116 [ "$1" ] && rootfs=$1
117 fs=$rootfs/home/slitaz
118 echo -ne "\nUnmounting virtual filesystems..."
119 umount $rootfs/dev/shm
120 umount $rootfs/dev/pts
121 umount $rootfs/sys
122 umount $rootfs/proc
123 if mount | fgrep -q $fs/src; then
124 umount $fs/src
125 umount $fs/packages
126 fi
127 status && echo ""
128 }
130 # Get the last cooking base rootfs, extract and configure.
131 gen_chroot() {
132 echo -e "\nGenerating new chroot in: $rootfs"
133 separator
134 mkdir -p $rootfs
135 for pkg in $CHROOT_PKGS
136 do
137 tazpkg get-install $pkg --root=$rootfs
138 done
139 echo -n "Creating resolv.conf..."
140 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
141 status
142 separator
143 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
144 echo -e "Example: tazdev chroot $rootfs\n"
145 }
147 # Remove obsolate slitaz packages
148 purge_packages() {
149 arg=$1
150 tmp=/tmp/tazdev.$$
151 ls $wok| while read pkg; do
152 [ -f $wok/$pkg/taz/*/receipt ] || continue
153 unset VERSION EXTRAVERSION
154 . $wok/$pkg/taz/*/receipt
155 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
156 done > $tmp
157 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
158 case "$pkg" in
159 *.tazpkg)
160 grep -q ^$pkg$ $tmp && continue
161 echo "Removing pkg: $pkg"
162 [ "$arg" == "purge" ] &&
163 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
164 esac
165 done
166 rm -f $tmp
167 }
169 # Remove obsolete source tarballs
170 purge_sources() {
171 arg=$1
172 wok=$slitaz/chroot/home/slitaz/wok
173 tmp=/tmp/tazdev.$$
174 ls $wok| while read pkg; do
175 [ -f $wok/$pkg/receipt ] || continue
176 TARBALL=""
177 . $wok/$pkg/receipt
178 [ -n "$TARBALL" ] && echo $TARBALL
179 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
180 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
181 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
182 sed "s|['\"/]||g" | while read file ; do
183 eval echo $file 2> /dev/null
184 done
185 done > $tmp
186 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
187 grep -q ^$pkg$ $tmp && continue
188 echo "Removing src: $pkg"
189 [ "$arg" == "purge" ] &&
190 rm -f $slitaz/chroot/home/slitaz/src/$pkg
191 done
192 rm -f $tmp
193 }
195 case "$1" in
196 info)
197 get_version $@
198 echo ""
199 echo "Version: $version"
200 [ "$arch" ] && echo "Arch : $arch"
201 echo "Chroot : $rootfs"
202 echo "" ;;
203 projects-stats|-ps)
204 echo -e "\nStatistics for: $PROJECTS\n"
205 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
206 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
207 separator
208 cd $PROJECTS
209 for proj in *
210 do
211 rev=""
212 echo -n "$proj"
213 size=`du -sh $proj | awk '{ print $1 }'`
214 echo -ne "\033[24G $size"
215 if [ -d $proj/.hg ]; then
216 cd $proj
217 rev=`hg head --template '{rev}\n'`
218 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
219 echo -ne "\033[38G $rev"
220 echo -ne "\033[48G $vers" && cd ..
221 fi
222 files=`find $proj -type f | wc -l`
223 echo -e "\033[64G $files"
224 done
225 separator
226 echo "" ;;
227 chroot|-c)
228 # Chroot into a build env. Default to cooking configured in tazdev.conf
229 check_root
230 get_version $@
231 [ -d "$2" ] && rootfs=$2
232 mount_chroot
233 echo -e "Chrooting to: $rootfs\n"
234 chroot $rootfs /bin/sh --login
235 umount_chroot ;;
236 umount-chroot|-uc)
237 check_root
238 get_version $@
239 [ "$2" ] && rootfs=$2
240 umount_chroot $rootfs ;;
241 gen-chroot|-gc)
242 check_root
243 # We can use: --rootfs=/path/to/chroot
244 if [ "$rootfs" ]; then
245 continue
246 else
247 get_version $@
248 fi
249 # Dont break another env.
250 if [ -d $rootfs/bin ]; then
251 echo -e "\nA chroot environment already exists in : $rootfs\n"
252 exit 1
253 fi
254 gen_chroot ;;
255 clean-chroot)
256 # Keep root/ and /home they may have a build wok, custom scripts, etc.
257 check_root
258 if [ -z "$2" ]; then
259 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
260 exit 0
261 else
262 rootfs=$2
263 if [ ! -d "$rootfs" ]; then
264 echo -e "\nWarning : $rootfs doesn't exist!\n"
265 exit 1
266 fi
267 fi
268 if [ -d $rootfs/proc/1 ]; then
269 echo -e "\nWarning : $rootfs/proc mounted!\n"
270 exit 1
271 fi
272 cd $rootfs || exit 1
273 echo ""
274 boldify "Cleaning chroot: $rootfs"
275 separator
276 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
277 do
278 if [ -d "$i" ]; then
279 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
280 rm -rf $i && status
281 fi
282 done
283 rm -f init
284 separator && echo "" ;;
285 push|-p)
286 check_mirror $@
287 rsync -r -t -O -l -v -z --delete \
288 $local -e ssh $user@$MIRROR:$remote ;;
289 dry-push|-dp)
290 check_mirror $@
291 rsync -r -t -O -l -v -z --delete --dry-run \
292 $local -e ssh $user@$MIRROR:$remote ;;
293 pull)
294 check_mirror $@
295 rsync -r -t -l -v -z --delete \
296 -e ssh $user@$MIRROR:$remote $local ;;
297 dry-pull)
298 check_mirror $@
299 rsync -r -t -l -v -z --delete --dry-run \
300 -e ssh $user@$MIRROR:$remote $local ;;
301 purge|dry-purge)
302 check_root
303 get_version $@
304 purge_packages $1
305 purge_sources $1 ;;
306 relpkg|-rp)
307 # Release a slitaz sub-project and upload tarball to mirror
308 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
309 if [ -z $2 ] || [ -z $3 ]; then
310 echo -e "\nUsage: $0 relpkg package version\n"
311 exit 0
312 fi
313 pkg=$2
314 version=$3
315 echo "" && cd $PROJECTS/$pkg
317 # Sanity check
318 if ! grep -q $version$ .hgtags; then
319 echo "Missing Hg tag for version: $version"
320 echo -e "You may want to: hg tag $version && hg push\n"
321 exit 0
322 fi
324 # Archive
325 echo -n "Creating tarball and md5sum for: $pkg-$version... "
326 hg archive -t tgz $pkg-$version.tar.gz
327 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
328 echo "Done"
330 # Upload
331 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
332 read upload
333 if [ "$upload" = "y" ]; then
334 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
335 scp $pkg-$version.tar.gz $pkg-$version.md5 \
336 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
337 fi
339 # Update pkg in wok
340 echo -n "Do you wish to update $pkg in wok [N/y] ? "
341 read update
342 if [ "$update" = "y" ]; then
343 echo -n "Updating $pkg: $version"
344 cd $PROJECTS/wok
345 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
346 status
347 fi ;;
348 help)
349 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
350 echo ""
351 boldify "Help for: $2"
352 separator
353 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
354 less -M /usr/share/doc/slitaz/$2.txt
355 else
356 echo "No help found"
357 fi
358 separator && echo "" ;;
359 usage|*)
360 usage ;;
361 esac
363 exit 0