cookutils view cookiso @ rev 697

cookutils: catch control-c in aufs jail (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 25 11:27:23 2014 +0200 (2014-10-25)
parents 5657f2b3d4d7
children 1bcdba9d34f0
line source
1 #!/bin/sh
2 #
3 # Cookiso utility - Build official ISOs in a chroot environment.
4 # The goal is to have a tool well integrated with cookutils but which
5 # can run on its own and automate official SliTaz ISO creation.
6 #
8 # --> cook.conf
9 # SSH/RSA configuration to upload on a server.
10 # Assign this before cook.conf so it can be
11 # reassigned in cook.conf.
12 SSH_CMD="dbclient -i /root/.ssh/id_rsa.dropbear"
13 SSH_ISO="/var/www/slitaz/mirror/iso"
14 SSH_HOST="slitaz@mirror1.slitaz.org"
15 #BWLIMIT="--bwlimit=40"
17 . /usr/lib/slitaz/libcook.sh
19 # Parse cmdline options.
20 for opt in "$@"
21 do
22 case "$opt" in
23 --pkgdb)
24 cook pkgdb --flavors ;;
25 --push)
26 push="yes" ;;
27 --flavors=*)
28 flavors=${opt#--flavors=} ;;
29 --version=*)
30 version=${opt#--version=} ;;
31 esac
32 done
34 # Default to rolling, or: cookiso [cmd] --version=stable
35 case "$version" in
36 stable)
37 string=stable ;;
38 cooking)
39 string=cooking ;;
40 *)
41 version=cooking
42 string=rolling ;;
43 esac
45 # Running command
46 [ -d "$cache" ] && echo "$@" > $command
47 trap 'rm -f $command && exit 1' INT TERM
49 #
50 # Functions
51 #
53 usage() {
54 cat << EOT
56 $(echo -e "\033[1mUsage:\033[0m") cookiso [command] [--option]
58 $(echo -e "\033[1mCommands:\033[0m")
59 usage Display this short usage.
60 setup Setup Cookiso build environment.
61 push Manually push ISO to a server via SSH.
62 gen Generate specified flavors.
63 4in1 Generate all 4in1 flavors.
64 rolling Build the rolling ISOs if any changes.
66 $(echo -e "\033[1mOptions:\033[0m")
67 --pkgdb Generate packages DB before building ISO.
68 --push Upload freshly generated ISO to a server.
69 --flavors= List of flavors to generate with 'gen' command.
70 --version= Specify SliTaz version: [rolling|cooking|stable]
72 EOT
73 }
75 spider() {
76 echo ' // \\'
77 echo ' _\\()//_'
78 echo '/ // \\ \\'
79 echo ' | \__/ |'
80 }
82 # Check for some flavors on cmdline
83 flavors_list() {
84 if [ "$flavors" == "all" ]; then
85 flavors=$(ls $SLITAZ/flavors)
86 fi
87 if [ ! "$flavors" ]; then
88 echo "No flavor specified on cmdline. Use: --flavors="
89 rm -f $command && exit 0
90 fi
91 }
93 # Log activities, we want first letter capitalized.
94 log() {
95 grep ^[A-Z] | \
96 sed s"#^[A-Z]\([^']*\)#$(date '+%Y-%m-%d %H:%M') : \0#" >> $activity
97 }
99 log_bot() {
100 sed '/^.\//'d | sed '/^.hg/'d | tee -a $rollog
101 }
103 # Generate requested flavors.
104 gen_flavors() {
105 cd $SLITAZ/flavors
106 [ -d ".hg" ] && hg pull -u
107 mkdir -p $cache && cd $cache
108 rm -rf *.flavor *.list *.conf *.sh
109 for flavor in $flavors
110 do
111 if [ "$flavor" != "core-4in1" ]; then
112 name="slitaz-$string-$flavor"
113 else
114 name="slitaz-$string"
115 fi
116 log=$iso/$name.log
117 rm -f $log && touch $log
118 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
119 echo "Cookiso started: $(date '+%Y-%m-%d %H:%M')" | tee -a $log
120 tazlito pack-flavor $flavor | tee -a $log
121 tazlito get-flavor $flavor | tee -a $log
122 # BUG: script sometimes screws up conspy on Tank
123 #script -c "yes '' | tazlito gen-distro" -a $log
124 yes '' | tazlito gen-distro 2>&1 | tee -a $log
125 # Rename ISO and md5
126 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
127 mv -f $SLITAZ/distro/slitaz-$flavor.iso $iso/$name.iso
128 cd $iso && md5sum $name.iso > $name.md5
129 echo "Cookiso ended: $(date '+%Y-%m-%d %H:%M')" | tee -a $log
130 done && echo ""
131 # Push ISO to mirror if requested.
132 [ "$push" ] && push_iso
133 }
135 # Push an ISO to a server.
136 push_iso() {
137 echo "Pushing to host: ${SSH_HOST}"
138 export DROPBEAR_PASSWORD=none
139 for flavor in $flavors
140 do
141 distro=slitaz-${string}-$flavor
142 file=${distro%-core-4in1}
143 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.* \
144 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
145 done
146 }
148 #
149 # Commands
150 #
152 case "$1" in
153 setup)
154 # Setup Hg repo and dirs
155 echo -e "\nSetting up Cookiso environment..."
156 cd $SLITAZ
157 if [ ! -d "flavors" ]; then
158 case $version in
159 cooking|rolling)
160 hg clone $FLAVORS_URL ;;
161 stable)
162 hg clone $FLAVORS_URL-stable flavors ;;
163 esac
164 fi
165 # Needed packages
166 for pkg in mercurial tazlito rsync dropbear
167 do
168 [ -d "$INSTALLED/$pkg" ] || tazpkg -gi $pkg
169 done
170 echo "Creating directories and files..."
171 mkdir -p $cache $iso
172 touch $activity
173 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
174 /etc/tazlito/tazlito.conf
175 echo ""
176 echo "Flavors files : $SLITAZ/flavors"
177 echo "Cache files : $cache"
178 echo "ISO images : $iso"
179 echo "" ;;
180 push)
181 # Manually upload an ISO to a server.
182 flavors_list
183 push_iso ;;
184 gen)
185 # Build one or more flavors.
186 flavors_list
187 echo -e "\nGenerating flavors:\n$flavors"
188 gen_flavors ;;
189 4in1)
190 echo -e "\nGenerating 4in1 distros..."
191 flavors="base justx gtkonly core core-4in1"
192 gen_flavors ;;
193 rolling)
194 #
195 # Official SliTaz rolling release flavors are automatically built.
196 #
197 # Check if packages list was modified or if any commits have been
198 # done in one of the rolling flavors and rebuild ISOs if needed.
199 #
200 pkgs=$SLITAZ/packages/packages.md5
201 last=$cache/packages.md5
202 diff=$cache/packages.diff
203 cook="preinit core-4in1 core core64"
205 # Log stuff
206 rm -f $rollog && touch $rollog
207 rm -f $commit $commits.tmp && touch $commits.tmp
208 echo "Rolling tracking for changes" | log
209 echo "Cookiso rolling started: $(date '+%Y-%m-%d %H:%M')" | log_bot
211 # Packages changes
212 [ -f "$last" ] || cp -f $pkgs $cache
213 diff $last $pkgs > $diff
214 if [ -s "$diff" ]; then
215 echo "Found new or rebuilt packages" | log_bot
216 cat $diff | grep "^+" >> $rollog
217 #
218 # TODO: Check new pkg and see if it's part of one of the rolling
219 # flavors, if not we have nothing to build.
220 #
221 for flavor in $cook
222 do
223 echo "$flavor" >> $commits.tmp
224 echo "New packages for : $flavor" | log_bot
225 done
226 else
227 echo "No changes found in packages MD5 sum" | log_bot
228 echo "" > $commits.tmp
229 fi
230 cp -f $pkgs $cache
232 # Hg changes
233 cd $repo || exit 1
234 cur=$(hg head --template '{rev}\n')
235 echo "Updating wok : $repo (rev $cur)" | log_bot
236 cd $repo && hg pull -u | log_bot
237 new=$(hg head --template '{rev}\n')
238 cur=$(($cur + 1))
239 for rev in $(seq $cur $new)
240 do
241 for file in $(hg log --rev=$rev --template "{files}")
242 do
243 flavor=$(echo $file | cut -d "/" -f 1)
244 desc=$(hg log --rev=$rev --template "{desc}" $file)
245 echo "Committed flavor : $flavor - $desc" | log_bot
246 # Build only rolling flavor
247 if echo "$cook" | fgrep -q $flavor; then
248 echo $flavor >> $commits.tmp
249 fi
250 done
251 done
253 # Keep previous commit and discard duplicate lines
254 cat $commits.tmp | sed /"^$"/d > $commits.new
255 uniq $commits.new > $commits && rm $commits.*
256 nb=$(cat $commits | wc -l)
257 echo "Flavors to cook : $nb" | log_bot
258 flavors=$(cat $commits)
259 gen_flavors ;;
260 spider)
261 # SliTaz Easter egg command :-)
262 spider ;;
263 *)
264 usage ;;
265 esac
267 rm -f $command
268 exit 0