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

tazdev: set mirror path in chroot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Dec 22 19:21:18 2013 +0000 (2013-12-22)
parents 4e046585acc6
children fd72f11de539
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 VERSION=1.9
17 . /lib/libtaz.sh
19 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
20 [ -f tazdev.conf ] && . ./tazdev.conf
22 if [ ! "$SLITAZ_HOME" ]; then
23 echo -e "\nNo config file found\n" && exit 1
24 fi
26 usage() {
27 cat << EOT
29 $(boldify "Usage:") $(basename $0) [command] [vers|user|tool] [vers|--opts]
31 SliTaz developers and build host tool v$VERSION
33 $(boldify "Commands:")
34 usage Print this short usage and command list
35 help Give help on a SliTaz tool or library.
36 stats|-s Display statistics about your projects
37 chroot|-c Mount virtual fs and chroot into the build env
38 gen-chroot|-gc Generate a chroot using packages from config file
39 umount-chroot|-uc Unmount chroot specified on cmdline
40 clean-chroot|-cc Clean a chroot environment (skip root/ and home/)
41 !purge Remove obsolete packages and obsolete source tarballs
42 !dry-purge Show obsolete packages and obsolete source tarballs
43 push|-p Upload new packages to the main mirror
44 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
45 pull Download new packages from the main mirror
46 dry-pull Show what will be downloaded from the mirror. Does nothing
47 relpkg|-rp Archive and upload new package/project version
49 $(boldify "Options:")
50 --rootfs= Path to the chroot to generate or clean
51 --arch= Specify the architecture type for cross-chroot, push/pull
52 --clean Clean chroot before generation a new one
54 $(boldify "Options:")
55 $(basename $0) gen-chroot undigest --clean
56 $(basename $0) chroot stable
57 $(basename $0) -c --arch=arm
59 EOT
60 }
62 get_version() {
63 # Stable, undigest or custom.
64 if [ "$2" ] && [ ! $(echo $2 | grep "\--*") ]; then
65 version=$2
66 slitaz=$SLITAZ_HOME/$2
67 else
68 version=cooking
69 slitaz=$SLITAZ_HOME/cooking
70 fi
71 if [ "$arch" ]; then
72 rootfs=$slitaz/$arch/chroot
73 else
74 rootfs=$slitaz/chroot
75 fi
76 }
78 check_mirror() {
79 # ping -c 1 $MIRROR
80 if [ -n "$2" ]; then
81 user=$2
82 else
83 user=$user
84 fi
85 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
86 remote=$MIRROR_PKGS/stable/
87 local=$SLITAZ_HOME/stable/packages/
88 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
89 remote=$MIRROR_PKGS/undigest/
90 local=$SLITAZ_HOME/undigest/packages/
91 else
92 remote=$MIRROR_PKGS/cooking/
93 local=$SLITAZ_HOME/cooking/packages/
94 fi
95 if [ "$arch" ]; then
96 remote=${remote}$arch/
97 local=${local}$arch/
98 fi
99 }
101 # Bind a directory into the chroot
102 bind_chroot_dir()
103 {
104 mkdir -p $1 $2
105 mount -o bind $1 $2
106 }
108 # Mount virtual Kernel file systems and chroot but check that nobody
109 # else has done mounts
110 mount_chroot()
111 {
112 if [ ! -d $rootfs/proc/1 ]; then
113 echo -ne "\nMounting virtual filesystems..."
114 mount -t proc proc $rootfs/proc
115 mount -t sysfs sysfs $rootfs/sys
116 mount -t devpts devpts $rootfs/dev/pts
117 mount -t tmpfs shm $rootfs/dev/shm
118 status
119 fi
120 # Mount source so they can be shared between cooking/stable/undigest.
121 # But do it only if it's a slitaz developement chroot.
122 fs=$rootfs/home/slitaz
123 if [ -d "$slitaz" ]; then
124 bind_chroot_dir $SLITAZ_HOME/src $fs/src
125 # Now mount package dir so they are in /home/slitaz/$version
126 # We may not mount cache wok or others it has no point and if
127 # one wants to use a shared wok he can bind it manually.
128 if [ "$arch" ]; then
129 slitaz=$slitaz/$arch
130 fi
131 [ -d "$fs/packages" ] || mkdir -p $fs/packages
132 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
133 bind_chroot_dir $slitaz/packages $fs/packages
134 fi
135 }
137 # Unmount virtual Kernel file systems.
138 umount_chroot() {
139 [ "$1" ] && rootfs=$1
140 fs=$rootfs/home/slitaz
141 echo -ne "\nUnmounting virtual filesystems..."
142 umount $rootfs/dev/shm
143 umount $rootfs/dev/pts
144 umount $rootfs/sys
145 umount $rootfs/proc
146 if mount | fgrep -q $fs/src; then
147 umount $fs/src
148 umount $fs/packages
149 fi
150 status && echo ""
151 }
153 # Get the last cooking base rootfs, extract and configure.
154 gen_chroot() {
155 echo -e "\nGenerating new chroot in: $rootfs"
156 separator
157 mkdir -p $rootfs
158 # We my gen cooking chroot from a stable version or invers
159 case "$version" in
160 cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
161 stable|4.0) url="http://$MIRROR/packages/stable/" ;;
162 esac
163 # --mirror=
164 [ "$mirror" ] && url="$mirror"
165 mpath=/var/lib/tazpkg/mirror
166 cp $mpath ${mpath}.tazdev
167 echo "$url" > $mpath
168 mkdir -p $(dirname $rootfs$mpath)
169 echo "$url" > $rootfs$mpath
170 echo -n "Mirror URL: ${url#http://}"
171 tazpkg recharge 2>/dev/null 1>/dev/null
172 status
173 for pkg in $CHROOT_PKGS
174 do
175 echo -n "Installing: $pkg $vers"
176 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
177 status
178 done
179 echo -n "Creating resolv.conf..."
180 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
181 status
182 echo -n "Creating TZ..."
183 cat /etc/TZ > $rootfs/etc/TZ
184 status
185 echo -n "Restoring host packages list..."
186 mv -f ${mpath}.tazdev $mpath
187 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
188 status
189 separator
190 case "$version" in
191 cooking) version="" ;;
192 esac
193 [ "$arch" ] && version="$version --arch=$arch"
194 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
195 newline
196 }
198 # Remove obsolate slitaz packages --> in cooker ???
199 purge_packages() {
200 arg=$1
201 tmp=/tmp/tazdev.$$
202 ls $wok| while read pkg; do
203 [ -f $wok/$pkg/taz/*/receipt ] || continue
204 unset VERSION EXTRAVERSION
205 . $wok/$pkg/taz/*/receipt
206 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
207 done > $tmp
208 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
209 case "$pkg" in
210 *.tazpkg)
211 grep -q ^$pkg$ $tmp && continue
212 echo "Removing pkg: $pkg"
213 [ "$arg" == "purge" ] &&
214 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
215 esac
216 done
217 rm -f $tmp
218 }
220 # Remove obsolete source tarballs --> in cooker ??? but we share $src
221 # between cooking and stable to we must scan all versions, all arch
222 purge_sources() {
223 arg=$1
224 wok=$slitaz/chroot/home/slitaz/wok
225 tmp=/tmp/tazdev.$$
226 ls $wok| while read pkg; do
227 [ -f $wok/$pkg/receipt ] || continue
228 TARBALL=""
229 . $wok/$pkg/receipt
230 [ -n "$TARBALL" ] && echo $TARBALL
231 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
232 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
233 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
234 sed "s|['\"/]||g" | while read file ; do
235 eval echo $file 2> /dev/null
236 done
237 done > $tmp
238 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
239 grep -q ^$pkg$ $tmp && continue
240 echo "Removing src: $pkg"
241 [ "$arg" == "purge" ] &&
242 rm -f $slitaz/chroot/home/slitaz/src/$pkg
243 done
244 rm -f $tmp
245 }
247 case "$1" in
248 stats|-s)
249 echo -e "\nStatistics for: $PROJECTS\n"
250 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
251 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
252 separator
253 cd $PROJECTS
254 for proj in *
255 do
256 rev=""
257 echo -n "$proj"
258 size=`du -sh $proj | awk '{ print $1 }'`
259 echo -ne "\033[24G $size"
260 if [ -d $proj/.hg ]; then
261 cd $proj
262 rev=`hg head --template '{rev}\n'`
263 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
264 echo -ne "\033[38G $rev"
265 echo -ne "\033[48G $vers" && cd ..
266 fi
267 files=`find $proj -type f | wc -l`
268 echo -e "\033[64G $files"
269 done
270 separator
271 echo "" ;;
272 chroot|-c)
273 # Chroot into a build env. Default to cooking configured in tazdev.conf
274 check_root
275 get_version $@
276 [ -d "$2" ] && rootfs=$2
277 mount_chroot
278 echo -e "Chrooting to: $rootfs\n"
279 chroot $rootfs /bin/sh --login
280 umount_chroot ;;
281 umount-chroot|-uc)
282 check_root
283 get_version $@
284 [ -d "$2" ] && rootfs=$2
285 umount_chroot $rootfs ;;
286 gen-chroot|-gc)
287 check_root
288 # We can use: --rootfs=/path/to/chroot
289 if [ ! "$rootfs" ]; then
290 get_version $@
291 fi
292 if [ "$clean" ] || [ "$forced" ]; then
293 $0 -cc --rootfs=$rootfs --noline
294 fi
295 # Dont break another env.
296 if [ -d $rootfs/bin ]; then
297 echo -e "\nA chroot environment already exists in : $rootfs\n"
298 exit 1
299 fi
300 gen_chroot ;;
301 clean-chroot|-cc)
302 check_root
303 # We can use: --rootfs=/path/to/chroot
304 if [ ! "$rootfs" ]; then
305 get_version $@
306 fi
307 if [ ! -d "$rootfs" ]; then
308 echo -e "\nChroot doesn't exist: $rootfs\n"
309 exit 1
310 fi
311 if [ -d $rootfs/proc/1 ]; then
312 echo -e "\nWARNING: $rootfs/proc mounted!\n"
313 exit 1
314 fi
315 cd $rootfs || exit 1
316 echo ""
317 boldify "Cleaning chroot: $rootfs"
318 separator
319 # Keep root/ and /home they may have a build wok, custom scripts, etc.
320 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
321 do
322 if [ -d "$i" ]; then
323 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
324 rm -rf $i && status
325 fi
326 done
327 rm -f init
328 separator
329 [ "$noline" ] || newline ;;
330 push|-p)
331 check_mirror $@
332 rsync -r -t -O -l -v -z --delete \
333 $local -e ssh $user@$MIRROR:$remote ;;
334 dry-push|-dp)
335 check_mirror $@
336 rsync -r -t -O -l -v -z --delete --dry-run \
337 $local -e ssh $user@$MIRROR:$remote ;;
338 pull)
339 check_mirror $@
340 rsync -r -t -l -v -z --delete \
341 -e ssh $user@$MIRROR:$remote $local ;;
342 dry-pull)
343 check_mirror $@
344 rsync -r -t -l -v -z --delete --dry-run \
345 -e ssh $user@$MIRROR:$remote $local ;;
346 purge|dry-purge)
347 check_root
348 get_version $@
349 purge_packages $1
350 purge_sources $1 ;;
351 relpkg|-rp)
352 # Release a slitaz sub-project and upload tarball to mirror
353 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
354 if [ -z $2 ]; then
355 echo -e "\nUsage: $0 relpkg package [version]\n"
356 exit 0
357 fi
358 pkg=$2
360 # We can get the last found version in .hgtags
361 if [ -z $3 ]; then
362 version=$(tail -n 1 $PROJECTS/$pkg/.hgtags | awk '{print $2'})
363 else
364 version=$3
365 fi
367 echo "" && cd $PROJECTS/$pkg
369 # Sanity check
370 if ! grep -q $version$ .hgtags; then
371 echo "Missing Hg tag for version: $version"
372 echo -e "You may want to: hg tag $version && hg push\n"
373 exit 0
374 fi
376 # Archive
377 echo -n "Creating tarball and md5sum for: $pkg-$version... "
378 hg archive -t tgz $SOURCE/$pkg-$version.tar.gz
379 ( cd $SOURCE; md5sum $pkg-$version.tar.gz > $pkg-$version.md5 )
380 echo "Done"
382 # Upload
383 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
384 read upload
385 if [ "$upload" = "y" ]; then
386 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
387 scp $pkg-$version.tar.gz $pkg-$version.md5 \
388 $MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
389 fi
391 # Update pkg in wok
392 echo -n "Do you wish to update $pkg in wok [N/y] ? "
393 read update
394 if [ "$update" = "y" ]; then
395 echo -n "Updating $pkg: $version"
396 cd $PROJECTS/wok
397 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
398 status
399 fi ;;
400 help)
401 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
402 echo ""
403 boldify "Help for: $2"
404 separator
405 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
406 less -M /usr/share/doc/slitaz/$2.txt
407 else
408 echo "No help found"
409 fi
410 separator && echo "" ;;
411 usage|*)
412 usage ;;
413 esac
415 exit 0