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

tazdev -rp: fix upload of source
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jan 02 14:31:28 2014 +0100 (2014-01-02)
parents 24d90601dcc6
children e7edf75033b3
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) 2014 SliTaz GNU/Linux - GNU gpl v3
9 #
10 # AUTHORS
11 # Christophe Lincoln <pankso@slitaz.org>
12 # Pascal Bellard <bellard@slitaz.org>
13 # Eric Joseph-Alexandre <erjo@slitaz.org>
14 #
16 VERSION=1.9
18 . /lib/libtaz.sh
20 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
21 [ -f tazdev.conf ] && . ./tazdev.conf
23 if [ ! "$SLITAZ_HOME" ]; then
24 echo -e "\nNo config file found\n" && exit 1
25 fi
27 usage() {
28 cat << EOT
30 $(boldify "Usage:") $(basename $0) [command] [vers|user|tool] [vers|--opts]
32 SliTaz developers and build host tool v$VERSION
34 $(boldify "Commands:")
35 usage Print this short usage and command list
36 help Give help on a SliTaz tool or library.
37 stats|-s Display statistics about your projects
38 chroot|-c Mount virtual fs and chroot into the build env
39 gen-chroot|-gc Generate a chroot using packages from config file
40 umount-chroot|-uc Unmount chroot specified on cmdline
41 clean-chroot|-cc Clean a chroot environment (skip root/ and home/)
42 push|-p Upload new packages to the main mirror
43 dry-push|-dp Show what will be uploaded to the mirror. Does nothing
44 pull Download new packages from the main mirror
45 dry-pull Show what will be downloaded from the mirror. Does nothing
46 relpkg|-rp Archive and upload new package/project version
48 $(boldify "Options:")
49 --rootfs= Path to the chroot to generate or clean
50 --arch= Specify the architecture type for cross-chroot, push/pull
51 --clean Clean chroot before generation a new one
53 $(boldify "Options:")
54 $(basename $0) gen-chroot undigest --clean
55 $(basename $0) chroot stable
56 $(basename $0) -c --arch=arm
58 EOT
59 }
61 get_version() {
62 # Stable, undigest or custom.
63 if [ "$2" ] && [ ! $(echo $2 | grep "\--*") ]; then
64 version=$2
65 slitaz=$SLITAZ_HOME/$2
66 else
67 version=cooking
68 slitaz=$SLITAZ_HOME/cooking
69 fi
70 if [ "$arch" ]; then
71 rootfs=$slitaz/$arch/chroot
72 else
73 rootfs=$slitaz/chroot
74 fi
75 }
77 check_mirror() {
78 # ping -c 1 $MIRROR
79 if [ -n "$2" ]; then
80 user=$2
81 else
82 user=$user
83 fi
84 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
85 remote=$MIRROR_PKGS/stable/
86 local=$SLITAZ_HOME/stable/packages/
87 elif [ "$2" = "backports" ] || [ "$3" = "backports" ]; then
88 remote=$MIRROR_PKGS/backports/
89 local=$SLITAZ_HOME/backports/packages/
90 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
91 remote=$MIRROR_PKGS/undigest/
92 local=$SLITAZ_HOME/undigest/packages/
93 else
94 remote=$MIRROR_PKGS/cooking/
95 local=$SLITAZ_HOME/cooking/packages/
96 fi
97 if [ "$arch" ]; then
98 remote=${remote}$arch/
99 local=${local}$arch/
100 fi
101 }
103 # Bind a directory into the chroot
104 bind_chroot_dir()
105 {
106 mkdir -p $1 $2
107 mount -o bind $1 $2
108 }
110 # Mount virtual Kernel file systems and chroot but check that nobody
111 # else has done mounts
112 mount_chroot()
113 {
114 if [ ! -d $rootfs/proc/1 ]; then
115 echo -ne "\nMounting virtual filesystems..."
116 mount -t proc proc $rootfs/proc
117 mount -t sysfs sysfs $rootfs/sys
118 mount -t devpts devpts $rootfs/dev/pts
119 mount -t tmpfs shm $rootfs/dev/shm
120 status
121 fi
122 # Mount source so they can be shared between cooking/stable/undigest.
123 # But do it only if it's a slitaz developement chroot.
124 fs=$rootfs/home/slitaz
125 if [ -d "$slitaz" ]; then
126 bind_chroot_dir $SLITAZ_HOME/src $fs/src
127 # Now mount package dir so they are in /home/slitaz/$version
128 # We may not mount cache wok or others it has no point and if
129 # one wants to use a shared wok he can bind it manually.
130 if [ "$arch" ]; then
131 slitaz=$slitaz/$arch
132 fi
133 [ -d "$fs/packages" ] || mkdir -p $fs/packages
134 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
135 bind_chroot_dir $slitaz/packages $fs/packages
136 fi
137 }
139 # Unmount virtual Kernel file systems.
140 umount_chroot() {
141 [ "$1" ] && rootfs=$1
142 fs=$rootfs/home/slitaz
143 echo -ne "\nUnmounting virtual filesystems..."
144 umount $rootfs/dev/shm
145 umount $rootfs/dev/pts
146 umount $rootfs/sys
147 umount $rootfs/proc
148 if mount | fgrep -q $fs/src; then
149 umount $fs/src
150 umount $fs/packages
151 fi
152 status && echo ""
153 }
155 # Get the last cooking base rootfs, extract and configure.
156 gen_chroot() {
157 echo -e "\nGenerating new chroot in: $rootfs"
158 separator
159 mkdir -p $rootfs
160 # We my gen cooking chroot from a stable version or invers
161 case "$version" in
162 cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
163 stable*|4.0*|backports) url="http://$MIRROR/packages/stable/" ;;
164 esac
165 # --mirror=
166 [ "$mirror" ] && url="$mirror"
167 mpath=/var/lib/tazpkg/mirror
168 cp $mpath ${mpath}.tazdev
169 echo "$url" > $mpath
170 mkdir -p $(dirname $rootfs$mpath)
171 echo "$url" > $rootfs$mpath
172 echo -n "Mirror URL: ${url#http://}"
173 tazpkg recharge 2>/dev/null 1>/dev/null
174 status
175 for pkg in $CHROOT_PKGS
176 do
177 echo -n "Installing: $pkg $vers"
178 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
179 status
180 done
181 echo -n "Creating resolv.conf..."
182 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
183 status
184 echo -n "Creating TZ..."
185 cat /etc/TZ > $rootfs/etc/TZ
186 status
187 echo -n "Restoring host packages list..."
188 mv -f ${mpath}.tazdev $mpath
189 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
190 status
191 separator
192 case "$version" in
193 cooking) version="" ;;
194 esac
195 [ "$arch" ] && version="$version --arch=$arch"
196 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
197 newline
198 }
200 #
201 # Commands
202 #
204 case "$1" in
205 stats|-s)
206 echo -e "\nStatistics for: $PROJECTS\n"
207 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
208 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
209 separator
210 cd $PROJECTS
211 for proj in *
212 do
213 rev=""
214 echo -n "$proj"
215 size=`du -sh $proj | awk '{ print $1 }'`
216 echo -ne "\033[24G $size"
217 if [ -d $proj/.hg ]; then
218 cd $proj
219 rev=`hg head --template '{rev}\n'`
220 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
221 echo -ne "\033[38G $rev"
222 echo -ne "\033[48G $vers" && cd ..
223 fi
224 files=`find $proj -type f | wc -l`
225 echo -e "\033[64G $files"
226 done
227 separator
228 echo "" ;;
229 chroot|-c)
230 # Chroot into a build env. Default to cooking configured in tazdev.conf
231 check_root
232 get_version $@
233 [ -d "$2" ] && rootfs=$2
234 mount_chroot
235 echo -e "Chrooting to: $rootfs\n"
236 chroot $rootfs /bin/sh --login
237 umount_chroot ;;
238 umount-chroot|-uc)
239 check_root
240 get_version $@
241 [ -d "$2" ] && rootfs=$2
242 umount_chroot $rootfs ;;
243 gen-chroot|-gc)
244 check_root
245 # We can use: --rootfs=/path/to/chroot
246 if [ ! "$rootfs" ]; then
247 get_version $@
248 fi
249 if [ "$clean" ] || [ "$forced" ]; then
250 $0 -cc --rootfs=$rootfs --noline
251 fi
252 # Dont break another env.
253 if [ -d $rootfs/bin ]; then
254 echo -e "\nA chroot environment already exists in : $rootfs\n"
255 exit 1
256 fi
257 gen_chroot ;;
258 clean-chroot|-cc)
259 check_root
260 # We can use: --rootfs=/path/to/chroot
261 if [ ! "$rootfs" ]; then
262 get_version $@
263 fi
264 if [ ! -d "$rootfs" ]; then
265 echo -e "\nChroot doesn't exist: $rootfs\n"
266 exit 1
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 # Keep root/ and /home they may have a build wok, custom scripts, etc.
277 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
278 do
279 if [ -d "$i" ]; then
280 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
281 rm -rf $i && status
282 fi
283 done
284 rm -f init
285 separator
286 [ "$noline" ] || newline ;;
287 push|-p)
288 check_mirror $@
289 rsync -r -t -O -l -v -z --delete \
290 $local -e ssh $user@$MIRROR:$remote ;;
291 dry-push|-dp)
292 check_mirror $@
293 rsync -r -t -O -l -v -z --delete --dry-run \
294 $local -e ssh $user@$MIRROR:$remote ;;
295 pull)
296 check_mirror $@
297 rsync -r -t -l -v -z --delete \
298 -e ssh $user@$MIRROR:$remote $local ;;
299 dry-pull)
300 check_mirror $@
301 rsync -r -t -l -v -z --delete --dry-run \
302 -e ssh $user@$MIRROR:$remote $local ;;
303 relpkg|-rp)
304 # Release a slitaz sub-project and upload tarball to mirror
305 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
306 if [ -z $2 ]; then
307 echo -e "\nUsage: $0 relpkg package [version]\n"
308 exit 0
309 fi
310 pkg=$2
312 # We can get the last found version in .hgtags
313 if [ -z $3 ]; then
314 version=$(tail -n 1 $PROJECTS/$pkg/.hgtags | awk '{print $2'})
315 else
316 version=$3
317 fi
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 $SOURCE/$pkg-$version.tar.gz
331 ( cd $SOURCE; 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 cd ${SOURCE}
339 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
340 scp $pkg-$version.tar.gz $pkg-$version.md5 \
341 $MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
342 fi
344 # Update pkg in wok
345 echo -n "Do you wish to update $pkg in wok [N/y] ? "
346 read update
347 if [ "$update" = "y" ]; then
348 echo -n "Updating $pkg: $version"
349 cd $PROJECTS/wok
350 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
351 status
352 fi ;;
353 help)
354 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
355 echo ""
356 boldify "Help for: $2"
357 separator
358 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
359 less -M /usr/share/doc/slitaz/$2.txt
360 else
361 echo "No help found"
362 fi
363 separator && echo "" ;;
364 usage|*)
365 usage ;;
366 esac
368 exit 0