cookutils view cookiso @ rev 585

Update (C) to 2013
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 01 23:49:02 2013 +0000 (2013-02-01)
parents 6b2e60bbf266
children
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 . /etc/slitaz/cookiso.conf
18 . /usr/lib/slitaz/libcookiso.sh
20 check_root
22 # Parse cmdline options.
23 for opt in "$@"
24 do
25 case "$opt" in
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
37 # Default to rolling, or: cookiso [cmd] --version=stable
38 case "$version" in
39 stable)
40 string=stable ;;
41 cooking)
42 string=cooking ;;
43 *)
44 version=cooking
45 string=rolling ;;
46 esac
48 # Running command
49 [ -d "$cache" ] && echo "$@" > $command
50 trap 'rm -f $command && exit 1' INT TERM
52 #
53 # Functions
54 #
56 usage() {
57 cat << EOT
59 $(echo -e "\033[1mUsage:\033[0m") cookiso [command] [--option]
61 $(echo -e "\033[1mCommands:\033[0m")
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 $(echo -e "\033[1mOptions:\033[0m")
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_bot() {
97 sed '/^.\//'d | sed '/^.hg/'d | tee -a $rollog
98 }
100 # Generate requested flavors.
101 gen_flavors() {
102 cd $SLITAZ/flavors
103 [ -d ".hg" ] && hg pull -u
104 mkdir -p $cache && cd $cache
105 rm -rf *.flavor *.list *.conf *.sh
106 for flavor in $flavors
107 do
108 if [ "$flavor" != "core-4in1" ]; then
109 name="slitaz-$string-$flavor"
110 else
111 name="slitaz-$string"
112 fi
113 log=$iso/$name.log
114 rm -f $log && touch $log
115 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
116 echo "Cookiso started: $(date '+%Y-%m-%d %H:%M')" | tee -a $log
117 pack_flavor $flavor | tee -a $log
118 get_flavor $flavor | tee -a $log
119 # BUG: script sometimes screws up conspy on Tank
120 #script -c "yes '' | tazlito gen-distro" -a $log
121 gen_distro 2>&1 | tee -a $log
122 # Rename ISO and md5
123 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
124 if [ -f $DISTRO/slitaz-$flavor.iso ]; then
125 mv -f $DISTRO/slitaz-$flavor.iso $iso/$name.iso
126 elif [ -f $DISTRO/$ISO_NAME.iso ]; then
127 mv -f $DISTRO/$ISO_NAME.iso $iso/$name.iso
128 fi
129 cd $iso && $CHECKSUM $name.iso > $name.$SUM
130 echo "Cookiso ended: $(date '+%Y-%m-%d %H:%M')" | tee -a $log
131 done && newline
132 # Push ISO to mirror if requested.
133 [ "$push" ] && push_iso
134 }
136 # Push an ISO to a server.
137 push_iso() {
138 echo "Pushing to host: ${SSH_HOST}"
139 export DROPBEAR_PASSWORD=none
140 for flavor in $flavors
141 do
142 distro=slitaz-${string}-$flavor
143 file=${distro%-core-4in1}
144 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.* \
145 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
146 done
147 }
149 #
150 # Commands
151 #
153 case "$1" in
154 setup)
155 # Setup Hg repo and dirs
156 echo -e "\nSetting up Cookiso environment..."
157 cd $SLITAZ
158 if [ ! -d "flavors" ]; then
159 case $version in
160 cooking|rolling)
161 hg clone $FLAVORS_URL ;;
162 stable)
163 hg clone $FLAVORS_URL-stable flavors ;;
164 esac
165 fi
166 # Needed packages
167 for pkg in mercurial tazlito rsync dropbear squashfs
168 do
169 [ -f "$INSTALLED/$pkg/receipt" ] || tazpkg -gi $pkg
170 done
171 echo "Creating directories and files..."
172 mkdir -p $cache $iso
173 touch $activity
174 sed -i "s|WORK_DIR=.*|WORK_DIR="$SLITAZ"|g" \
175 /etc/slitaz/cookiso.conf
176 newline
177 echo "Flavors files : $SLITAZ/flavors"
178 echo "Cache files : $cache"
179 echo "ISO images : $iso"
180 newline ;;
181 push)
182 # Manually upload an ISO to a server.
183 flavors_list
184 push_iso ;;
185 gen)
186 # Build one or more flavors.
187 flavors_list
188 echo -e "\nGenerating flavors:\n$flavors"
189 gen_flavors ;;
190 4in1)
191 echo -e "\nGenerating 4in1 distros..."
192 flavors="base justx gtkonly core core-4in1"
193 gen_flavors ;;
194 rolling)
195 #
196 # Official SliTaz rolling release flavors are automatically built.
197 #
198 # Check if packages list was modified or if any commits have been
199 # done in one of the rolling flavors and rebuild ISOs if needed.
200 #
201 pkgs=$SLITAZ/packages/packages.md5
202 last=$cache/packages.md5
203 diff=$cache/packages.diff
204 cook="preinit core-4in1"
206 # Log stuff
207 rm -f $rollog && touch $rollog
208 rm -f $commit $commits.tmp && touch $commits.tmp
209 echo "Rolling tracking for changes" | log
210 echo "Cookiso rolling started: $(date '+%Y-%m-%d %H:%M')" | log_bot
212 # Packages changes
213 [ -f "$last" ] || cp -f $pkgs $cache
214 diff $last $pkgs > $diff
215 if [ -s "$diff" ]; then
216 echo "Found new or rebuilt packages" | log_bot
217 cat $diff | grep "^+" >> $rollog
218 #
219 # TODO: Check new pkg and see if it's part of one of the rolling
220 # flavors, if not we have nothing to build.
221 #
222 for flavor in $cook
223 do
224 echo "$flavor" >> $commits.tmp
225 echo "New packages for : $flavor" | log_bot
226 done
227 else
228 echo "No changes found in packages MD5 sum" | log_bot
229 newline > $commits.tmp
230 fi
231 cp -f $pkgs $cache
233 # Hg changes
234 cd $repo || exit 1
235 cur=$(hg head --template '{rev}\n')
236 echo "Updating wok : $repo (rev $cur)" | log_bot
237 cd $repo && hg pull -u | log_bot
238 new=$(hg head --template '{rev}\n')
239 cur=$(($cur + 1))
240 for rev in $(seq $cur $new)
241 do
242 for file in $(hg log --rev=$rev --template "{files}")
243 do
244 flavor=$(echo $file | cut -d "/" -f 1)
245 desc=$(hg log --rev=$rev --template "{desc}" $file)
246 echo "Committed flavor : $flavor - $desc" | log_bot
247 # Build only rolling flavor
248 if echo "$cook" | fgrep -q $flavor; then
249 echo $flavor >> $commits.tmp
250 fi
251 done
252 done
254 # Keep previous commit and discard duplicate lines
255 cat $commits.tmp | sed /"^$"/d > $commits.new
256 uniq $commits.new > $commits && rm $commits.*
257 nb=$(cat $commits | wc -l)
258 echo "Flavors to cook : $nb" | log_bot
259 flavors=$(cat $commits)
260 gen_flavors ;;
261 spider)
262 # SliTaz Easter egg command :-)
263 spider ;;
264 *)
265 usage ;;
266 esac
268 rm -f $command
269 exit 0