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

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