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

tazwikiss/wkp_Upload: fix data links
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 11 22:08:34 2011 +0200 (2011-08-11)
parents a37a60aa57f2
children a646c0b4d8ef
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 variablea are $UPERCASE
6 # and variables initialized by tazdev itself are $lowersace
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 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
16 [ -f tazdev.conf ] && . ./tazdev.conf
18 if [ -z "$SLITAZ" ]; then
19 echo -e "\nNo config file found\n" && exit 1
20 fi
22 usage()
23 {
24 echo -e "\nSliTaz developers and build host tool\n
25 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|undigest|path]
26 \033[1mCommands: \033[0m\n
27 usage Print this short usage and command list
28 projects-stats|-ps Display statistics about your projects
29 chroot Mount virtual fs if needed and chroot into the build env
30 gen-chroot|-gs Generate a chroot using the last cooking base rootfs
31 umount-chroot|-uc Unmount chroot specified on cmdline (--forced to force)
32 clean-chroot Clean a chroot environment (skip root/ and home/)
33 purge Remove obsolete packages and obsolete source tarballs
34 dry-purge Show obsolete packages and obsolete source tarballs
35 push|-p Upload new packages to the main mirror.
36 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
37 pull Download new packages from the main mirror.
38 dry-pull Show what will be downloaded from the mirror. Does nothing
39 pack-flavors Pack all SliTaz Live flavors at once.
40 relpkg|-rp Archive and upload new package/project version
41 reliso|-ri Create all main flavors (not loram)\n"
42 }
44 # Be sure we root.
45 check_root() {
46 [ $(id -u) != 0 ] && \
47 echo -e "\nYou must be root to use: $(basename $0) $@\n" && exit 0
48 }
50 separator() {
51 echo "================================================================================"
52 }
54 status() {
55 echo -en "\\033[70G[ "
56 if [ $? = 0 ]; then
57 echo -en "\\033[1;32mOK"
58 else
59 echo -en "\\033[1;31mFailed"
60 fi
61 echo -e "\\033[0;39m ]"
62 }
64 get_version()
65 {
66 if [ "$2" = "stable" ]; then
67 version=stable
68 slitaz=$STABLE
69 elif [ -n "$2" ]; then
70 # Undigest - custom ?
71 version=$2
72 slitaz=$SLITAZ/$2
73 else
74 version=cooking
75 slitaz=$COOKING
76 fi
77 rootfs=$slitaz/chroot
78 }
80 check_mirror()
81 {
82 # ping -c 1 $MIRROR
83 if [ -n "$2" ]; then
84 user=$2
85 else
86 user=$user
87 fi
88 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
89 remote=$MIRROR_PKGS/stable/
90 local=$STABLE/packages/
91 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
92 remote=$MIRROR_PKGS/undigest/
93 local=$UNDIGEST/packages/
94 else
95 remote=$MIRROR_PKGS/cooking/
96 local=$COOKING/packages/
97 fi
98 }
100 # Mount virtual Kernel file systems and chroot but check that nobody
101 # else has done mounts
102 mount_chroot()
103 {
104 if [ ! -d $rootfs/proc/1 ]; then
105 echo -ne "\nMounting virtual filesystems..."
106 mount -t proc proc $rootfs/proc
107 mount -t sysfs sysfs $rootfs/sys
108 mount -t devpts devpts $rootfs/dev/pts
109 mount -t tmpfs shm $rootfs/dev/shm
110 status
111 fi
112 # Mount source so they can be shared between cooking/stable/undigest.
113 # But do it only if it's a slitaz developement chroot.
114 fs=$rootfs/home/slitaz
115 if [ -d "$slitaz" ]; then
116 mkdir -p $SLITAZ/src $fs/src
117 mount -o bind $SLITAZ/src $fs/src
118 # Now mount package dir so they are in /home/slitaz/$version
119 # We may not mount cache wok or others it has no point and if
120 # one want to use a shared wok he can bind it manually.
121 mkdir -p $slitaz/packages $fs/packages
122 mount -o bind $slitaz/packages $fs/packages
123 fi
124 }
126 # Unmount virtual Kernel file systems on exit and ensure we are the last
127 # user before unmounting !
128 umount_chroot()
129 {
130 [ "$1" ] && ROOTF=$1
131 fs=$rootfs/home/slitaz
132 echo -ne "\nUnmounting virtual filesystems..."
133 umount $rootfs/dev/shm
134 umount $rootfs/dev/pts
135 umount $rootfs/sys
136 umount $rootfs/proc
137 umount $fs/src
138 umount $fs/packages
139 status && echo ""
140 #echo -e "\nProcess: $ps\n"
141 #ps | grep `basename $0` | grep -v grep
142 #echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
143 }
145 # Get the last cooking base rootfs, extract and configure.
146 gen_new_chroot()
147 {
148 echo -e "\nGenerating new chroot in : $rootfs"
149 separator
150 mkdir -p $rootfs
151 if [ "$ROOTFS_PKG" == "yes" ]; then
152 for pkg in $CHROOT_PKGS
153 do
154 tazpkg get-install $pkg --root=$rootfs
155 done
156 elif [ "$ROOTFS_PKG" == "no" ]; then
157 cd $rootfs
158 wget $DL_URL/boot/cooking/rootfs-base.gz
159 echo -n "Extracting the rootfs..."
160 lzma d rootfs-base.gz -so | cpio -id
161 rm rootfs-base.gz
162 fi
163 echo -n "Creating resolv.conf..."
164 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
165 status
166 separator
167 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
168 echo -e "Example: tazdev chroot $rootfs\n"
169 }
171 # Remove obsolate slitaz packages
172 purge_packages()
173 {
174 arg=$1
175 tmp=/tmp/tazdev.$$
176 ls $BUILD_WOK | while read pkg; do
177 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
178 EXTRAversion=""
179 . $BUILD_WOK/$pkg/taz/*/receipt
180 echo $pkg-$version$EXTRAversion.tazpkg
181 done > $tmp
182 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
183 case "$pkg" in
184 *.tazpkg)
185 grep -q ^$pkg$ $tmp && continue
186 echo Remove $pkg
187 [ "$arg" == "purge" ] &&
188 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
189 esac
190 done
191 rm -f $tmp
192 }
194 # Remove obsolate source tarballs
195 purge_sources()
196 {
197 arg=$1
198 tmp=/tmp/tazdev.$$
199 ls $BUILD_WOK | while read pkg; do
200 [ -f $BUILD_WOK/$pkg/receipt ] || continue
201 TARBALL=""
202 . $BUILD_WOK/$pkg/receipt
203 [ -n "$TARBALL" ] && echo $TARBALL
204 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
205 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
206 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
207 sed "s|['\"/]||g" | while read file ; do
208 eval echo $file 2> /dev/null
209 done
210 done > $tmp
211 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
212 grep -q ^$pkg$ $tmp && continue
213 echo Remove $pkg
214 [ "$arg" == "purge" ] &&
215 rm -f $slitaz/chroot/home/slitaz/src/$pkg
216 done
217 rm -f $tmp
218 }
220 case "$1" in
221 projects-stats|-ps)
222 echo -e "\nStatistics for: $PROJECTS\n"
223 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
224 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
225 separator
226 cd $PROJECTS
227 for proj in *
228 do
229 rev=""
230 echo -n "$proj"
231 size=`du -sh $proj | awk '{ print $1 }'`
232 echo -ne "\033[24G $size"
233 if [ -d $proj/.hg ]; then
234 cd $proj
235 rev=`hg head --template '{rev}\n'`
236 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
237 echo -ne "\033[38G $rev"
238 echo -ne "\033[48G $vers" && cd ..
239 fi
240 files=`find $proj -type f | wc -l`
241 echo -e "\033[64G $files"
242 done
243 separator
244 echo "" ;;
245 chroot)
246 # Chroot into a build env. Default to cooking configured in tazdev.conf
247 check_root
248 get_version $@
249 [ -d "$2" ] && rootfs=$2
250 mount_chroot
251 echo -e "Chrooting to: $rootfs\n"
252 chroot $rootfs /bin/sh --login
253 umount_chroot ;;
254 umount-chroot|-uc)
255 check_root
256 get_version $@
257 [ "$2" ] && rootfs=$2
258 umount_chroot $rootfs ;;
259 gen-chroot|-gc)
260 check_root
261 get_version $@
262 [ -d "$2" ] && rootfs=$2
263 # Dont break another env.
264 if [ -d $rootfs/bin ]; then
265 echo -e "\nA chroot environment already exists in : $rootfs\n"
266 exit 1
267 fi
268 gen_new_chroot ;;
269 clean-chroot)
270 # Keep root/ and /home they may have a build wok, custom scripts, etc.
271 check_root
272 if [ -z "$2" ]; then
273 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
274 exit 0
275 else
276 rootfs=$2
277 if [ ! -d "$rootfs" ]; then
278 echo -e "\nWarning : $rootfs doesn't exist!\n"
279 exit 1
280 fi
281 fi
282 if [ -d $rootfs/proc/1 ]; then
283 echo -e "\nWarning : $rootfs/proc mounted!\n"
284 exit 1
285 fi
286 cd $rootfs || exit 1
287 echo -e "\nCleaning chroot in: $rootfs"
288 separator
289 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
290 do
291 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
292 rm -rf $i
293 status
294 done
295 separator && echo "" ;;
296 push|-p)
297 check_mirror $@
298 rsync -r -t -O -l -v -z --delete \
299 $local -e ssh $user@$MIRROR:$remote ;;
300 dry-push|-dp)
301 check_mirror $@
302 rsync -r -t -O -l -v -z --delete --dry-run \
303 $local -e ssh $user@$MIRROR:$remote ;;
304 pull)
305 check_mirror $@
306 rsync -r -t -l -v -z --delete \
307 -e ssh $user@$MIRROR:$remote $local ;;
308 dry-pull)
309 check_mirror $@
310 rsync -r -t -l -v -z --delete --dry-run \
311 -e ssh $user@$MIRROR:$remote $local ;;
312 purge|dry-purge)
313 check_root
314 get_version $@
315 purge_packages $1
316 purge_sources $1 ;;
317 relpkg|-rp)
318 # Release a slitaz sub-project and upload tarball to mirror
319 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
320 if [ -z $2 ] || [ -z $3 ]; then
321 echo -e "\nUsage: $0 relpkg package version\n"
322 exit 0
323 fi
324 pkg=$2
325 version=$3
326 echo "" && cd $PROJECTS/$pkg
328 # Sanity check
329 if ! grep -q $version$ .hgtags; then
330 echo "Missing Hg tag for version: $version"
331 echo -e "You may want to: hg tag $version && hg push\n"
332 exit 0
333 fi
335 # Archive
336 echo -n "Creating tarball and md5sum for: $pkg-$version... "
337 hg archive -t tgz $pkg-$version.tar.gz
338 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
339 echo "Done"
341 # Upload
342 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
343 read upload
344 if [ "$upload" = "y" ]; then
345 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
346 scp $pkg-$version.tar.gz $pkg-$version.md5 \
347 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
348 fi ;;
349 reliso|-ri)
350 # Generate all official images iso at once for a specific version.
351 get_version $@
352 iso=$slitaz/iso
353 mkdir -p $iso
354 for flavor in base core justx firefox
355 do
356 cd $slitaz
357 tazlito pack-flavor $flavor
358 tazlito get-flavor $flavor
359 tazlito gen-distro
360 if [ "$flavor" == "core" ]; then
361 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
362 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
363 else
364 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
365 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
366 fi
367 done
368 # Clean up slitaz working directory.
369 rm *.flavor tazlito.conf ;;
370 usage|*)
371 usage ;;
372 esac
374 exit 0