cookutils view cookiso @ rev 830
Update fr.po
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Sep 19 12:58:15 2016 +0200 (2016-09-19) |
parents | d2668c48792f |
children | f6478839bdd8 |
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 rm -f $log; touch $log
128 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
129 echo "Cookiso started: $(date '+%F %R')" | tee -a $log
130 tazlito pack-flavor $flavor | tee -a $log
131 tazlito get-flavor $flavor | tee -a $log
132 # BUG: script sometimes screws up conspy on Tank
133 #script -c "yes '' | tazlito gen-distro" -a $log
134 yes '' | tazlito gen-distro --forced 2>&1 | tee -a $log
135 # Rename ISO and md5
136 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
137 mv -f $SLITAZ/distro/slitaz-$flavor.iso $iso/$name.iso
138 cd $iso; md5sum $name.iso > $name.md5
139 echo "Cookiso ended: $(date '+%F %R')" | tee -a $log
140 done
141 newline
143 # Push ISO to mirror if requested.
144 [ -n "$push" ] && push_iso
145 }
148 # Push an ISO to a server.
150 push_iso() {
151 echo "Pushing to host: ${SSH_HOST}"
152 export DROPBEAR_PASSWORD=none
153 for flavor in $flavors; do
154 distro="slitaz-${string}-$flavor"
155 file="${distro%-core-4in1}"
156 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.* \
157 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
158 done
159 }
162 #
163 # Commands
164 #
166 case "$1" in
167 setup)
168 # Setup Hg repo and dirs
169 echo -e "\nSetting up Cookiso environment..."
170 cd $SLITAZ
171 if [ ! -d "flavors" ]; then
172 case $version in
173 cooking|rolling)
174 hg clone $FLAVORS_URL ;;
175 stable)
176 hg clone $FLAVORS_URL-stable flavors ;;
177 esac
178 fi
180 # Needed packages
181 for pkg in mercurial tazlito rsync dropbear; do
182 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
183 done
185 echo 'Creating directories and files...'
186 mkdir -p $cache $iso
187 touch $activity
188 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
189 /etc/tazlito/tazlito.conf
190 newline
191 echo "Flavors files : $SLITAZ/flavors"
192 echo "Cache files : $cache"
193 echo "ISO images : $iso"
194 newline ;;
196 push)
197 # Manually upload an ISO to a server.
198 flavors_list
199 push_iso ;;
201 gen)
202 # Build one or more flavors.
203 flavors_list
204 echo -e "\nGenerating flavors:\n$flavors"
205 gen_flavors ;;
207 4in1)
208 echo -e "\nGenerating 4in1 distros..."
209 flavors="base justx gtkonly core core-4in1"
210 gen_flavors ;;
212 rolling)
213 #
214 # Official SliTaz rolling release flavors are automatically built.
215 #
216 # Check if packages list was modified or if any commits have been
217 # done in one of the rolling flavors and rebuild ISOs if needed.
218 #
219 pkgs="$SLITAZ/packages/packages.md5"
220 last="$cache/packages.md5"
221 diff="$cache/packages.diff"
222 cook="preinit core-4in1 core core64"
224 # Log stuff
225 rm -f $rollog; touch $rollog
226 rm -f $commit $commits.tmp; touch $commits.tmp
227 echo 'Rolling tracking for changes' | log
228 echo "Cookiso rolling started: $(date '+%F %R')" | log_bot
230 # Packages changes
231 [ ! -f "$last" ] && cp -f $pkgs $cache
232 diff $last $pkgs > $diff
233 if [ "$force" ] || [ -s "$diff" ]; then
234 echo 'Found new or rebuilt packages' | log_bot
235 cat $diff | grep "^+" >> $rollog
236 #
237 # TODO: Check new pkg and see if it's part of one of the rolling
238 # flavors, if not we have nothing to build.
239 #
240 for flavor in $cook; do
241 echo "$flavor" >> $commits.tmp
242 echo "New packages for : $flavor" | log_bot
243 done
244 else
245 echo 'No changes found in packages MD5 sum' | log_bot
246 echo '' > $commits.tmp
247 fi
248 cp -f $pkgs $cache
250 # Hg changes
251 cd $repo || exit 1
252 cur=$(hg head --template '{rev}\n')
253 echo "Updating wok : $repo (rev $cur)" | log_bot
254 cd $repo; hg pull -u | log_bot
255 new=$(hg head --template '{rev}\n')
256 cur=$(($cur + 1))
257 for rev in $(seq $cur $new); do
258 for file in $(hg log --rev=$rev --template "{files}"); do
259 flavor=$(echo $file | cut -d/ -f1)
260 desc=$(hg log --rev=$rev --template "{desc}" $file)
261 echo "Committed flavor : $flavor - $desc" | log_bot
262 # Build only rolling flavor
263 if echo "$cook" | fgrep -q $flavor; then
264 echo $flavor >> $commits.tmp
265 fi
266 done
267 done
269 # Keep previous commit and discard duplicate lines
270 cat $commits.tmp | sed /"^$"/d > $commits.new
271 uniq $commits.new > $commits && rm $commits.*
272 nb=$(cat $commits | wc -l)
273 echo "Flavors to cook : $nb" | log_bot
274 flavors=$(cat $commits)
275 gen_flavors ;;
277 spider)
278 # SliTaz Easter egg command :-)
279 spider ;;
281 *)
282 usage ;;
283 esac
285 rm -f $command
286 exit 0