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

tazdev: dont sed chroot cook.conf (BUG)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 13 09:22:05 2012 +0100 (2012-03-13)
parents c2a6cca2e245
children 116c7b18fea2
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 [ -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 # Bind a directory into the chroot
101 bind_chroot_dir()
102 {
103 mkdir -p $1 $2
104 mount -o bind $1 $2
106 # Update aufs jail configuration
107 # BUGGY
108 #if [ "${2#*/home}" != "$2" ] &&
109 #grep -s ^AUFS_MOUNTS= ${2%/home/*}/etc/slitaz/cook.conf &&
110 #! grep -q /home${2#*/home} ${2%/home/*}/etc/slitaz/cook.conf; then
111 #sed -i "s|^AUFS_MOUNTS=\"|&/home${2#*/home}|" \
112 #${2%/home/*}/etc/slitaz/cook.conf
113 #fi
114 }
116 # Mount virtual Kernel file systems and chroot but check that nobody
117 # else has done mounts
118 mount_chroot()
119 {
120 if [ ! -d $rootfs/proc/1 ]; then
121 echo -ne "\nMounting virtual filesystems..."
122 mount -t proc proc $rootfs/proc
123 mount -t sysfs sysfs $rootfs/sys
124 mount -t devpts devpts $rootfs/dev/pts
125 mount -t tmpfs shm $rootfs/dev/shm
126 status
127 fi
128 # Mount source so they can be shared between cooking/stable/undigest.
129 # But do it only if it's a slitaz developement chroot.
130 fs=$rootfs/home/slitaz
131 if [ -d "$slitaz" ]; then
132 bind_chroot_dir $SLITAZ/src $fs/src
133 # Now mount package dir so they are in /home/slitaz/$version
134 # We may not mount cache wok or others it has no point and if
135 # one want to use a shared wok he can bind it manually.
136 bind_chroot_dir $slitaz/packages $fs/packages
137 fi
138 }
140 # Unmount virtual Kernel file systems on exit and ensure we are the last
141 # user before unmounting !
142 umount_chroot()
143 {
144 [ "$1" ] && ROOTF=$1
145 fs=$rootfs/home/slitaz
146 echo -ne "\nUnmounting virtual filesystems..."
147 umount $rootfs/dev/shm
148 umount $rootfs/dev/pts
149 umount $rootfs/sys
150 umount $rootfs/proc
151 umount $fs/src
152 umount $fs/packages
153 status && echo ""
154 #echo -e "\nProcess: $ps\n"
155 #ps | grep `basename $0` | grep -v grep
156 #echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
157 }
159 # Get the last cooking base rootfs, extract and configure.
160 gen_new_chroot()
161 {
162 echo -e "\nGenerating new chroot in : $rootfs"
163 separator
164 mkdir -p $rootfs
165 if [ "$ROOTFS_PKG" == "yes" ]; then
166 for pkg in $CHROOT_PKGS
167 do
168 tazpkg get-install $pkg --root=$rootfs
169 done
170 elif [ "$ROOTFS_PKG" == "no" ]; then
171 cd $rootfs
172 wget $DL_URL/boot/cooking/rootfs-base.gz
173 echo -n "Extracting the rootfs..."
174 lzma d rootfs-base.gz -so | cpio -id
175 rm rootfs-base.gz
176 fi
177 echo -n "Creating resolv.conf..."
178 cat /etc/resolv.conf > $rootfs/etc/resolv.conf
179 status
180 separator
181 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
182 echo -e "Example: tazdev chroot $rootfs\n"
183 }
185 # Remove obsolate slitaz packages
186 purge_packages()
187 {
188 arg=$1
189 tmp=/tmp/tazdev.$$
190 ls $BUILD_WOK | while read pkg; do
191 [ -f $BUILD_WOK/$pkg/taz/*/receipt ] || continue
192 EXTRAversion=""
193 . $BUILD_WOK/$pkg/taz/*/receipt
194 echo $pkg-$version$EXTRAversion.tazpkg
195 done > $tmp
196 ls $slitaz/chroot/home/slitaz/packages | while read pkg; do
197 case "$pkg" in
198 *.tazpkg)
199 grep -q ^$pkg$ $tmp && continue
200 echo Remove $pkg
201 [ "$arg" == "purge" ] &&
202 rm -f $slitaz/chroot/home/slitaz/packages/$pkg ;;
203 esac
204 done
205 rm -f $tmp
206 }
208 # Remove obsolete source tarballs
209 purge_sources()
210 {
211 arg=$1
212 tmp=/tmp/tazdev.$$
213 ls $BUILD_WOK | while read pkg; do
214 [ -f $BUILD_WOK/$pkg/receipt ] || continue
215 TARBALL=""
216 . $BUILD_WOK/$pkg/receipt
217 [ -n "$TARBALL" ] && echo $TARBALL
218 grep SOURCES_REPOSITORY/ $BUILD_WOK/$pkg/receipt | sed \
219 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)\( .*\)$|\1|' \
220 -e 's|.*SOURCES_REPOSITORY/\([^ ]*\)$|\1|' | sort | uniq | \
221 sed "s|['\"/]||g" | while read file ; do
222 eval echo $file 2> /dev/null
223 done
224 done > $tmp
225 ls $slitaz/chroot/home/slitaz/src | while read pkg; do
226 grep -q ^$pkg$ $tmp && continue
227 echo Remove $pkg
228 [ "$arg" == "purge" ] &&
229 rm -f $slitaz/chroot/home/slitaz/src/$pkg
230 done
231 rm -f $tmp
232 }
234 case "$1" in
235 projects-stats|-ps)
236 echo -e "\nStatistics for: $PROJECTS\n"
237 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
238 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
239 separator
240 cd $PROJECTS
241 for proj in *
242 do
243 rev=""
244 echo -n "$proj"
245 size=`du -sh $proj | awk '{ print $1 }'`
246 echo -ne "\033[24G $size"
247 if [ -d $proj/.hg ]; then
248 cd $proj
249 rev=`hg head --template '{rev}\n'`
250 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
251 echo -ne "\033[38G $rev"
252 echo -ne "\033[48G $vers" && cd ..
253 fi
254 files=`find $proj -type f | wc -l`
255 echo -e "\033[64G $files"
256 done
257 separator
258 echo "" ;;
259 chroot)
260 # Chroot into a build env. Default to cooking configured in tazdev.conf
261 check_root
262 get_version $@
263 [ -d "$2" ] && rootfs=$2
264 mount_chroot
265 echo -e "Chrooting to: $rootfs\n"
266 chroot $rootfs /bin/sh --login
267 umount_chroot ;;
268 umount-chroot|-uc)
269 check_root
270 get_version $@
271 [ "$2" ] && rootfs=$2
272 umount_chroot $rootfs ;;
273 gen-chroot|-gc)
274 check_root
275 get_version $@
276 [ -d "$2" ] && rootfs=$2
277 # Dont break another env.
278 if [ -d $rootfs/bin ]; then
279 echo -e "\nA chroot environment already exists in : $rootfs\n"
280 exit 1
281 fi
282 gen_new_chroot ;;
283 clean-chroot)
284 # Keep root/ and /home they may have a build wok, custom scripts, etc.
285 check_root
286 if [ -z "$2" ]; then
287 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
288 exit 0
289 else
290 rootfs=$2
291 if [ ! -d "$rootfs" ]; then
292 echo -e "\nWarning : $rootfs doesn't exist!\n"
293 exit 1
294 fi
295 fi
296 if [ -d $rootfs/proc/1 ]; then
297 echo -e "\nWarning : $rootfs/proc mounted!\n"
298 exit 1
299 fi
300 cd $rootfs || exit 1
301 echo -e "\nCleaning chroot in: $rootfs"
302 separator
303 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
304 do
305 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
306 rm -rf $i
307 status
308 done
309 separator && echo "" ;;
310 push|-p)
311 check_mirror $@
312 rsync -r -t -O -l -v -z --delete \
313 $local -e ssh $user@$MIRROR:$remote ;;
314 dry-push|-dp)
315 check_mirror $@
316 rsync -r -t -O -l -v -z --delete --dry-run \
317 $local -e ssh $user@$MIRROR:$remote ;;
318 pull)
319 check_mirror $@
320 rsync -r -t -l -v -z --delete \
321 -e ssh $user@$MIRROR:$remote $local ;;
322 dry-pull)
323 check_mirror $@
324 rsync -r -t -l -v -z --delete --dry-run \
325 -e ssh $user@$MIRROR:$remote $local ;;
326 purge|dry-purge)
327 check_root
328 get_version $@
329 purge_packages $1
330 purge_sources $1 ;;
331 relpkg|-rp)
332 # Release a slitaz sub-project and upload tarball to mirror
333 [ -z "$MIRROR_SOURCES" ] && MIRROR_SOURCES="/var/www/slitaz/mirror/sources"
334 if [ -z $2 ] || [ -z $3 ]; then
335 echo -e "\nUsage: $0 relpkg package version\n"
336 exit 0
337 fi
338 pkg=$2
339 version=$3
340 echo "" && cd $PROJECTS/$pkg
342 # Sanity check
343 if ! grep -q $version$ .hgtags; then
344 echo "Missing Hg tag for version: $version"
345 echo -e "You may want to: hg tag $version && hg push\n"
346 exit 0
347 fi
349 # Archive
350 echo -n "Creating tarball and md5sum for: $pkg-$version... "
351 hg archive -t tgz $pkg-$version.tar.gz
352 md5sum $pkg-$version.tar.gz > $pkg-$version.md5
353 echo "Done"
355 # Upload
356 echo -n "Do you wish to upload tarball to the mirror [N/y] ? "
357 read upload
358 if [ "$upload" = "y" ]; then
359 echo "Uploading to: $MIRROR/sources/${pkg#slitaz-}"
360 scp $pkg-$version.tar.gz $pkg-$version.md5 \
361 $user@$MIRROR:$MIRROR_SOURCES/${pkg#slitaz-}
362 fi
364 # Update pkg in wok
365 echo -n "Do you wish to update $pkg in wok [N/y] ? "
366 read update
367 if [ "$update" = "y" ]; then
368 cd $PROJECTS/wok
369 sed -i s"/VERSION=.*/VERSION=\"$version\"/" $pkg*/receipt
370 fi ;;
371 reliso|-ri)
372 # Generate all official images iso at once for a specific version.
373 get_version $@
374 iso=$slitaz/iso
375 mkdir -p $iso
376 for flavor in base core gtkonly firefox
377 do
378 cd $slitaz
379 tazlito pack-flavor $flavor
380 tazlito get-flavor $flavor
381 tazlito gen-distro
382 if [ "$flavor" == "core" ]; then
383 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version.iso
384 cd $ISO && md5sum slitaz-$version.iso > slitaz-$version.md5
385 else
386 cp distro/slitaz-$flavor.iso $ISO/slitaz-$version-$flavor.iso
387 cd $ISO && md5sum slitaz-$version-$flavor.iso slitaz-$version-$flavor.md5
388 fi
389 done
390 # Clean up slitaz working directory.
391 rm *.flavor tazlito.conf ;;
392 usage|*)
393 usage ;;
394 esac
396 exit 0