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