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

Tiny edits
author Paul Issott <paul@slitaz.org>
date Tue Feb 28 22:36:16 2017 +0000 (2017-02-28)
parents 66c023d0f82f
children 1705daa4b44a
line source
1 #!/bin/sh
2 #
3 # Tazdev - SliTaz developers and build host tool. System-wide config file
4 # is located at /etc/slitaz/tazdev.conf. Please, keep the code clear and
5 # well commented. Also keep in mind: configuration variables are $UPPERCASE
6 # and variables initialized by tazdev itself are $lowercase.
7 #
8 # (c) 2014-2017 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.1
18 . /lib/libtaz.sh
20 [ -f /etc/slitaz/tazdev.conf ] && . /etc/slitaz/tazdev.conf
21 [ -f ~/.config/slitaz/tazdev.conf ] && . ~/.config/slitaz/tazdev.conf
22 [ -f tazdev.conf ] && . ./tazdev.conf
24 [ -n "$SLITAZ_HOME" ] || die "No config file found"
27 # Remove all --parameters from cmdline
28 IFS=$'\n'
29 set -- $(echo "$*" | sed '/^--/d')
30 unset IFS
33 usage() {
34 cat <<EOT
36 $(boldify "Usage:") $(basename $0) <command> [<options>] [--options]
38 SliTaz developers and build host tool v$VERSION
40 $(boldify "Commands:")
41 usage Print this short usage and command list
42 help <tool> Give help on a SliTaz tool or library
43 -s stats Display statistics for your projects
44 -c chroot [<ver>|<rootfs>] Mount virtual FS and chroot into the build env
45 -gc gen-chroot [<ver>] Generate a chroot using packages from config
46 file
47 -uc umchroot [<rootfs>] Unmount chroot specified on cmdline
48 -cc clean-chroot [<ver>] Clean a chroot environment (skip root/ and
49 home/)
50 -p push [<user> [<ver>]] Upload new packages to the main mirror
51 -dp dry-push [<user> [<ver>]] Show what will be uploaded to the mirror
52 pull [<user> [<ver>]] Download new packages from the main mirror
53 dry-pull [<user> [<ver>]] Show what will be downloaded from the mirror
54 -ur up-repos Update all your SliTaz projects repos in one
55 command
56 -rp relpkg <pkg> [<version>] Archive and upload new package/project version
57 -sc setup-cgi Setup your CGI environment
59 $(boldify "Options:")
60 --rootfs= Path to the chroot to generate or clean
61 --arch= Specify the architecture type for cross-chroot, push/pull
62 --clean or --forced Clean chroot before generating a new one
64 $(boldify "Examples:")
65 $(basename $0) gen-chroot undigest --clean
66 $(basename $0) -c --arch=arm
68 EOT
69 }
71 get_version() {
72 # Stable, undigest or custom.
73 version=${2:-cooking}
74 slitaz="$SLITAZ_HOME/$version"
75 if [ -n "$arch" ]; then
76 rootfs="$slitaz/$arch/chroot"
77 else
78 rootfs="$slitaz/chroot"
79 fi
80 }
82 check_mirror() {
83 [ -n "$2" ] && user="$2"
84 local repo="$3"
85 case $repo in
86 stable|backports|undigest)
87 remote="$MIRROR_PKGS/$repo/"
88 local="$SLITAZ_HOME/$repo/packages/"
89 ;;
90 rpi)
91 remote="$MIRROR_PKGS/cross/rpi/"
92 local="$SLITAZ_HOME/cooking/arm/packages/"
93 ;;
94 *)
95 remote="$MIRROR_PKGS/cooking/"
96 local="$SLITAZ_HOME/cooking/packages/"
97 ;;
98 esac
100 if [ -n "$arch" ]; then
101 remote="$remote$arch/"
102 local="$local$arch/"
103 fi
104 }
106 # Bind a directory into the chroot
107 bind_chroot_dir()
108 {
109 mkdir -p $1 $2
110 mount -o bind $1 $2
111 }
113 # Mount virtual Kernel file systems and chroot, but check that nobody
114 # else has done mounts
115 mount_chroot()
116 {
117 if [ ! -d "$rootfs/proc/1" ]; then
118 newline
119 action 'Mounting 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, one can bind it manually.
134 [ -n "$arch" ] && slitaz="$slitaz/$arch"
135 mkdir -p "$fs/packages" "$slitaz/packages"
136 bind_chroot_dir "$slitaz/packages" "$fs/packages"
137 fi
138 }
140 # Unmount virtual Kernel file systems.
141 umount_chroot() {
142 [ -n "$1" ] && rootfs="$1"
143 fs="$rootfs/home/slitaz"
144 newline
145 action 'Unmounting virtual filesystems...'
146 umount $rootfs/dev/shm
147 umount $rootfs/dev/pts
148 umount $rootfs/sys
149 umount $rootfs/proc
150 if mount | fgrep -q $fs/src; then
151 umount $fs/src
152 umount $fs/packages
153 fi
154 status
155 newline
156 }
158 # Get the last cooking base rootfs, extract and configure.
159 gen_chroot() {
160 title "Generating new chroot in $rootfs"
162 mkdir -p $rootfs
163 # We may gen cooking chroot from a stable version or vice versa
164 case "$version" in
165 stable*|4.0*|backports)
166 url="http://$MIRROR/packages/stable/" ;;
167 *)
168 url="http://$MIRROR/packages/cooking/" ;;
169 esac
171 # --mirror=
172 [ -n "$mirror" ] && url="$mirror"
173 mpath="/var/lib/tazpkg/mirror"
174 mkdir -p $(dirname $rootfs$mpath)
175 echo "$url" > $rootfs$mpath
177 action "Mirror URL: ${url#http://}"
178 tazpkg recharge --root="$rootfs" --quiet >/dev/null
179 status
181 for pkg in $CHROOT_PKGS; do
182 action "Installing: $pkg $vers"
183 tazpkg -gi $pkg --root="$rootfs" --quiet
184 status
185 done
187 action "Creating resolv.conf..."
188 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
189 status
191 action "Creating TZ..."
192 cat /etc/TZ > $rootfs/etc/TZ
193 status
195 case "$version" in
196 cooking) version="" ;;
197 esac
198 [ "$arch" ] && version="$version --arch=$arch"
199 footer "Ready to chroot with: $(colorize 34 "tazdev -c $version")"
200 }
202 #
203 # Commands
204 #
206 case "$1" in
207 stats|-s)
208 title "Statistics for $PROJECTS"
209 printf "%-23s %-13s %-15s %s\n" 'Project' 'Revision' 'Version' 'Files'
210 separator '-'
211 cd $PROJECTS
212 for proj in *; do
213 rev=""
214 if [ -d "$PROJECTS/$proj/.hg" ]; then
215 cd $PROJECTS/$proj
216 rev=$(hg head --template '{rev};' | sed 's|;$||') # we have multiple heads in some projects
217 vers=$(hg tags | grep -v tip | head -n1 | cut -d" " -f1) # some projects don't have any version tags
218 files=$(find . -type f | wc -l)
219 printf "%-23s %-13s %-15s %s\n" "$proj" "$rev" "${vers:--}" "$files"
220 fi
221 done
222 footer
223 ;;
225 chroot|-c)
226 # Chroot into a build env. Default to cooking configured in tazdev.conf
227 check_root $1
228 get_version $@
229 [ -d "$2" ] && rootfs="$2"
230 mount_chroot
231 echo -e "Chrooting to: $rootfs\n"
232 chroot $rootfs /bin/sh --login
233 umount_chroot
234 ;;
236 umchroot|-uc)
237 check_root $1
238 get_version $@
239 [ -d "$2" ] && rootfs="$2"
240 umount_chroot $rootfs
241 ;;
243 gen-chroot|-gc)
244 check_root $1
245 # We can use: --rootfs=/path/to/chroot
246 [ -n "$rootfs" ] || get_version $@
248 # If --clean or --forced option given
249 [ -n "$clean$forced" ] && $0 -cc --rootfs=$rootfs
251 # Don't break another env.
252 [ -d "$rootfs/bin" ] &&
253 die "A chroot environment already exists in $rootfs.\nUse --clean or --forced to clean this chroot."
255 gen_chroot
256 ;;
258 clean-chroot|-cc)
259 check_root $1
260 # We can use: --rootfs=/path/to/chroot
261 [ -n "$rootfs" ] || get_version $@
263 [ ! -d "$rootfs" ] && die "Chroot '$rootfs' doesn't exist"
265 [ -d "$rootfs/proc/1" ] && die "WARNING: $rootfs/proc mounted!"
267 cd $rootfs || exit 1
269 title "Cleaning chroot $rootfs"
270 # Keep root/ and /home they may have a build wok, custom scripts, etc.
271 for i in boot bin dev etc lib media mnt proc sbin sys tmp usr var run; do
272 if [ -d "$i" ]; then
273 action "Removing: $i ($(du -sh $i | awk '{ print $1 }'))..."
274 rm -rf $i
275 status
276 fi
277 done
278 rm -f init
279 footer
280 ;;
282 push|-p)
283 check_mirror $@
284 rsync -r -t -O -l -v -z --delete \
285 $local -e ssh $user@$MIRROR:$remote
286 ;;
288 dry-push|-dp)
289 check_mirror $@
290 rsync -r -t -O -l -v -z --delete --dry-run \
291 $local -e ssh $user@$MIRROR:$remote
292 ;;
294 pull)
295 check_mirror $@
296 rsync -r -t -l -v -z --delete \
297 -e ssh $user@$MIRROR:$remote $local
298 ;;
300 dry-pull)
301 check_mirror $@
302 rsync -r -t -l -v -z --delete --dry-run \
303 -e ssh $user@$MIRROR:$remote $local
304 ;;
306 up-repos|-ur)
307 # Update all at once.
308 title "Update all SliTaz Hg repos"
309 for p in $(ls $PROJECTS); do
310 title "Project $p"
311 cd $PROJECTS/$p
312 hg pull -u
313 done
314 footer
315 ;;
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 [ -z "$2" ] && die "Usage: $0 relpkg package [version]"
322 pkg=$2
323 version="$3"
325 # We can get the last found version in .hgtags
326 [ -n "$version" ] ||
327 version=$(awk 'END{print $2}' $PROJECTS/$pkg/.hgtags)
329 newline
330 cd $PROJECTS/$pkg
332 # Sanity check
333 grep -q $version$ .hgtags ||
334 die "Missing Hg tag for version $version\nYou may want to: hg tag $version; hg push\n"
336 # Archive
337 action "Creating tarball and md5sum for $pkg-$version..."
338 hg archive -t tgz $SOURCE/$pkg-$version.tar.gz
339 ( cd $SOURCE; md5sum $pkg-$version.tar.gz > $pkg-$version.md5 )
340 status
342 # Upload
343 confirm 'Do you wish to upload tarball to the mirror?' 'n' &&
344 {
345 cd $SOURCE
346 echo "Uploading to $MIRROR/sources/${pkg#slitaz-}"
347 scp "$pkg-$version.tar.gz" "$pkg-$version.md5" \
348 $MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
349 }
351 # Update pkg in wok
352 confirm "Do you wish to update $pkg in wok?" 'n' &&
353 {
354 action "Updating $pkg: $version"
355 cd $PROJECTS/wok
356 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
357 status
358 }
359 ;;
361 setup-cgi|-sc)
362 . /etc/slitaz/slitaz.conf
363 echo "$(boldify 'Public:') $PUBLIC"
364 mkdir -p $PUBLIC/cgi-bin
365 cd $PUBLIC/cgi-bin
366 for proj in tazbug tinycm mediabox; do
367 [ -d "$proj" ] || hg clone http://hg.slitaz.org/$proj
368 done
369 [ -d "$INSTALLED/lighttpd" ] || sudo tazpkg -gi lighttpd
371 echo
372 echo "TODO: setup SCN (tinycm install + plugins from slitaz-forge)"
373 echo
374 echo "$(boldify 'URL :') http://localhost/~$USER/cgi-bin/"
375 ;;
377 help)
378 doc='/usr/share/doc/slitaz/'
379 topics="Available help topics: $(cd $doc; ls *.txt | sed 's|.txt$||' | tr '\n' ' ')"
380 [ -n "$2" ] ||
381 die "Missing tool/library name\nExample: tazdev help httphelper\n\n$topics"
383 if [ -f "$doc$2.txt" ]; then
384 {
385 output='raw' title "Help for $2"
386 cat $doc$2.txt
387 footer
388 } | less -M
389 else
390 echo "No help found for '$2'"
391 longline "$topics"
392 fi
393 ;;
395 usage|*)
396 usage
397 ;;
399 esac
401 exit 0