OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
4.3 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-reschedule-package
  6. # Copyright (C) 2008 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Reschedule packages from the builds
  16. [ -n "$SDEROOT" ] ||
  17. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  18. . "$SDEROOT/lib/libsde.in"
  19. reschedule_usage() {
  20. local progname=${0##*/}
  21. cat <<EOT
  22. Usage: ${progname//-/ } [<options>] <package_1> ...
  23. Supported Options:
  24. --all|-a every package
  25. --new|-N every package updated since it was built
  26. --deps|-D every package depending on the others
  27. --cfg|-c <config> process a given config (multiple supported)
  28. --any|-A process any available config
  29. --dry-run|-n don't really reschedule
  30. --soft|-s don't remove the packages when rescheduling
  31. EOT
  32. }
  33. shortopts='aNDc:Ans'
  34. longopts='help,all,new,deps,cfg:,any,soft,dry-run'
  35. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  36. if [ $? -ne 0 ]; then
  37. reschedule_usage
  38. exit -1
  39. fi
  40. # load new arguments list
  41. eval set -- "$options"
  42. reschedule_all=
  43. reschedule_new=
  44. reschedule_dependers=
  45. reschedule_any=
  46. reschedule_soft=
  47. reschedule_dry=
  48. reschedule_configs=
  49. while [ $# -gt 0 ]; do
  50. case "$1" in
  51. --help)
  52. reschedule_usage
  53. exit 0 ;;
  54. --all|-a) reschedule_all=yes ;;
  55. --new|-N) reschedule_new=yes ;;
  56. --deps|-D) reschedule_dependers=yes ;;
  57. --any|-A) reschedule_any=yes ;;
  58. --soft|-s) reschedule_soft=yes ;;
  59. --dry-run|-n) reschedule_dry=yes ;;
  60. --cfg|-c) reschedule_configs="$reschedule_configs $2"
  61. shift ;;
  62. --) shift; break ;;
  63. *) echo_abort 1 "$1: Unknown argument, aborting."
  64. esac
  65. shift
  66. done
  67. . "$SDEROOT/lib/sde-config.in"
  68. . "$SDEROOT/lib/sde-package.in"
  69. reschedule_package()
  70. {
  71. local config="$1" pkg= sandbox=
  72. local logs= log=
  73. shift
  74. [ $# -gt 0 ] || return
  75. sandbox="$SDEROOT/build/$( config_id "$config" )"
  76. for pkg; do
  77. logs=$(ls -1 "$sandbox/var/adm/logs"/?-$pkg.{err,out,log} \
  78. 2> /dev/null)
  79. [ -n "$logs" ] || continue
  80. echo "$config: Removing $pkg..."
  81. if [ "$reschedule_dry" != "yes" ]; then
  82. if [ "$reschedule_soft" != "yes" ]; then
  83. mine -rf -R "$sandbox" "$pkg"
  84. fi
  85. # in the case $SDEROOT includes spaces
  86. echo "$logs" | while read log; do
  87. rm -f "$log"
  88. done
  89. fi
  90. done
  91. }
  92. # which configs?
  93. #
  94. if [ "$reschedule_any" = "yes" ]; then
  95. reschedule_configs=$( config_list )
  96. [ -n "$reschedule_configs" ] || echo_abort 1 "No config found."
  97. elif [ -z "$reschedule_configs" ]; then
  98. # try default
  99. y="$( config_id default )"
  100. if [ -z "$y" ]; then
  101. echo_abort 1 "No config found."
  102. elif [ -d "$SDEROOT/build/$y/" ]; then
  103. reschedule_configs=default
  104. else
  105. exit 0
  106. fi
  107. else
  108. z="$reschedule_configs"
  109. reschedule_configs=
  110. for x in $z; do
  111. y=$( config_id "$x" )
  112. if [ -z "$y" ]; then
  113. echo_warning "$x: Invalid config."
  114. elif [ -d "$SDEROOT/build/$y/" ]; then
  115. reschedule_configs="$reschedule_configs $x"
  116. fi
  117. done
  118. fi
  119. # any config ?
  120. [ -n "$reschedule_configs" ] || exit 0
  121. if [ "$reschedule_all" = "yes" ]; then
  122. # every single package
  123. #
  124. for x in $reschedule_configs; do
  125. y="$SDEROOT/build/$( config_id $x )/var/adm/logs"
  126. reschedule_package "$x" $( ls -1d "$y"/* 2> /dev/null |
  127. sed -e 's|.*/.-\(.*\)\..*|\1|' )
  128. done
  129. exit $?
  130. elif [ -n "$reschedule_new" ]; then
  131. # every modified package
  132. #
  133. $SDEROOT/bin/sde-reschedule-new \
  134. ${reschedule_dry:+--dry-run} \
  135. ${reschedule_dependers:+--deps} \
  136. ${reschedule_soft:+--soft} \
  137. $reschedule_configs
  138. fi
  139. reschedule_packages=
  140. for x; do
  141. if package_exists "$x"; then
  142. reschedule_packages="$reschedule_packages $x"
  143. else
  144. echo_warning "$x: Invalid package"
  145. fi
  146. done
  147. [ $UID -eq 0 -o "$reschedule_dry" = "yes" ] ||
  148. echo_abort 1 "You have to be superuser to proceed, sorry."
  149. set -- $reschedule_packages
  150. for x in $reschedule_configs; do
  151. reschedule_package "$x" "$@"
  152. if [ "$reschedule_dependers" = "yes" ]; then
  153. $SDEROOT/bin/sde-reschedule-dependers \
  154. ${reschedule_dry:+--dry-run} \
  155. ${reschedule_soft:+--soft} \
  156. -c "$x" "$@"
  157. fi
  158. done