wok-6.x view slitaz-dev-tools/stuff/tazdev @ rev 3921

linux: fix .config
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Aug 18 21:42:30 2009 +0200 (2009-08-18)
parents baa5f0488bc8
children 031f6e973842
line source
1 #!/bin/sh
2 # Tazdev - SliTaz developers and build host tool.
3 # System wide config file: /etc/slitaz/tazdev.conf
4 #
5 # (c) 2009 SliTaz GNU/Linux - GNU gpl v3
6 #
7 # Authors : Christophe Lincoln (Pankso) <pankso@slitaz.org>
8 #
10 if [ -f /etc/slitaz/tazdev.conf ]; then
11 . /etc/slitaz/tazdev.conf
12 if [ -f $PWD/tazdev.conf ]; then
13 . $PWD/tazdev.conf
14 fi
15 else
16 echo -e "\nNo config file found in /etc/slitaz or the current dir...\n"
17 exit 0
18 fi
20 usage()
21 {
22 echo -e "\nSliTaz developers and build host tool\n
23 \033[1mUsage: \033[0m `basename $0` [command] [user] [stable|cooking|path]
24 \033[1mCommands: \033[0m\n
25 usage Print this short usage and command list.
26 projects-stats Display statistics about your projects (-ps).
27 cmplog Log 'tazwok cmp' result (or use tazbb).
28 update-wok Update Hg wok and copy it to the chroot wok.
29 update-www Update SliTaz Website repo from Hg.
30 chroot Mount virtual fs if needed and chroot into the build env.
31 gen-chroot Generate a chroot using the last cooking base rootfs.
32 clean-chroot Clean a chroot environment (skip root/ and home/).
33 push Upload new packages to the main mirror (-p).
34 dry-push Show what will be uploaded to the mirror. Does nothing (-dp).
35 pull Download new packages from the main mirror.
36 dry-pull Show what will be downloaded from the mirror. Does nothing.\n"
37 }
39 # Exit if user is not root.
40 check_root()
41 {
42 if test $(id -u) != 0 ; then
43 echo -e "\nThis program requires being run as root.\n"
44 exit 0
45 fi
46 }
48 status()
49 {
50 local CHECK=$?
51 echo -en "\033[70G"
52 if [ $CHECK = 0 ]; then
53 echo "Done"
54 else
55 echo "Failed"
56 fi
57 return $CHECK
58 }
60 get_version()
61 {
62 if [ "$2" = "stable" ]; then
63 VERSION=stable
64 SLITAZ=$STABLE
65 elif [ -n "$2" ]; then
66 # Undigest - custom ?
67 VERSION=$2
68 SLITAZ=/home/slitaz/$2
69 else
70 VERSION=cooking
71 SLITAZ=$COOKING
72 fi
73 ROOTFS=$SLITAZ/chroot
74 HG_WOK=$SLITAZ/wok
75 BUILD_WOK=$SLITAZ/chroot/home/slitaz/wok
76 }
78 check_mirror()
79 {
80 # ping -c 1 $MIRROR
81 if [ -n "$2" ]; then
82 USER=$2
83 else
84 USER=$USER
85 fi
86 if [ "$2" = "stable" ] || [ "$3" = "stable" ]; then
87 REMOTE_DIR=$MIRROR_DIR/stable/
88 LOCAL_DIR=$STABLE/packages/
89 else
90 REMOTE_DIR=$MIRROR_DIR/cooking/
91 LOCAL_DIR=$COOKING/packages/
92 fi
93 }
95 # Mount virtual Kernel file systems and chroot but check that nobody
96 # else has done mounts
97 mount_chroot()
98 {
99 if [ ! -d $ROOTFS/proc/1 ]; then
100 echo -n "Mounting virtual filesystems..."
101 mount -t proc proc $ROOTFS/proc
102 mount -t sysfs sysfs $ROOTFS/sys
103 mount -t devpts devpts $ROOTFS/dev/pts
104 mount -t tmpfs shm $ROOTFS/dev/shm
105 status
106 fi
107 }
109 # Unmount virtual Kernel file systems on exit and ensure we are the last
110 # user before unmounting !
111 umount_chroot()
112 {
113 # Not working. Buggy ps ?
114 #sleep 6
115 ps=$(ps | grep `basename $0` | grep -v grep | wc -l)
116 if [ "$ps" == "1" ]; then
117 echo -ne "\Unmounting virtual filesystems..."
118 umount $ROOTFS/dev/shm
119 umount $ROOTFS/dev/pts
120 umount $ROOTFS/sys
121 umount $ROOTFS/proc
122 status
123 else
124 echo -e "\nProcess: $ps\n"
125 ps | grep `basename $0` | grep -v grep
126 echo -e "\nLeaving virtual filesystems unmounted (`pidof tazdev`)...\n"
127 fi
128 }
130 # Get the last cooking base rootfs, extract and configure.
131 gen_new_chroot()
132 {
133 echo -e "\nGenerating new chroot in : $ROOTFS"
134 echo "================================================================================"
135 mkdir -p $ROOTFS && cd $ROOTFS
136 wget $DL_URL/boot/cooking/rootfs-base.gz
137 echo -n "Extracting the rootfs..."
138 lzma d rootfs-base.gz -so | cpio -id
139 rm rootfs-base.gz
140 echo -n "Creating resolv.conf..."
141 cat /etc/resolv.conf > etc/resolv.conf
142 status
143 echo "================================================================================"
144 echo -e "Ready to chroot. Use 'tazdev chroot [version|path]'"
145 echo -e "Example: tazdev chroot $ROOTFS\n"
146 }
148 case "$1" in
149 cmplog)
150 # Log 'tazwok cmp' for the web interface (can be used via a cron job).
151 check_root
152 echo -e "Starting 'tazwok cmp' (can be long)...\n"
153 tazwok cmp | grep ^[A-Z] | tee $CMP_LOG
154 echo "Date: `date`" >> $CMP_LOG ;;
155 '-ps'|projects-stats)
156 echo -e "\nStatistics for: $PROJECTS\n"
157 echo -n "Project" && echo -ne "\033[24G Size" && echo -ne "\033[38G Revision"
158 echo -ne "\033[48G Version" && echo -e "\033[64G Files"
159 echo "================================================================================"
160 cd $PROJECTS
161 for proj in *
162 do
163 rev=""
164 echo -n "$proj"
165 size=`du -sh $proj | awk '{ print $1 }'`
166 echo -ne "\033[24G $size"
167 if [ -d $proj/.hg ]; then
168 cd $proj
169 rev=`hg head --template '{rev}\n'`
170 vers=`hg tags | head -n 2 | tail -n 1 | cut -d " " -f 1`
171 echo -ne "\033[38G $rev"
172 echo -ne "\033[48G $vers" && cd ..
173 fi
174 files=`find $proj -type f | wc -l`
175 echo -e "\033[64G $files"
176 done
177 echo "================================================================================"
178 echo "" ;;
179 update-wok)
180 # Update the Hg wok and copy it to the chroot env. Hg wok is
181 # copied to the chroot wok to avoid messing with build result
182 # file and so we can also modify receipt directly without affecting
183 # the Hg wok.
184 check_root
185 get_version $@
186 echo ""
187 echo "Hg wok : $HG_WOK"
188 echo "Build wok : $BUILD_WOK"
189 cd $HG_WOK
190 hg pull && hg update
191 echo -n "Copying Hg wok to the build wok... "
192 cp -a $HG_WOK/* $BUILD_WOK
193 cp -a $HG_WOK/.hg $BUILD_WOK
194 status && echo "" ;;
195 update-www)
196 # Update website from repo.
197 echo ""
198 cd $WEBSITE && hg pull && hg update
199 echo "" ;;
200 chroot)
201 # Chroot into a build env. Default to cooking configured in
202 # tazdev.conf
203 check_root
204 get_version $@
205 mount_chroot
206 echo -e "\nChrooting in $ROOTFS...\n"
207 chroot $ROOTFS /bin/sh --login
208 umount_chroot
209 echo -e "Exiting $ROOTFS chroot environment...\n" ;;
210 gen-chroot)
211 check_root
212 get_version $@
213 # Dont break another env.
214 if [ -d $ROOTFS/bin ]; then
215 echo -e "\nA chroot environment already exists in : $ROOTFS\n"
216 exit 1
217 fi
218 gen_new_chroot ;;
219 clean-chroot)
220 # Keep root/ and /home they may have a build wok, custom scripts, etc.
221 check_root
222 if [ -z "$2" ]; then
223 echo -e "\nPlease specify the path to the chroot environment to clean.\n"
224 exit 0
225 else
226 ROOTFS=$2
227 if [ ! -d "$ROOTFS" ]; then
228 echo -e "\nWarning : $ROOTFS doesn't exist!\n"
229 exit 1
230 fi
231 fi
232 if [ -d $ROOTFS/proc/1 ]; then
233 echo -e "\nWarning : $ROOTFS/proc mounted!\n"
234 exit 1
235 fi
236 cd $ROOTFS || exit 1
237 echo -e "\nCleaning chroot in: $ROOTFS"
238 echo "================================================================================"
239 for i in bin dev etc init lib media mnt proc sbin sys tmp usr var
240 do
241 echo -n "Removing: $i (`du -sh $i | awk '{ print $1 }'`)... "
242 rm -rf $i
243 status
244 done
245 echo "================================================================================"
246 echo "" ;;
247 '-p'|push)
248 check_mirror $@
249 rsync -r -t -l -v -z --delete \
250 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
251 '-dp'|dry-push)
252 check_mirror $@
253 rsync -r -t -l -v -z --delete --dry-run \
254 $LOCAL_DIR -e ssh $USER@$MIRROR:$REMOTE_DIR ;;
255 pull)
256 check_mirror $@
257 rsync -r -t -l -v -z --delete \
258 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
259 dry-pull)
260 check_mirror $@
261 rsync -r -t -l -v -z --delete --dry-run \
262 -e ssh $USER@$MIRROR:$REMOTE_DIR $LOCAL_DIR ;;
263 usage|*)
264 usage ;;
265 esac
267 exit 0