cookutils view cookiso @ rev 392

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