cookutils view cookiso @ rev 893
web/cooker.cgi: work with HTTP headers "Last-Modified", "If-Modified-Since", "HTTP 304 Not Modified", "HTTP 404 Not Found". Other small improvements.
SliTaz Next Cooker is working right now with this version of cooker.cgi.
SliTaz Next Cooker is working right now with this version of cooker.cgi.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Mon Mar 20 05:12:29 2017 +0200 (2017-03-20) |
parents | a328952982d6 |
children | 63fb59f6fd67 |
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
20 # Parse cmdline options.
22 for opt in "$@"; do
23 case "$opt" in
24 --force)
25 force='yes' ;;
26 --pkgdb)
27 cook pkgdb --flavors ;;
28 --push)
29 push='yes' ;;
30 --flavors=*)
31 flavors=${opt#--flavors=} ;;
32 --version=*)
33 version=${opt#--version=} ;;
34 esac
35 done
38 # Default to rolling, or: cookiso [cmd] --version=stable
40 case "$version" in
41 stable) string='stable' ;;
42 cooking) string='cooking' ;;
43 *) string='rolling'; version='cooking' ;;
44 esac
47 # Running command
49 [ -d "$cache" ] && echo "$@" > $command
50 trap 'rm -f $command && exit 1' INT TERM
53 #
54 # Functions
55 #
57 usage() {
58 cat <<EOT
60 $(boldify "Usage:") cookiso [command] [--option]
62 $(boldify "Commands:")
63 usage Display this short usage.
64 setup Setup Cookiso build environment.
65 push Manually push ISO to a server via SSH.
66 gen Generate specified flavors.
67 4in1 Generate all 4in1 flavors.
68 rolling Build the rolling ISOs if any changes.
70 $(boldify "Options:")
71 --force Build ISO rolling anyway.
72 --pkgdb Generate packages DB before building ISO.
73 --push Upload freshly generated ISO to a server.
74 --flavors= List of flavors to generate with 'gen' command.
75 --version= Specify SliTaz version: [rolling|cooking|stable]
77 EOT
78 }
81 spider() {
82 echo -e ' // \\\\\n _\\\\()//_\n/ // \\\\ \\\n | \\__/ |'
83 }
86 # Check for some flavors on cmdline
88 flavors_list() {
89 if [ "$flavors" == 'all' ]; then
90 flavors=$(ls $SLITAZ/flavors)
91 fi
92 if [ -z "$flavors" ]; then
93 echo 'No flavor specified on cmdline. Use: --flavors='
94 rm -f $command
95 exit 0
96 fi
97 }
100 # Log activities, we want first letter capitalized.
102 log() {
103 grep ^[A-Z] | \
104 sed s"#^[A-Z]\([^']*\)#$(date '+%F %R') : \0#" >> $activity
105 }
108 log_bot() {
109 sed '/^.\//'d | sed '/^.hg/'d | tee -a $rollog
110 }
113 # Generate requested flavors.
115 gen_flavors() {
116 cd $SLITAZ/flavors
117 [ -d ".hg" ] && hg pull -u
118 mkdir -p $cache; cd $cache
119 rm -rf *.flavor *.list *.conf *.sh
120 for flavor in $flavors; do
121 if [ "$flavor" != 'core-4in1' ]; then
122 name="slitaz-$string-$flavor"
123 else
124 name="slitaz-$string"
125 fi
126 log="$iso/$name.log"
127 for i in $(seq 9 -1 1); do # Rotate log
128 j=$(($i - 1))
129 [ -e $log.$j ] && mv -f $log.$j $log.$i
130 done
131 [ -e $log ] && mv $log $log.0
132 touch $log
133 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
134 echo "Cookiso started: $(date '+%F %R')" | tee -a $log
135 tazlito pack-flavor $flavor | tee -a $log
136 tazlito get-flavor $flavor | tee -a $log
137 # BUG: script sometimes screws up conspy on Tank
138 #script -c "yes '' | tazlito gen-distro" -a $log
139 yes '' | tazlito gen-distro --forced 2>&1 | tee -a $log
140 # Rename ISO and md5
141 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
142 mv -f $SLITAZ/distro/slitaz-$flavor.iso $iso/$name.iso
143 cd $iso; md5sum $name.iso > $name.md5
144 echo "Cookiso ended: $(date '+%F %R')" | tee -a $log
145 done
146 newline
148 # Push ISO to mirror if requested.
149 [ -n "$push" ] && push_iso
150 }
153 # Push an ISO to a server.
155 push_iso() {
156 echo "Pushing to host: ${SSH_HOST}"
157 export DROPBEAR_PASSWORD=none
158 for flavor in $flavors; do
159 distro="slitaz-${string}-$flavor"
160 file="${distro%-core-4in1}"
161 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.??? \
162 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
163 done
164 }
167 #
168 # Commands
169 #
171 case "$1" in
172 setup)
173 # Setup Hg repo and dirs
174 echo -e "\nSetting up Cookiso environment..."
175 cd $SLITAZ
176 if [ ! -d "flavors" ]; then
177 case $version in
178 cooking|rolling)
179 hg clone $FLAVORS_URL ;;
180 stable)
181 hg clone $FLAVORS_URL-stable flavors ;;
182 esac
183 fi
185 # Needed packages
186 for pkg in mercurial tazlito rsync dropbear; do
187 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
188 done
190 echo 'Creating directories and files...'
191 mkdir -p $cache $iso
192 touch $activity
193 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
194 /etc/tazlito/tazlito.conf
195 newline
196 echo "Flavors files : $SLITAZ/flavors"
197 echo "Cache files : $cache"
198 echo "ISO images : $iso"
199 newline ;;
201 push)
202 # Manually upload an ISO to a server.
203 flavors_list
204 push_iso ;;
206 gen)
207 # Build one or more flavors.
208 flavors_list
209 echo -e "\nGenerating flavors:\n$flavors"
210 gen_flavors ;;
212 4in1)
213 echo -e "\nGenerating 4in1 distros..."
214 flavors="base justx gtkonly core core-4in1"
215 gen_flavors ;;
217 rolling)
218 #
219 # Official SliTaz rolling release flavors are automatically built.
220 #
221 # Check if packages list was modified or if any commits have been
222 # done in one of the rolling flavors and rebuild ISOs if needed.
223 #
224 pkgs="$SLITAZ/packages/packages.md5"
225 last="$cache/packages.md5"
226 diff="$cache/packages.diff"
227 cook="preinit core-4in1 core core64"
229 # Log stuff
230 rm -f $rollog; touch $rollog
231 rm -f $commit $commits.tmp; touch $commits.tmp
232 echo 'Rolling tracking for changes' | log
233 echo "Cookiso rolling started: $(date '+%F %R')" | log_bot
235 # Packages changes
236 [ ! -f "$last" ] && cp -f $pkgs $cache
237 diff $last $pkgs > $diff
238 if [ "$force" ] || [ -s "$diff" ]; then
239 echo 'Found new or rebuilt packages' | log_bot
240 cat $diff | grep "^+" >> $rollog
241 #
242 # TODO: Check new pkg and see if it's part of one of the rolling
243 # flavors, if not we have nothing to build.
244 #
245 for flavor in $cook; do
246 echo "$flavor" >> $commits.tmp
247 echo "New packages for : $flavor" | log_bot
248 done
249 else
250 echo 'No changes found in packages MD5 sum' | log_bot
251 echo '' > $commits.tmp
252 fi
253 cp -f $pkgs $cache
255 # Hg changes
256 cd $repo || exit 1
257 cur=$(hg head --template '{rev}\n')
258 echo "Updating wok : $repo (rev $cur)" | log_bot
259 cd $repo; hg pull -u | log_bot
260 new=$(hg head --template '{rev}\n')
261 cur=$(($cur + 1))
262 for rev in $(seq $cur $new); do
263 for file in $(hg log --rev=$rev --template "{files}"); do
264 flavor=$(echo $file | cut -d/ -f1)
265 desc=$(hg log --rev=$rev --template "{desc}" $file)
266 echo "Committed flavor : $flavor - $desc" | log_bot
267 # Build only rolling flavor
268 if echo "$cook" | fgrep -q $flavor; then
269 echo $flavor >> $commits.tmp
270 fi
271 done
272 done
274 # Keep previous commit and discard duplicate lines
275 cat $commits.tmp | sed /"^$"/d > $commits.new
276 uniq $commits.new > $commits && rm $commits.*
277 nb=$(cat $commits | wc -l)
278 echo "Flavors to cook : $nb" | log_bot
279 flavors=$(cat $commits)
280 gen_flavors ;;
282 spider)
283 # SliTaz Easter egg command :-)
284 spider ;;
286 *)
287 usage ;;
288 esac
290 rm -f $command
291 exit 0