cookutils view cookiso @ rev 546

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