cookutils view cookiso @ rev 1141
modules/pack: take care of stuff update dates
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Jul 14 11:52:54 2019 +0200 (2019-07-14) |
parents | ac5d3d0f9b3c |
children | e58a083722aa |
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|cooking|next) string="$version";;
42 *) version='cooking'; string='rolling';;
43 esac
46 # Running command
48 [ -d "$cache" ] && echo "$@" > $command
49 trap 'rm -f $command && exit 1' INT TERM
52 #
53 # Functions
54 #
56 usage() {
57 cat <<EOT
59 $(boldify "Usage:") cookiso [command] [--option]
61 $(boldify "Commands:")
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 $(boldify "Options:")
70 --force Build ISO rolling anyway.
71 --pkgdb Generate packages DB before building ISO.
72 --push Upload freshly generated ISO to a server.
73 --flavors= List of flavors to generate with 'gen' command.
74 --version= Specify SliTaz version: [rolling|cooking|stable]
76 EOT
77 }
80 spider() {
81 echo -e ' // \\\\\n _\\\\()//_\n/ // \\\\ \\\n | \\__/ |'
82 }
85 # Check for some flavors on cmdline
87 flavors_list() {
88 if [ "$flavors" == 'all' ]; then
89 flavors=$(ls $SLITAZ/flavors)
90 fi
91 if [ -z "$flavors" ]; then
92 echo 'No flavor specified on cmdline. Use: --flavors='
93 rm -f $command
94 exit 0
95 fi
96 }
99 # Log activities, we want first letter capitalized.
101 log() {
102 grep ^[A-Z] | \
103 sed "s#^[A-Z]\([^']*\)#$(date '+%F %R') : \0#" >> $activity
104 }
107 log_bot() {
108 sed '/^.\//d' | sed '/^.hg/d' | tee -a $rollog
109 }
112 # Generate requested flavors.
114 gen_flavors() {
115 cd $SLITAZ/flavors
116 [ -d ".hg" -a -n "$(which hg)" ] && hg pull -u
117 mkdir -p $cache; cd $cache
118 rm -rf *.flavor *.list *.conf *.sh
119 for flavor in $flavors; do
120 case "$flavor" in
121 core-*in1)
122 name="slitaz-$string-$flavor" ;;
123 *)
124 name="slitaz-$string" ;;
125 esac
127 log="$iso/$name.log"
128 for i in $(seq 9 -1 1); do # Rotate log
129 j=$(($i - 1))
130 [ -e $log.$j ] && mv -f $log.$j $log.$i
131 done
132 [ -e $log ] && mv $log $log.0
133 touch $log
135 echo "Building $string <a href='?distro=$string-$flavor'>$flavor</a>" | log
137 echo "Cookiso started: $(date '+%F %R')" | tee -a $log
138 tazlito pack-flavor $flavor | tee -a $log
139 tazlito get-flavor $flavor | tee -a $log
140 # BUG: script sometimes screws up conspy on Tank
141 #script -c "yes '' | tazlito gen-distro" -a $log
142 yes '' | tazlito gen-distro --forced 2>&1 | tee -a $log
143 # Rename ISO and md5
144 echo "Moving ISO to: $iso/$name.iso" | tee -a $log
145 mv -f $SLITAZ/distro/slitaz-$flavor.iso $iso/$name.iso
146 cd $iso; md5sum $name.iso > $name.md5
147 echo "Cookiso ended: $(date '+%F %R')" | tee -a $log
148 done
149 newline
151 # Push ISO to mirror if requested.
152 [ -n "$push" ] && push_iso
153 }
156 # Push an ISO to a server.
158 push_iso() {
159 echo "Pushing to host: ${SSH_HOST}"
160 export DROPBEAR_PASSWORD=none
161 for flavor in $flavors; do
162 distro="slitaz-${string}-$flavor"
163 file="${distro%-core-*in1}"
164 rsync $BWLIMIT -vtP -e "$SSH_CMD" $iso/$file.??? \
165 ${SSH_HOST}:$SSH_ISO/$string 2>&1 | tee $synclog
166 done
167 }
170 #
171 # Commands
172 #
174 case "$1" in
175 setup)
176 # Setup Hg repo and dirs
177 echo -e "\nSetting up Cookiso environment..."
178 cd $SLITAZ
179 if [ ! -d "flavors" ]; then
180 case $version in
181 cooking|rolling)
182 hg clone $FLAVORS_URL ;;
183 stable)
184 hg clone $FLAVORS_URL-stable flavors ;;
185 esac
186 fi
188 # Needed packages
189 for pkg in mercurial tazlito rsync dropbear; do
190 [ ! -d "$INSTALLED/$pkg" ] && tazpkg -gi $pkg
191 done
193 echo 'Creating directories and files...'
194 mkdir -p $cache $iso
195 touch $activity
196 sed -i s'/^WORK_DIR=.*/WORK_DIR="\/home\/slitaz"/' \
197 /etc/tazlito/tazlito.conf
198 newline
199 echo "Flavors files : $SLITAZ/flavors"
200 echo "Cache files : $cache"
201 echo "ISO images : $iso"
202 newline ;;
204 push)
205 # Manually upload an ISO to a server.
206 flavors_list
207 push_iso ;;
209 gen)
210 # Build one or more flavors.
211 flavors_list
212 echo -e "\nGenerating flavors:\n$flavors"
213 gen_flavors ;;
215 *in1)
216 echo -e "\nGenerating $1 distros..."
217 flavors="base justx gtkonly core core-$1"
218 gen_flavors ;;
220 rolling)
221 #
222 # Official SliTaz rolling release flavors are automatically built.
223 #
224 # Check if packages list was modified or if any commits have been
225 # done in one of the rolling flavors and rebuild ISOs if needed.
226 #
227 pkgs="$SLITAZ/packages/packages.md5"
228 last="$cache/packages.md5"
229 diff="$cache/packages.diff"
230 cook="preinit core-4in1 core core-5in1 core64"
232 # Log stuff
233 rm -f $rollog; touch $rollog
234 rm -f $commit $commits.tmp; touch $commits.tmp
235 echo 'Rolling tracking for changes' | log
236 echo "Cookiso rolling started: $(date '+%F %R')" | log_bot
238 # Packages changes
239 [ ! -f "$last" ] && cp -f $pkgs $cache
240 diff $last $pkgs > $diff
241 if [ "$force" ] || [ -s "$diff" ]; then
242 echo 'Found new or rebuilt packages' | log_bot
243 cat $diff | grep "^+" >> $rollog
244 #
245 # TODO: Check new pkg and see if it's part of one of the rolling
246 # flavors, if not we have nothing to build.
247 #
248 for flavor in $cook; do
249 echo "$flavor" >> $commits.tmp
250 echo "New packages for : $flavor" | log_bot
251 done
252 else
253 echo 'No changes found in packages MD5 sum' | log_bot
254 echo '' > $commits.tmp
255 fi
256 cp -f $pkgs $cache
258 # Hg changes
259 cd $repo || exit 1
260 cur=$(hg head --template '{rev}\n')
261 echo "Updating wok : $repo (rev $cur)" | log_bot
262 cd $repo; hg pull -u | log_bot
263 new=$(hg head --template '{rev}\n')
264 cur=$(($cur + 1))
265 for rev in $(seq $cur $new); do
266 for file in $(hg log --rev=$rev --template "{files}"); do
267 flavor=$(echo $file | cut -d/ -f1)
268 desc=$(hg log --rev=$rev --template "{desc}" $file)
269 echo "Committed flavor : $flavor - $desc" | log_bot
270 # Build only rolling flavor
271 if echo "$cook" | fgrep -q $flavor; then
272 echo $flavor >> $commits.tmp
273 fi
274 done
275 done
277 # Keep previous commit and discard duplicate lines
278 cat $commits.tmp | sed /"^$"/d > $commits.new
279 uniq $commits.new > $commits && rm $commits.*
280 nb=$(cat $commits | wc -l)
281 echo "Flavors to cook : $nb" | log_bot
282 flavors=$(cat $commits)
283 gen_flavors ;;
285 spider)
286 # SliTaz Easter egg command :-)
287 spider ;;
289 *)
290 usage ;;
291 esac
293 rm -f $command
294 exit 0