cookutils view cookiso @ rev 1016
lighttpd/index.cgi: fix coloring (php log)
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Fri Dec 01 15:09:18 2017 +0200 (2017-12-01) |
parents | 63fb59f6fd67 |
children | ac5d3d0f9b3c |
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|cooking|next) string="$version";;
42 *) version='cooking'; string='rolling';;
43 esac
46 # Running command
48 [ -d "$cache" ] && echo "$@" > $command
49 trap 'rm -f $command && exit 1' INT TERM
52 #
53 # Functions
54 #
56 usage() {
57 cat <<EOT
59 $(boldify "Usage:") cookiso [command] [--option]
61 $(boldify "Commands:")
62 usage Display this short usage.
63 setup Setup Cookiso build environment.
64 push Manually push ISO to a server via SSH.
65 gen Generate specified flavors.
66 4in1 Generate all 4in1 flavors.
67 rolling Build the rolling ISOs if any changes.
69 $(boldify "Options:")
70 --force Build ISO rolling anyway.
71 --pkgdb Generate packages DB before building ISO.
72 --push Upload freshly generated ISO to a server.
73 --flavors= List of flavors to generate with 'gen' command.
74 --version= Specify SliTaz version: [rolling|cooking|stable]
76 EOT
77 }
80 spider() {
81 echo -e ' // \\\\\n _\\\\()//_\n/ // \\\\ \\\n | \\__/ |'
82 }
85 # Check for some flavors on cmdline
87 flavors_list() {
88 if [ "$flavors" == 'all' ]; then
89 flavors=$(ls $SLITAZ/flavors)
90 fi
91 if [ -z "$flavors" ]; then
92 echo 'No flavor specified on cmdline. Use: --flavors='
93 rm -f $command
94 exit 0
95 fi
96 }
99 # Log activities, we want first letter capitalized.
101 log() {
102 grep ^[A-Z] | \
103 sed "s#^[A-Z]\([^']*\)#$(date '+%F %R') : \0#" >> $activity
104 }
107 log_bot() {
108 sed '/^.\//d' | sed '/^.hg/d' | tee -a $rollog
109 }
112 # Generate requested flavors.
114 gen_flavors() {
115 cd $SLITAZ/flavors
116 [ -d ".hg" -a -n "$(which hg)" ] && hg pull -u
117 mkdir -p $cache; cd $cache
118 rm -rf *.flavor *.list *.conf *.sh
119 for flavor in $flavors; do
120 if [ "$flavor" != 'core-4in1' ]; then
121 name="slitaz-$string-$flavor"
122 else
123 name="slitaz-$string"
124 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
134 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
136 echo "Cookiso started: $(date '+%F %R')" | tee -a $log
137 tazlito pack-flavor $flavor | tee -a $log
138 tazlito get-flavor $flavor | tee -a $log
139 # BUG: script sometimes screws up conspy on Tank
140 #script -c "yes '' | tazlito gen-distro" -a $log
141 yes '' | tazlito gen-distro --forced 2>&1 | tee -a $log
142 # Rename ISO and md5
143 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
144 mv -f $SLITAZ/distro/slitaz-$flavor.iso $iso/$name.iso
145 cd $iso; md5sum $name.iso > $name.md5
146 echo "Cookiso ended: $(date '+%F %R')" | tee -a $log
147 done
148 newline
150 # Push ISO to mirror if requested.
151 [ -n "$push" ] && push_iso
152 }
155 # Push an ISO to a server.
157 push_iso() {
158 echo "Pushing to host: ${SSH_HOST}"
159 export DROPBEAR_PASSWORD=none
160 for flavor in $flavors; do
161 distro="slitaz-${string}-$flavor"
162 file="${distro%-core-4in1}"
163 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.??? \
164 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
165 done
166 }
169 #
170 # Commands
171 #
173 case "$1" in
174 setup)
175 # Setup Hg repo and dirs
176 echo -e "\nSetting up Cookiso environment..."
177 cd $SLITAZ
178 if [ ! -d "flavors" ]; then
179 case $version in
180 cooking|rolling)
181 hg clone $FLAVORS_URL ;;
182 stable)
183 hg clone $FLAVORS_URL-stable flavors ;;
184 esac
185 fi
187 # Needed packages
188 for pkg in mercurial tazlito rsync dropbear; do
189 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
190 done
192 echo 'Creating directories and files...'
193 mkdir -p $cache $iso
194 touch $activity
195 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
196 /etc/tazlito/tazlito.conf
197 newline
198 echo "Flavors files : $SLITAZ/flavors"
199 echo "Cache files : $cache"
200 echo "ISO images : $iso"
201 newline ;;
203 push)
204 # Manually upload an ISO to a server.
205 flavors_list
206 push_iso ;;
208 gen)
209 # Build one or more flavors.
210 flavors_list
211 echo -e "\nGenerating flavors:\n$flavors"
212 gen_flavors ;;
214 4in1)
215 echo -e "\nGenerating 4in1 distros..."
216 flavors="base justx gtkonly core core-4in1"
217 gen_flavors ;;
219 rolling)
220 #
221 # Official SliTaz rolling release flavors are automatically built.
222 #
223 # Check if packages list was modified or if any commits have been
224 # done in one of the rolling flavors and rebuild ISOs if needed.
225 #
226 pkgs="$SLITAZ/packages/packages.md5"
227 last="$cache/packages.md5"
228 diff="$cache/packages.diff"
229 cook="preinit core-4in1 core core64"
231 # Log stuff
232 rm -f $rollog; touch $rollog
233 rm -f $commit $commits.tmp; touch $commits.tmp
234 echo 'Rolling tracking for changes' | log
235 echo "Cookiso rolling started: $(date '+%F %R')" | log_bot
237 # Packages changes
238 [ ! -f "$last" ] && cp -f $pkgs $cache
239 diff $last $pkgs > $diff
240 if [ "$force" ] || [ -s "$diff" ]; then
241 echo 'Found new or rebuilt packages' | log_bot
242 cat $diff | grep "^+" >> $rollog
243 #
244 # TODO: Check new pkg and see if it's part of one of the rolling
245 # flavors, if not we have nothing to build.
246 #
247 for flavor in $cook; do
248 echo "$flavor" >> $commits.tmp
249 echo "New packages for : $flavor" | log_bot
250 done
251 else
252 echo 'No changes found in packages MD5 sum' | log_bot
253 echo '' > $commits.tmp
254 fi
255 cp -f $pkgs $cache
257 # Hg changes
258 cd $repo || exit 1
259 cur=$(hg head --template '{rev}\n')
260 echo "Updating wok : $repo (rev $cur)" | log_bot
261 cd $repo; hg pull -u | log_bot
262 new=$(hg head --template '{rev}\n')
263 cur=$(($cur + 1))
264 for rev in $(seq $cur $new); do
265 for file in $(hg log --rev=$rev --template "{files}"); do
266 flavor=$(echo $file | cut -d/ -f1)
267 desc=$(hg log --rev=$rev --template "{desc}" $file)
268 echo "Committed flavor : $flavor - $desc" | log_bot
269 # Build only rolling flavor
270 if echo "$cook" | fgrep -q $flavor; then
271 echo $flavor >> $commits.tmp
272 fi
273 done
274 done
276 # Keep previous commit and discard duplicate lines
277 cat $commits.tmp | sed /"^$"/d > $commits.new
278 uniq $commits.new > $commits && rm $commits.*
279 nb=$(cat $commits | wc -l)
280 echo "Flavors to cook : $nb" | log_bot
281 flavors=$(cat $commits)
282 gen_flavors ;;
284 spider)
285 # SliTaz Easter egg command :-)
286 spider ;;
288 *)
289 usage ;;
290 esac
292 rm -f $command
293 exit 0