cookutils view cookiso @ rev 714

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