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

tazwikiss: add wkp_FullScreen.sh
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Nov 27 11:03:01 2013 +0000 (2013-11-27)
parents 8d049d40ee22
children 2d939b459507
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 echo -n "Mirror URL: ${url#http://}"
169 tazpkg recharge 2>/dev/null 1>/dev/null
170 status
171 for pkg in $CHROOT_PKGS
172 do
173 echo -n "Installing: $pkg $vers"
174 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
175 status
176 done
177 echo -n "Creating resolv.conf..."
178 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
179 status
180 echo -n "Creating TZ..."
181 cat /etc/TZ > $rootfs/etc/TZ
182 status
183 echo -n "Restoring host packages list..."
184 mv -f ${mpath}.tazdev $mpath
185 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
186 status
187 separator
188 case "$version" in
189 cooking) version="" ;;
190 esac
191 [ "$arch" ] && version="$version --arch=$arch"
192 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
193 newline
194 }
196 # Remove obsolate slitaz packages --> in cooker ???
197 purge_packages() {
198 arg=$1
199 tmp=/tmp/tazdev.$$
200 ls $wok| while read pkg; do
201 [ -f $wok/$pkg/taz/*/receipt ] || continue
202 unset VERSION EXTRAVERSION
203 . $wok/$pkg/taz/*/receipt
204 echo $pkg-${VERSION}$EXTRAVERSION.tazpkg
205 done > $tmp
206 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
207 case "$pkg" in
208 *.tazpkg)
209 grep -q ^$pkg$ $tmp && continue
210 echo "Removing pkg: $pkg"
211 [ "$arg" == "purge" ] &&
212 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
213 esac
214 done
215 rm -f $tmp
216 }
218 # Remove obsolete source tarballs --> in cooker ??? but we share $src
219 # between cooking and stable to we must scan all versions, all arch
220 purge_sources() {
221 arg=$1
222 wok=$slitaz/chroot/home/slitaz/wok
223 tmp=/tmp/tazdev.$$
224 ls $wok| while read pkg; do
225 [ -f $wok/$pkg/receipt ] || continue
226 TARBALL=""
227 . $wok/$pkg/receipt
228 [ -n "$TARBALL" ] && echo $TARBALL
229 grep SOURCES_REPOSITORY/ $wok/$pkg/receipt | sed \
230 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
231 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
232 sed "s|['\"/]||g" | while read file ; do
233 eval echo $file 2> /dev/null
234 done
235 done > $tmp
236 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
237 grep -q ^$pkg$ $tmp && continue
238 echo "Removing src: $pkg"
239 [ "$arg" == "purge" ] &&
240 rm -f $slitaz/chroot/home/slitaz/src/$pkg
241 done
242 rm -f $tmp
243 }
245 case "$1" in
246 stats|-s)
247 echo -e "\nStatistics for: $PROJECTS\n"
248 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
249 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
250 separator
251 cd $PROJECTS
252 for proj in *
253 do
254 rev=""
255 echo -n "$proj"
256 size=`du -sh $proj | awk '{ print $1 }'`
257 echo -ne "\033[24G $size"
258 if [ -d $proj/.hg ]; then
259 cd $proj
260 rev=`hg head --template '{rev}\n'`
261 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
262 echo -ne "\033[38G $rev"
263 echo -ne "\033[48G $vers" && cd ..
264 fi
265 files=`find $proj -type f | wc -l`
266 echo -e "\033[64G $files"
267 done
268 separator
269 echo "" ;;
270 chroot|-c)
271 # Chroot into a build env. Default to cooking configured in tazdev.conf
272 check_root
273 get_version $@
274 [ -d "$2" ] && rootfs=$2
275 mount_chroot
276 echo -e "Chrooting to: $rootfs\n"
277 chroot $rootfs /bin/sh --login
278 umount_chroot ;;
279 umount-chroot|-uc)
280 check_root
281 get_version $@
282 [ -d "$2" ] && rootfs=$2
283 umount_chroot $rootfs ;;
284 gen-chroot|-gc)
285 check_root
286 # We can use: --rootfs=/path/to/chroot
287 if [ ! "$rootfs" ]; then
288 get_version $@
289 fi
290 if [ "$clean" ] || [ "$forced" ]; then
291 $0 -cc --rootfs=$rootfs --noline
292 fi
293 # Dont break another env.
294 if [ -d $rootfs/bin ]; then
295 echo -e "\nA chroot environment already exists in : $rootfs\n"
296 exit 1
297 fi
298 gen_chroot ;;
299 clean-chroot|-cc)
300 check_root
301 # We can use: --rootfs=/path/to/chroot
302 if [ ! "$rootfs" ]; then
303 get_version $@
304 fi
305 if [ ! -d "$rootfs" ]; then
306 echo -e "\nChroot doesn't exist: $rootfs\n"
307 exit 1
308 fi
309 if [ -d $rootfs/proc/1 ]; then
310 echo -e "\nWARNING: $rootfs/proc mounted!\n"
311 exit 1
312 fi
313 cd $rootfs || exit 1
314 echo ""
315 boldify "Cleaning chroot: $rootfs"
316 separator
317 # Keep root/ and /home they may have a build wok, custom scripts, etc.
318 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
319 do
320 if [ -d "$i" ]; then
321 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
322 rm -rf $i && status
323 fi
324 done
325 rm -f init
326 separator
327 [ "$noline" ] || newline ;;
328 push|-p)
329 check_mirror $@
330 rsync -r -t -O -l -v -z --delete \
331 $local -e ssh $user@$MIRROR:$remote ;;
332 dry-push|-dp)
333 check_mirror $@
334 rsync -r -t -O -l -v -z --delete --dry-run \
335 $local -e ssh $user@$MIRROR:$remote ;;
336 pull)
337 check_mirror $@
338 rsync -r -t -l -v -z --delete \
339 -e ssh $user@$MIRROR:$remote $local ;;
340 dry-pull)
341 check_mirror $@
342 rsync -r -t -l -v -z --delete --dry-run \
343 -e ssh $user@$MIRROR:$remote $local ;;
344 purge|dry-purge)
345 check_root
346 get_version $@
347 purge_packages $1
348 purge_sources $1 ;;
349 relpkg|-rp)
350 # Release a slitaz sub-project and upload tarball to mirror
351 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
352 if [ -z $2 ]; then
353 echo -e "\nUsage: $0 relpkg package [version]\n"
354 exit 0
355 fi
356 pkg=$2
358 # We can get the last found version in .hgtags
359 if [ -z $3 ]; then
360 version=$(tail -n 1 $PROJECTS/$pkg/.hgtags | awk '{print $2'})
361 else
362 version=$3
363 fi
365 echo "" && cd $PROJECTS/$pkg
367 # Sanity check
368 if ! grep -q $version$ .hgtags; then
369 echo "Missing Hg tag for version: $version"
370 echo -e "You may want to: hg tag $version && hg push\n"
371 exit 0
372 fi
374 # Archive
375 echo -n "Creating tarball and md5sum for: $pkg-$version... "
376 hg archive -t tgz $SOURCE/$pkg-$version.tar.gz
377 ( cd $SOURCE; md5sum $pkg-$version.tar.gz > $pkg-$version.md5 )
378 echo "Done"
380 # Upload
381 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
382 read upload
383 if [ "$upload" = "y" ]; then
384 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
385 scp $pkg-$version.tar.gz $pkg-$version.md5 \
386 $MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
387 fi
389 # Update pkg in wok
390 echo -n "Do you wish to update $pkg in wok [N/y] ? "
391 read update
392 if [ "$update" = "y" ]; then
393 echo -n "Updating $pkg: $version"
394 cd $PROJECTS/wok
395 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
396 status
397 fi ;;
398 help)
399 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
400 echo ""
401 boldify "Help for: $2"
402 separator
403 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
404 less -M /usr/share/doc/slitaz/$2.txt
405 else
406 echo "No help found"
407 fi
408 separator && echo "" ;;
409 usage|*)
410 usage ;;
411 esac
413 exit 0