cookutils annotate cooker @ rev 795
Tiny edits
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Mar 30 01:25:01 2016 +0300 (2016-03-30) |
parents | 2185b741fba9 |
children | 2850833e8670 |
rev | line source |
---|---|
pankso@4 | 1 #!/bin/sh |
pankso@4 | 2 # |
pankso@383 | 3 # SliTaz Build Bot. The Cooker is a tool to automate and test SliTaz package |
pankso@383 | 4 # building. Please read the Cookbook documentation for more information |
paul@54 | 5 # and discuss with the AUTHORS before adding anything here. PS: no translations |
paul@495 | 6 # here since it's not an end user tool and it's not useful. All devs should |
pankso@4 | 7 # at least understand basic English. |
pankso@4 | 8 # |
al@728 | 9 |
pankso@431 | 10 . /usr/lib/slitaz/libcook.sh |
pankso@4 | 11 |
pankso@49 | 12 # Set pkg name and use same wok as cook. |
pankso@49 | 13 pkg="$2" |
pankso@4 | 14 wok="$WOK" |
pankso@4 | 15 |
pankso@81 | 16 # PID file. |
pankso@81 | 17 pidfile='/var/run/cooker.pid' |
pankso@81 | 18 |
pankso@4 | 19 # |
pankso@4 | 20 # Functions |
pankso@4 | 21 # |
pankso@4 | 22 |
pankso@4 | 23 usage() { |
al@728 | 24 cat <<EOT |
pankso@4 | 25 |
pankso@341 | 26 Usage: cooker [command] [pkg|list|note|hours] |
pankso@4 | 27 |
pankso@4 | 28 Options: |
pankso@49 | 29 usage|-u Display this short usage. |
pankso@49 | 30 setup|-s Setup the Cooker environment. |
pankso@341 | 31 setup-cron Setup a cron job for the Cooker. |
pankso@383 | 32 arch-db Create host arch packages DB. |
pankso@49 | 33 note|-n Add a note to the cooknotes. |
pankso@49 | 34 notes|-ns Display all the cooknotes. |
pankso@49 | 35 block|-b Block a package so cook will skip it. |
pankso@49 | 36 unblock|-ub Unblock a blocked package. |
pankso@49 | 37 pkg|-p Same as 'cook pkg' but with cooker log. |
pankso@49 | 38 flavor|-f Cook all packages of a flavor. |
paul@54 | 39 list|-l Cook all packages in the given list. |
pankso@49 | 40 cat|-c Cook all packages of a category. |
pankso@79 | 41 rev|-r Cook packages of a specific revision. |
pankso@49 | 42 all|-a Find and cook all unbuilt packages. |
pankso@4 | 43 |
pankso@4 | 44 EOT |
pankso@4 | 45 exit 0 |
pankso@4 | 46 } |
pankso@4 | 47 |
al@728 | 48 |
paul@54 | 49 # Some messages occur in activity but log verbose output when checking for commits |
pankso@14 | 50 # into a log file. |
al@728 | 51 |
pankso@14 | 52 log_commits() { |
pankso@35 | 53 sed '/^.\//'d | sed '/^.hg/'d | tee -a $LOGS/commits.log |
pankso@14 | 54 } |
pankso@14 | 55 |
al@728 | 56 |
pankso@81 | 57 # Clean up before exit when check and cook commits finish. |
al@728 | 58 |
pankso@81 | 59 clean_exit() { |
al@728 | 60 rm -f $command; touch $command |
pascal@766 | 61 [ "$previous_command" ] && ps | grep -q "${previous_command/:/ }" && |
pascal@766 | 62 echo -n "$previous_command" > $command |
pankso@81 | 63 rm -f $pidfile |
pankso@14 | 64 } |
pankso@14 | 65 |
al@728 | 66 |
pankso@35 | 67 # Summary for commits. |
al@728 | 68 |
pankso@35 | 69 commits_summary() { |
pankso@35 | 70 msg="from revision $cur to $new" |
pankso@35 | 71 [ "$new" == "$cur" ] && msg="revision $new" |
pankso@35 | 72 echo "Will cook $msg" |
pankso@35 | 73 separator |
pankso@35 | 74 echo -e "\nSummary for commits" |
pankso@35 | 75 separator |
pankso@35 | 76 echo "Hg wok revision : $cur" |
pankso@35 | 77 echo "Pulled revision : $new" |
al@728 | 78 echo "Check date : $(date '+%F %T')" |
pankso@35 | 79 } |
pankso@35 | 80 |
al@728 | 81 |
paul@54 | 82 # Scan packages build deps and fill up cookorder list. |
al@728 | 83 |
pankso@4 | 84 cook_order_scan() { |
pankso@124 | 85 rm -f $cookorder |
pankso@383 | 86 touch $cookorder |
al@728 | 87 for pkg in $(cat $cooklist); do |
pascal@273 | 88 unset WANTED BUILD_DEPENDS |
pankso@14 | 89 . $wok/$pkg/receipt |
pankso@29 | 90 # The :: is for web interface color. |
pascal@273 | 91 [ "$WANTED$BUILD_DEPENDS" ] && echo "$pkg :: $WANTED $BUILD_DEPENDS" |
al@728 | 92 for dep in $WANTED $BUILD_DEPENDS; do |
pankso@4 | 93 if grep -q "^$dep$" $cooklist; then |
pankso@4 | 94 if ! grep -q "^$dep$" $cookorder; then |
pankso@4 | 95 echo "$dep" >> $cookorder |
pankso@4 | 96 fi |
pankso@4 | 97 fi |
pankso@4 | 98 done |
pankso@4 | 99 done |
pankso@383 | 100 |
paul@54 | 101 # Append unordered packages to cookorder. |
al@728 | 102 for pkg in $(cat $cooklist); do |
pankso@4 | 103 if ! grep -q "^$pkg$" $cookorder; then |
pankso@4 | 104 echo "$pkg" >> $cookorder |
pankso@4 | 105 fi |
pankso@4 | 106 done |
pankso@4 | 107 } |
pankso@4 | 108 |
al@728 | 109 |
paul@54 | 110 # Scan and rescan until the cooklist is ordered then handle WANTED. |
al@728 | 111 |
pankso@4 | 112 cook_order() { |
pankso@4 | 113 time=$(date +%s) |
pankso@4 | 114 scan=0 |
pankso@4 | 115 |
pankso@4 | 116 # Keep an original cooklist so we do a diff when ordering is finished. |
pankso@4 | 117 cp -f $cooklist $cooklist.0 |
al@728 | 118 echo 'cookorder' > $command |
al@728 | 119 echo -e '\nInitial Cooker order scan' |
pankso@4 | 120 separator |
pankso@4 | 121 cook_order_scan |
pankso@383 | 122 |
pankso@4 | 123 # Diff between the cooklist and new ordered list ? So copy the last |
pankso@4 | 124 # cookorder to cooklist and rescan it. |
al@728 | 125 while /bin/true; do |
pankso@4 | 126 diff $cooklist $cookorder > $cookorder.diff |
pankso@4 | 127 if [ -s "$cookorder.diff" ]; then |
pankso@4 | 128 scan=$(($scan + 1)) |
pankso@4 | 129 echo -e "\nDiff scan: $scan" |
pankso@4 | 130 separator |
pankso@4 | 131 mv -f $cookorder $cooklist |
pankso@4 | 132 cook_order_scan |
pankso@4 | 133 else |
pankso@4 | 134 break |
pankso@4 | 135 fi |
pankso@4 | 136 done |
pankso@4 | 137 |
paul@647 | 138 # Keep a diff between submitted cooklist and the ordered. |
pankso@4 | 139 diff $cooklist.0 $cooklist > $cooklist.diff |
pankso@4 | 140 rm -f $cookorder $cookorder.diff $cooklist.0 |
pankso@4 | 141 |
pankso@107 | 142 # Scan finished: append pkg to WANTED or leave it in the ordered cooklist. |
paul@214 | 143 # TODO: grep the line number to get pkg position and keep it higher. |
al@728 | 144 echo -e '\nHandle WANTED package' |
pankso@4 | 145 separator |
al@728 | 146 for pkg in $(cat $cooklist); do |
pankso@4 | 147 unset WANTED |
pankso@14 | 148 . $wok/$pkg/receipt |
al@728 | 149 for wanted in $WANTED; do |
pascal@291 | 150 echo "$pkg :: $wanted" |
pascal@291 | 151 if grep -q ^${wanted}$ $cooklist; then |
pankso@107 | 152 sed -i -e "/^$pkg$/"d \ |
pascal@291 | 153 -e "/^$wanted$/ a $pkg" $cooklist |
pankso@107 | 154 fi |
pascal@291 | 155 done |
pankso@4 | 156 done |
pankso@4 | 157 |
pankso@4 | 158 # Show ordered cooklist |
al@728 | 159 echo -e '\nCooklist order' |
pankso@4 | 160 separator |
pankso@4 | 161 cat $cooklist |
pankso@4 | 162 separator |
al@728 | 163 |
pankso@4 | 164 time=$(($(date +%s) - $time)) |
pankso@4 | 165 pkgs=$(cat $cooklist | wc -l) |
al@728 | 166 echo -e '\nSummary for cookorder' |
pankso@4 | 167 separator |
al@728 | 168 cat <<EOT |
pankso@4 | 169 Ordered packages : $pkgs |
pankso@4 | 170 Scans executed : $scan |
pankso@4 | 171 Scan duration : ${time}s |
pankso@4 | 172 EOT |
al@728 | 173 separator |
al@728 | 174 |
al@728 | 175 rm -f $command |
pankso@4 | 176 } |
pankso@4 | 177 |
al@728 | 178 |
pankso@14 | 179 # Remove blocked (faster this way than grepping before). |
al@728 | 180 |
pankso@14 | 181 strip_blocked() { |
al@728 | 182 for pkg in $(cat $blocked); do |
pankso@14 | 183 sed -i /^${pkg}$/d $cooklist |
al@728 | 184 done |
al@728 | 185 sed -i /^$/d $cooklist |
pankso@14 | 186 } |
pankso@14 | 187 |
al@728 | 188 |
paul@54 | 189 # Use in default mode and with all cmd. |
al@728 | 190 |
pankso@4 | 191 cook_commits() { |
pankso@4 | 192 if [ -s "$commits" ]; then |
al@728 | 193 for pkg in $(cat $commits); do |
pascal@765 | 194 ps | grep -q "cook $pkg$" && continue |
pankso@14 | 195 echo "cook:$pkg" > $command |
pankso@394 | 196 cook $pkg || broken |
pankso@4 | 197 sed -i /^${pkg}$/d $commits |
pankso@4 | 198 done |
pankso@4 | 199 fi |
pankso@4 | 200 } |
pankso@4 | 201 |
al@728 | 202 |
paul@54 | 203 # Cook all packages in a cooklist. |
al@728 | 204 |
pankso@14 | 205 cook_list() { |
al@728 | 206 for pkg in $(cat $cooklist); do |
pascal@765 | 207 ps | grep -q "cook $pkg$" && continue |
pankso@79 | 208 cook $pkg || broken |
pankso@79 | 209 sed -i /^${pkg}$/d $cooklist |
pankso@14 | 210 done |
pankso@14 | 211 } |
pankso@14 | 212 |
al@728 | 213 |
paul@388 | 214 # Create a arch.$ARCH file for each package cooked for the target host |
pankso@383 | 215 # architecture |
pankso@383 | 216 # |
pankso@383 | 217 # The deal: we dont want all packages handled by cooker commands and stats, |
pankso@383 | 218 # since we dont cross compile all packages for each arch but only a set of |
paul@388 | 219 # packages to provide one full featured desktop, servers and goodies useful |
pankso@383 | 220 # for the host system. |
pankso@383 | 221 # |
al@728 | 222 |
pankso@383 | 223 arch_db() { |
pankso@383 | 224 count=0 |
pankso@391 | 225 echo "Cleaning packages DB : arch.$ARCH" |
pankso@390 | 226 rm -f $wok/*/arch.$ARCH && cd $wok |
pankso@383 | 227 echo "Creating $ARCH packages DB..." |
al@728 | 228 for pkg in *; do |
pascal@693 | 229 HOST_ARCH= |
pascal@693 | 230 . $wok/$pkg/receipt |
pascal@693 | 231 if [ -n "$HOST_ARCH" ]; then |
pankso@678 | 232 if $(echo "$HOST_ARCH" | egrep -q "$ARCH|any"); then |
pankso@678 | 233 count=$(($count + 1)) |
pankso@678 | 234 echo "Adding: $pkg" |
pankso@678 | 235 touch $pkg/arch.$ARCH |
pankso@678 | 236 fi |
pankso@678 | 237 unset HOST_ARCH |
pankso@678 | 238 else |
pankso@678 | 239 # HOST_ARCH not set --> in i486 |
al@728 | 240 if [ "$ARCH" == 'i486' ]; then |
pankso@678 | 241 count=$(($count + 1)) |
pankso@678 | 242 echo "Adding: $pkg" |
pankso@678 | 243 touch $pkg/arch.$ARCH |
pankso@678 | 244 fi |
pankso@383 | 245 fi |
pankso@383 | 246 done |
pankso@391 | 247 echo "Packages for $ARCH : $count" |
pankso@383 | 248 } |
pankso@383 | 249 |
al@728 | 250 |
pankso@4 | 251 # |
pankso@4 | 252 # Commands |
pankso@4 | 253 # |
al@728 | 254 |
pascal@764 | 255 previous_command="$(cat $command)" |
pankso@4 | 256 case "$1" in |
pankso@31 | 257 usage|help|-u|-h) |
pankso@4 | 258 usage ;; |
al@728 | 259 |
pankso@31 | 260 setup|-s) |
pankso@4 | 261 # Setup the Cooker environment. |
al@728 | 262 echo -e '\nSetting up the Cooker' |
pankso@349 | 263 mkdir -p $CACHE |
pankso@31 | 264 echo "Cooker setup using: $SLITAZ" | log |
pankso@4 | 265 separator |
al@728 | 266 for pkg in $SETUP_PKGS mercurial rsync tazlito; do |
pankso@4 | 267 [ ! -d "$INSTALLED/$pkg" ] && tazpkg get-install $pkg |
pankso@4 | 268 done |
pankso@4 | 269 mkdir -p $SLITAZ && cd $SLITAZ |
al@728 | 270 if [ -d "${wok}-hg" ]; then |
al@728 | 271 echo -e 'Hg wok already exists.\n' |
al@728 | 272 exit 1 |
al@728 | 273 fi |
al@728 | 274 if [ -d "$wok" ]; then |
al@728 | 275 echo -e 'Build wok already exists.\n' |
al@728 | 276 exit 1 |
al@728 | 277 fi |
pankso@4 | 278 |
pankso@4 | 279 # Directories and files |
pankso@4 | 280 echo "mkdir's and touch files in: $SLITAZ" |
pankso@311 | 281 mkdir -p $PKGS $LOGS $FEEDS $CACHE $SRC |
al@728 | 282 for f in $activity $blocked $broken $commits $cooklist $command; do |
pankso@4 | 283 touch $f |
pankso@4 | 284 done |
pankso@14 | 285 hg clone $WOK_URL ${wok}-hg || exit 1 |
pankso@60 | 286 [ -d "$flavors" ] || hg clone $FLAVORS_URL flavors |
pankso@4 | 287 cp -a ${wok}-hg $wok |
al@728 | 288 separator; newline ;; |
al@728 | 289 |
pankso@383 | 290 arch-db) |
pankso@383 | 291 # Manually create arch packages DB. |
pankso@383 | 292 arch_db ;; |
al@728 | 293 |
pankso@341 | 294 setup-cron) |
pankso@341 | 295 # Create cron job for the cooker. |
pankso@341 | 296 [ "$2" ] || hours=2 |
pankso@341 | 297 if [ ! -f "$crontabs" ]; then |
pankso@341 | 298 mkdir -p /var/spool/cron/crontabs |
pankso@341 | 299 fi |
pankso@341 | 300 if ! fgrep -q /usr/bin/cooker $crontabs; then |
pascal@760 | 301 cat > $crontabs << EOT |
pascal@760 | 302 # Run SliTaz Cooker every $hours hours |
pascal@777 | 303 59 */$hours * * * touch $CACHE/cooker-request |
pascal@760 | 304 */5 * * * * [ $CACHE/cooker-request -nt $CACHE/activity ] && /usr/bin/cooker --output=html |
pascal@777 | 305 */5 * * * * [ -z "$(pidof cooker)" ] && [ -s $CACHE/recook-packages ] && /usr/bin/cooker list $CACHE/recook-packages |
pascal@760 | 306 EOT |
pascal@773 | 307 touch $CACHE/cooker-request $CACHE/recook-packages |
pascal@773 | 308 chmod 666 $CACHE/cooker-request $CACHE/recook-packages |
pankso@341 | 309 killall crond 2>/dev/null && /etc/init.d/crond start |
pankso@341 | 310 fi ;; |
al@728 | 311 |
pankso@341 | 312 check-cron) |
al@728 | 313 if [ ! -f "$crontabs" ]; then |
al@728 | 314 echo "There is no $crontabs here. Use setup-cron option." |
al@728 | 315 exit 1 |
al@728 | 316 fi |
pankso@341 | 317 fgrep /usr/bin/cooker $crontabs ;; |
al@728 | 318 |
pankso@31 | 319 note|-n) |
al@728 | 320 # Blocked a pkg and want others to know why? Post a note! |
al@728 | 321 [ -n "$2" ] && echo "$(date '+%F %R') : $2" >> $cooknotes ;; |
al@728 | 322 |
pankso@31 | 323 notes|-ns) |
pankso@29 | 324 # View cooknotes. |
al@728 | 325 echo -e '\nCooknotes' |
pankso@29 | 326 separator |
pankso@29 | 327 cat $cooknotes |
al@728 | 328 separator; newline ;; |
al@728 | 329 |
pankso@49 | 330 block|-b) |
pankso@49 | 331 # Block a package. |
pankso@49 | 332 [ "$pkg" ] && cook $pkg --block ;; |
al@728 | 333 |
pankso@49 | 334 unblock|-ub) |
pankso@49 | 335 # Unblock a package. |
pankso@49 | 336 [ "$pkg" ] && cook $pkg --unblock ;; |
al@728 | 337 |
pankso@31 | 338 reverse|-r) |
paul@54 | 339 # Cook all reverse dependencies for a package. This command lets us |
paul@54 | 340 # control the Cooker manually for commits that will cook a lot of packages. |
pankso@14 | 341 # |
al@728 | 342 # Use hg commit? Ex: hg commit -m "Message bla bla | cooker:reverse" |
pankso@14 | 343 # |
al@728 | 344 if [ ! -d "$wok/$pkg" ]; then |
al@728 | 345 echo -e "\nNo package $2 found.\n" |
al@728 | 346 exit 0 |
al@728 | 347 fi |
al@728 | 348 rm -f $cooklist; touch $cooklist |
pankso@32 | 349 echo -e "\nReverse cooklist for: $pkg" |
al@728 | 350 separator |
al@728 | 351 |
al@728 | 352 cd $wok |
al@728 | 353 for rev in *; do |
al@728 | 354 unset WANTED DEPENDS BUILD_DEPENDS; . $wok/$rev/receipt |
pascal@273 | 355 if echo "$WANTED $DEPENDS $BUILD_DEPENDS" | fgrep -q $pkg; then |
pankso@32 | 356 echo "$rev" | tee -a $cooklist |
pankso@4 | 357 fi |
al@728 | 358 done |
al@728 | 359 separator |
pankso@32 | 360 echo -e "Reverse dependencies found: $(cat $cooklist | wc -l)\n" |
pankso@32 | 361 strip_blocked |
pankso@32 | 362 cook_order | tee $LOGS/cookorder.log |
pankso@32 | 363 cook_list ;; |
al@728 | 364 |
pankso@31 | 365 pkg|-p) |
pankso@12 | 366 # Same as 'cook pkg' but with log for web interface. |
pascal@765 | 367 ps | grep -q "cook $pkg$" && echo 'Already running' && continue |
pankso@394 | 368 cook $pkg || broken |
pankso@81 | 369 clean_exit ;; |
al@728 | 370 |
pankso@31 | 371 cat|-c) |
pankso@4 | 372 # Cook all packages of a category. |
pankso@31 | 373 cat="$2" |
al@728 | 374 rm -f $cooklist; touch $cooklist |
al@728 | 375 |
al@728 | 376 cd $wok |
al@728 | 377 for pkg in *; do |
al@728 | 378 unset CATEGORY; . $pkg/receipt |
pankso@4 | 379 [ "$CATEGORY" == "$cat" ] && echo $pkg >> $cooklist |
pankso@4 | 380 done |
pankso@14 | 381 strip_blocked |
pankso@14 | 382 cook_order | tee $LOGS/cookorder.log |
pankso@26 | 383 cook_list ;; |
al@728 | 384 |
pankso@31 | 385 flavor|-f) |
pankso@21 | 386 # Cook all packages of a flavor. |
pankso@31 | 387 name="$2" |
al@728 | 388 if [ ! -d "$flavors/$name" ]; then |
al@728 | 389 echo -e "\nSpecified flavor does not exist: $name\n" |
al@728 | 390 exit 1 |
al@728 | 391 fi |
al@728 | 392 if [ -d "$flavors/.hg" ]; then |
al@728 | 393 cd $flavors; hg pull -u |
al@728 | 394 fi |
al@728 | 395 list="$flavors/$name/packages.list" |
pankso@21 | 396 cp -a $list $cooklist |
pankso@21 | 397 strip_blocked |
pankso@21 | 398 cook_order | tee $LOGS/cookorder.log |
pankso@32 | 399 cook_list ;; |
al@728 | 400 |
pankso@31 | 401 list|-l) |
paul@54 | 402 # Cook a list of packages given in argument. |
pankso@31 | 403 list="$2" |
al@728 | 404 if [ ! -f "$list" ]; then |
al@728 | 405 echo -e "\nSpecified list does not exist: $list\n" |
al@728 | 406 exit 1 |
al@728 | 407 fi |
pascal@774 | 408 cat $list >> $cooklist |
pascal@774 | 409 echo -n > $list |
pankso@26 | 410 strip_blocked |
pankso@98 | 411 cook_order | tee $LOGS/cookorder.log |
pankso@98 | 412 cook_list ;; |
al@728 | 413 |
pankso@79 | 414 rev|-r) |
pankso@79 | 415 # Cook or recook a specific Hg revision. |
pankso@79 | 416 rev="$2" |
pankso@79 | 417 [ "$rev" ] || exit 0 |
al@728 | 418 rm -f $cooklist; touch $cooklist |
al@728 | 419 |
pankso@79 | 420 cd $wok |
al@728 | 421 for pkg in $(hg log --rev=$rev --template "{files}"); do |
al@728 | 422 echo "$pkg" | cut -d/ -f1 >> $cooklist |
pankso@79 | 423 done |
pankso@79 | 424 strip_blocked |
pankso@26 | 425 cook_order | tee $LOGS/cookorder.log |
pankso@26 | 426 cook_list ;; |
al@728 | 427 |
pankso@31 | 428 all|-a) |
pankso@4 | 429 # Try to build all unbuilt packages except blocked's. |
al@728 | 430 echo 'cooker:all' > $command |
al@728 | 431 rm -f $cooklist; touch $cooklist |
al@728 | 432 newline |
al@728 | 433 echo 'Cooker cooklist' |
pankso@4 | 434 separator |
pankso@383 | 435 |
pankso@118 | 436 # Find all unbuilt packages. Get EXTRAVERSION from packed receipt |
paul@132 | 437 # if it exists since extra version is added when packing the package. |
al@728 | 438 echo 'Searching for all unbuilt packages' | log |
al@728 | 439 |
al@728 | 440 cd $wok |
al@728 | 441 for pkg in *; do |
pankso@118 | 442 unset EXTRAVERSION |
pankso@4 | 443 . $pkg/receipt |
pankso@118 | 444 [ -f "$pkg/taz/$PACKAGE-$VERSION/receipt" ] && \ |
pankso@118 | 445 . $pkg/taz/$PACKAGE-$VERSION/receipt |
al@728 | 446 if [ ! -f "$PKGS/$PACKAGE-$VERSION$EXTRAVERSION.tazpkg" ]; then |
al@728 | 447 echo $pkg; echo $pkg >> $cooklist |
pankso@118 | 448 fi |
pankso@4 | 449 done |
pankso@14 | 450 strip_blocked |
pankso@99 | 451 cook_order | tee $LOGS/cookorder.log |
pankso@13 | 452 echo "Packages to cook: $(cat $cooklist | wc -l)" | log |
pankso@79 | 453 cook_list ;; |
al@728 | 454 |
pankso@4 | 455 *) |
pankso@81 | 456 # Default is to cook all commits if not yet running. |
al@728 | 457 [ -n "$1" ] && usage |
slaxemulator@489 | 458 cooklist=$commits |
pankso@81 | 459 if [ -f "$pidfile" ]; then |
slaxemulator@488 | 460 pid=$(cat $pidfile) |
pascal@274 | 461 if [ -s /proc/$pid/status ]; then |
al@728 | 462 echo -e "\nStill cooking latest commits with pid:" |
al@728 | 463 echo -e " $pid\n" |
al@728 | 464 exit 0 |
pascal@274 | 465 fi |
pascal@274 | 466 rm -f "$pidfile" |
pankso@81 | 467 fi |
pankso@81 | 468 |
pankso@81 | 469 # Start and get a PID file. |
pankso@14 | 470 rm -f $LOGS/commits.log |
slaxemulator@486 | 471 newline |
al@728 | 472 echo 'Checking for commits' | log_commits |
pankso@14 | 473 separator | tee -a $LOGS/commits.log |
pankso@383 | 474 |
pankso@82 | 475 echo $$ > $pidfile |
pankso@233 | 476 trap 'echo -e "\nCooker stopped: PID $$\n" && \ |
pankso@233 | 477 rm -f $pidfile $command && exit 1' INT TERM |
pankso@383 | 478 |
pankso@82 | 479 echo "Cooker PID : $$" | log_commits |
al@728 | 480 echo "Cooker date : $(date '+%F %T')" | log_commits |
pankso@383 | 481 |
paul@132 | 482 # Get revisions. Here we have 2 echoes since we want a msg on screen, |
paul@132 | 483 # in commits log and activity DB without a space before. |
pankso@60 | 484 cd $wok || exit 1 |
pankso@4 | 485 cur=$(hg head --template '{rev}\n') |
pankso@82 | 486 echo "Updating wok : ${wok}-hg (rev $cur)" | log_commits |
pankso@82 | 487 echo "Updating wok: ${wok}-hg" | log |
al@728 | 488 echo 'hg:pull' > $command |
al@728 | 489 cd $wok-hg; hg pull -u | log_commits |
pankso@4 | 490 new=$(hg head --template '{rev}\n') |
paul@168 | 491 # Store last rev to be used by CGI so it doesn't need to call hg head |
pankso@164 | 492 # on each load. |
slaxemulator@488 | 493 echo "$new" > $wokrev |
pankso@383 | 494 |
paul@54 | 495 # Sync build wok with rsync so we don't take care about removing old |
pankso@4 | 496 # files as before. |
pankso@4 | 497 if [ "$new" -gt "$cur" ]; then |
pankso@4 | 498 echo "Changes found from: $cur to $new" | log |
al@728 | 499 echo 'Syncing build wok with Hg wok...' | log_commits |
al@728 | 500 rsync -r -t -c -l -u -v -D -E $wok-hg/ $wok/ | \ |
pankso@35 | 501 sed '/^$/'d | log_commits |
pankso@4 | 502 else |
pankso@13 | 503 echo "No revision changes: $cur vs $new" | log |
pankso@14 | 504 separator | log_commits |
al@728 | 505 clean_exit; newline |
al@728 | 506 exit 0 |
pankso@4 | 507 fi |
pankso@383 | 508 |
pankso@35 | 509 # Get and display modifications. |
al@728 | 510 cd $wok-hg |
pankso@110 | 511 commits_summary | log_commits |
pankso@14 | 512 cur=$(($cur + 1)) |
al@728 | 513 rm -f $commits.tmp; touch $commits.tmp |
al@728 | 514 for rev in $(seq $cur $new); do |
al@728 | 515 for file in $(hg log --rev=$rev --template "{files}"); do |
al@728 | 516 pkg=$(echo $file | cut -d/ -f1) |
pankso@36 | 517 desc=$(hg log --rev=$rev --template "{desc}" $file) |
paul@388 | 518 echo "Committed package : $pkg - $desc" | log_commits |
pankso@80 | 519 echo $pkg >> $commits.tmp |
pankso@4 | 520 done |
pankso@4 | 521 done |
pankso@248 | 522 |
pankso@248 | 523 # We may have deleted packages and files in stuff/. Remove it and |
pankso@248 | 524 # clean DB as well as log file. |
pankso@248 | 525 cd $wok |
al@728 | 526 for pkg in *; do |
pankso@248 | 527 if [ ! -d "${wok}-hg/$pkg" ]; then |
pankso@248 | 528 echo "Removing package: $pkg" | log_commits |
pankso@248 | 529 . $wok/$pkg/receipt |
pankso@248 | 530 rm -rf $PKGS/$PACKAGE-$VERSION* $wok/$pkg $LOGS/$pkg.log |
slaxemulator@489 | 531 sed -i "/^${pkg}$/"d $blocked $broken $commits.tmp |
pankso@248 | 532 fi |
pankso@248 | 533 done |
pankso@383 | 534 |
paul@54 | 535 # Keep previous commit and discard duplicate lines |
pankso@4 | 536 cat $commits $commits.tmp | sed /"^$"/d > $commits.new |
al@728 | 537 uniq $commits.new > $commits; rm $commits.* |
pankso@383 | 538 |
paul@388 | 539 # Handle cross compilation. Create arch packages DB and remove pkgs |
pankso@383 | 540 # not cooked for this arch from the commits list. |
pankso@677 | 541 arch_db |
al@728 | 542 for pkg in $(cat $commits); do |
pankso@677 | 543 if [ ! -f "$wok/$pkg/arch.$ARCH" ]; then |
pankso@677 | 544 echo "Cooker arch : skip $pkg (not included in: $ARCH)" | \ |
pankso@677 | 545 log_commits |
pankso@677 | 546 sed -i "/^${pkg}$/"d $commits |
pankso@677 | 547 else |
pankso@677 | 548 echo "Cooker arch : $ARCH" | log_commits |
pankso@677 | 549 fi |
pankso@677 | 550 done |
al@728 | 551 |
pankso@383 | 552 # Stats |
pankso@109 | 553 pkgs=$(cat $commits | wc -l) |
pankso@100 | 554 echo "Packages to cook: $pkgs" | log |
pankso@109 | 555 echo "Packages to cook : $pkgs" | log_commits |
pankso@35 | 556 separator | log_commits |
slaxemulator@486 | 557 newline |
pankso@14 | 558 strip_blocked |
pankso@14 | 559 cook_order | tee $LOGS/cookorder.log |
pankso@81 | 560 cook_commits |
pankso@81 | 561 clean_exit ;; |
pankso@4 | 562 esac |
pankso@4 | 563 |
pankso@4 | 564 exit 0 |