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