cookutils view cookiso @ rev 520

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