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

Tiny edits
author Paul Issott <paul@slitaz.org>
date Mon Dec 12 21:42:12 2016 +0000 (2016-12-12)
parents b1e8c4f9bf01
children 32887197a722
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=2.0
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 up-repos|-upr Update all your SliTaz projects repos in one command.
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" = "backports" ] || [ "$3" = "backports" ]; then
89 remote=$MIRROR_PKGS/backports/
90 local=$SLITAZ_HOME/backports/packages/
91 elif [ "$2" = "undigest" ] || [ "$3" = "undigest" ]; then
92 remote=$MIRROR_PKGS/undigest/
93 local=$SLITAZ_HOME/undigest/packages/
94 elif [ "$2" = "rpi" ] || [ "$3" = "rpi" ]; then
95 remote=$MIRROR_PKGS/cross/rpi/
96 local=$SLITAZ_HOME/cooking/arm/packages/
97 else
98 remote=$MIRROR_PKGS/cooking/
99 local=$SLITAZ_HOME/cooking/packages/
100 fi
101 if [ "$arch" ]; then
102 remote=${remote}$arch/
103 local=${local}$arch/
104 fi
105 }
107 # Bind a directory into the chroot
108 bind_chroot_dir()
109 {
110 mkdir -p $1 $2
111 mount -o bind $1 $2
112 }
114 # Mount virtual Kernel file systems and chroot but check that nobody
115 # else has done mounts
116 mount_chroot()
117 {
118 if [ ! -d $rootfs/proc/1 ]; then
119 echo -ne "\nMounting virtual filesystems..."
120 mount -t proc proc $rootfs/proc
121 mount -t sysfs sysfs $rootfs/sys
122 mount -t devpts devpts $rootfs/dev/pts
123 mount -t tmpfs shm $rootfs/dev/shm
124 status
125 fi
126 # Mount source so they can be shared between cooking/stable/undigest.
127 # But do it only if it's a slitaz development chroot.
128 fs=$rootfs/home/slitaz
129 if [ -d "$slitaz" ]; then
130 bind_chroot_dir $SLITAZ_HOME/src $fs/src
131 # Now mount package dir so they are in /home/slitaz/$version
132 # We may not mount cache wok or others it has no point and if
133 # one wants to use a shared wok he can bind it manually.
134 if [ "$arch" ]; then
135 slitaz=$slitaz/$arch
136 fi
137 [ -d "$fs/packages" ] || mkdir -p $fs/packages
138 [ -d "$slitaz/packages" ] || mkdir -p $fs/packages
139 bind_chroot_dir $slitaz/packages $fs/packages
140 fi
141 }
143 # Unmount virtual Kernel file systems.
144 umount_chroot() {
145 [ "$1" ] && rootfs=$1
146 fs=$rootfs/home/slitaz
147 echo -ne "\nUnmounting virtual filesystems..."
148 umount $rootfs/dev/shm
149 umount $rootfs/dev/pts
150 umount $rootfs/sys
151 umount $rootfs/proc
152 if mount | fgrep -q $fs/src; then
153 umount $fs/src
154 umount $fs/packages
155 fi
156 status && echo ""
157 }
159 # Get the last cooking base rootfs, extract and configure.
160 gen_chroot() {
161 echo -e "\nGenerating new chroot in: $rootfs"
162 separator
163 mkdir -p $rootfs
164 # We my gen cooking chroot from a stable version or invers
165 case "$version" in
166 cooking|undigest) url="http://$MIRROR/packages/cooking/" ;;
167 stable*|4.0*|backports) url="http://$MIRROR/packages/stable/" ;;
168 esac
169 # --mirror=
170 [ "$mirror" ] && url="$mirror"
171 mpath=/var/lib/tazpkg/mirror
172 cp $mpath ${mpath}.tazdev
173 echo "$url" > $mpath
174 mkdir -p $(dirname $rootfs$mpath)
175 echo "$url" > $rootfs$mpath
176 echo -n "Mirror URL: ${url#http://}"
177 tazpkg recharge 2>/dev/null 1>/dev/null
178 status
179 for pkg in $CHROOT_PKGS
180 do
181 echo -n "Installing: $pkg $vers"
182 tazpkg -gi $pkg --root=$rootfs 2>/dev/null 1>/dev/null
183 status
184 done
185 echo -n "Creating resolv.conf..."
186 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
187 status
188 echo -n "Creating TZ..."
189 cat /etc/TZ > $rootfs/etc/TZ
190 status
191 echo -n "Restoring host packages list..."
192 mv -f ${mpath}.tazdev $mpath
193 tazpkg recharge 2>/dev/null 1>/dev/null >/dev/null
194 status
195 separator
196 case "$version" in
197 cooking) version="" ;;
198 esac
199 [ "$arch" ] && version="$version --arch=$arch"
200 echo -n "Ready to chroot with:"; colorize 34 " tazdev -c $version"
201 newline
202 }
204 #
205 # Commands
206 #
208 case "$1" in
209 stats|-s)
210 echo -e "\nStatistics for: $PROJECTS\n"
211 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
212 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
213 separator
214 cd $PROJECTS
215 for proj in *
216 do
217 rev=""
218 echo -n "$proj"
219 size=`du -sh $proj | awk '{ print $1 }'`
220 echo -ne "\033[24G $size"
221 if [ -d $proj/.hg ]; then
222 cd $proj
223 rev=`hg head --template '{rev}\n'`
224 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
225 echo -ne "\033[38G $rev"
226 echo -ne "\033[48G $vers" && cd ..
227 fi
228 files=`find $proj -type f | wc -l`
229 echo -e "\033[64G $files"
230 done
231 separator
232 echo "" ;;
233 chroot|-c)
234 # Chroot into a build env. Default to cooking configured in tazdev.conf
235 check_root
236 get_version $@
237 [ -d "$2" ] && rootfs=$2
238 mount_chroot
239 echo -e "Chrooting to: $rootfs\n"
240 chroot $rootfs /bin/sh --login
241 umount_chroot ;;
242 umount-chroot|-uc)
243 check_root
244 get_version $@
245 [ -d "$2" ] && rootfs=$2
246 umount_chroot $rootfs ;;
247 gen-chroot|-gc)
248 check_root
249 # We can use: --rootfs=/path/to/chroot
250 if [ ! "$rootfs" ]; then
251 get_version $@
252 fi
253 if [ "$clean" ] || [ "$forced" ]; then
254 $0 -cc --rootfs=$rootfs --noline
255 fi
256 # Dont break another env.
257 if [ -d $rootfs/bin ]; then
258 echo -e "\nA chroot environment already exists in : $rootfs\n"
259 exit 1
260 fi
261 gen_chroot ;;
262 clean-chroot|-cc)
263 check_root
264 # We can use: --rootfs=/path/to/chroot
265 if [ ! "$rootfs" ]; then
266 get_version $@
267 fi
268 if [ ! -d "$rootfs" ]; then
269 echo -e "\nChroot doesn't exist: $rootfs\n"
270 exit 1
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 # Keep root/ and /home they may have a build wok, custom scripts, etc.
281 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run
282 do
283 if [ -d "$i" ]; then
284 echo -n "Removing: $i ($(du -sh $i | awk '{ print $1 }'))... "
285 rm -rf $i && status
286 fi
287 done
288 rm -f init
289 separator
290 [ "$noline" ] || newline ;;
291 push|-p)
292 check_mirror $@
293 rsync -r -t -O -l -v -z --delete \
294 $local -e ssh $user@$MIRROR:$remote ;;
295 dry-push|-dp)
296 check_mirror $@
297 rsync -r -t -O -l -v -z --delete --dry-run \
298 $local -e ssh $user@$MIRROR:$remote ;;
299 pull)
300 check_mirror $@
301 rsync -r -t -l -v -z --delete \
302 -e ssh $user@$MIRROR:$remote $local ;;
303 dry-pull)
304 check_mirror $@
305 rsync -r -t -l -v -z --delete --dry-run \
306 -e ssh $user@$MIRROR:$remote $local ;;
307 up-repos|-upr)
308 # Update all at once.
309 newline
310 boldify "Update all SliTaz Hg repos"
311 separator
312 for p in $(ls $PROJECTS)
313 do
314 echo -n $(boldify Project:) && colorize 36 " $p"
315 cd ${PROJECTS}/${p}
316 hg pull -u
317 done
318 separator
319 newline ;;
320 relpkg|-rp)
321 # Release a slitaz sub-project and upload tarball to mirror
322 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
323 if [ -z $2 ]; then
324 echo -e "\nUsage: $0 relpkg package [version]\n"
325 exit 0
326 fi
327 pkg=$2
329 # We can get the last found version in .hgtags
330 if [ -z $3 ]; then
331 version=$(tail -n 1 $PROJECTS/$pkg/.hgtags | awk '{print $2'})
332 else
333 version=$3
334 fi
336 echo "" && cd $PROJECTS/$pkg
338 # Sanity check
339 if ! grep -q $version$ .hgtags; then
340 echo "Missing Hg tag for version: $version"
341 echo -e "You may want to: hg tag $version && hg push\n"
342 exit 0
343 fi
345 # Archive
346 echo -n "Creating tarball and md5sum for: $pkg-$version... "
347 hg archive -t tgz $SOURCE/$pkg-$version.tar.gz
348 ( cd $SOURCE; md5sum $pkg-$version.tar.gz > $pkg-$version.md5 )
349 echo "Done"
351 # Upload
352 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
353 read upload
354 if [ "$upload" = "y" ]; then
355 cd ${SOURCE}
356 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
357 scp $pkg-$version.tar.gz $pkg-$version.md5 \
358 $MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
359 fi
361 # Update pkg in wok
362 echo -n "Do you wish to update $pkg in wok [N/y] ? "
363 read update
364 if [ "$update" = "y" ]; then
365 echo -n "Updating $pkg: $version"
366 cd $PROJECTS/wok
367 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
368 status
369 fi ;;
370 help)
371 [ ! "$2" ] && echo "Missing tool/library name" && exit 0
372 echo ""
373 boldify "Help for: $2"
374 separator
375 if [ -f "/usr/share/doc/slitaz/$2.txt" ]; then
376 less -M /usr/share/doc/slitaz/$2.txt
377 else
378 echo "No help found"
379 fi
380 separator && echo "" ;;
381 usage|*)
382 usage ;;
383 esac
385 exit 0