cookutils annotate cookiso @ rev 339

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