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.

199 lines
4.6 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. #Alias: pkg
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . "$SDEROOT/lib/libsde.in"
  20. reschedule_usage() {
  21. local progname=${0##*/}
  22. cat <<EOT
  23. Usage: ${progname//-/ } [<options>] <package_1> ...
  24. Supported Options:
  25. --all|-a every package
  26. --new|-N every package updated since it was built
  27. --deps|-D every package depending on the others
  28. --cfg|-c <config> process a given config (multiple supported)
  29. --any|-A process any available config
  30. --dry-run|-n don't really reschedule
  31. --soft|-s don't remove the packages when rescheduling
  32. --force|-f try to remove them even if we can't validate the package
  33. EOT
  34. }
  35. shortopts='aNDc:Ansf'
  36. longopts='help,all,new,deps,cfg:,any,soft,dry-run,force'
  37. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  38. if [ $? -ne 0 ]; then
  39. reschedule_usage
  40. exit -1
  41. fi
  42. # load new arguments list
  43. eval set -- "$options"
  44. reschedule_all=
  45. reschedule_new=
  46. reschedule_dependers=
  47. reschedule_any=
  48. reschedule_soft=
  49. reschedule_dry=
  50. reschedule_force=
  51. reschedule_configs=
  52. while [ $# -gt 0 ]; do
  53. case "$1" in
  54. --help)
  55. reschedule_usage
  56. exit 0 ;;
  57. --all|-a) reschedule_all=yes ;;
  58. --new|-N) reschedule_new=yes ;;
  59. --deps|-D) reschedule_dependers=yes ;;
  60. --any|-A) reschedule_any=yes ;;
  61. --soft|-s) reschedule_soft=yes ;;
  62. --dry-run|-n) reschedule_dry=yes ;;
  63. --force|-f) reschedule_force=yes ;;
  64. --cfg|-c) reschedule_configs="$reschedule_configs $2"
  65. shift ;;
  66. --) shift; break ;;
  67. *) echo_abort 1 "$1: Unknown argument, aborting."
  68. esac
  69. shift
  70. done
  71. . "$SDEROOT/lib/sde-config.in"
  72. . "$SDEROOT/lib/sde-package.in"
  73. reschedule_package()
  74. {
  75. local config="$1" pkg= sandbox=
  76. local logs= log=
  77. shift
  78. [ $# -gt 0 ] || return
  79. sandbox="$SDEROOT/build/$( config_id "$config" )"
  80. for pkg; do
  81. logs=$(ls -1 "$sandbox/var/adm/logs"/?-$pkg.{err,out,log} \
  82. 2> /dev/null)
  83. [ -n "$logs" -o -s "$sandbox/var/adm/packages/$pkg" ] || continue
  84. echo "$config: Removing $pkg..."
  85. if [ "$reschedule_dry" != "yes" ]; then
  86. if [ "$reschedule_soft" != "yes" ]; then
  87. mine -rf -R "$sandbox" "$pkg"
  88. fi
  89. # in the case $SDEROOT includes spaces
  90. echo "$logs" | while read log; do
  91. rm -f "$log"
  92. done
  93. fi
  94. done
  95. }
  96. # which configs?
  97. #
  98. if [ "$reschedule_any" = "yes" ]; then
  99. reschedule_configs=$( config_list )
  100. [ -n "$reschedule_configs" ] || echo_abort 1 "No config found."
  101. elif [ -z "$reschedule_configs" ]; then
  102. # try default
  103. y="$( config_id default )"
  104. if [ -z "$y" ]; then
  105. echo_abort 1 "No config found."
  106. elif [ -d "$SDEROOT/build/$y/" ]; then
  107. reschedule_configs=default
  108. else
  109. exit 0
  110. fi
  111. else
  112. z="$reschedule_configs"
  113. reschedule_configs=
  114. for x in $z; do
  115. y=$( config_id "$x" )
  116. if [ -z "$y" ]; then
  117. echo_warning "$x: Invalid config."
  118. elif [ -d "$SDEROOT/build/$y/" ]; then
  119. reschedule_configs="$reschedule_configs $x"
  120. fi
  121. done
  122. fi
  123. # any config ?
  124. [ -n "$reschedule_configs" ] || exit 0
  125. if [ "$reschedule_all" = "yes" ]; then
  126. # every single package
  127. #
  128. for x in $reschedule_configs; do
  129. y="$SDEROOT/build/$( config_id $x )/var/adm/logs"
  130. reschedule_package "$x" $( ls -1d "$y"/* 2> /dev/null |
  131. sed -e 's|.*/.-\(.*\)\..*|\1|' )
  132. done
  133. exit $?
  134. elif [ -n "$reschedule_new" ]; then
  135. # every modified package
  136. #
  137. $SDEROOT/bin/sde-reschedule-new \
  138. ${reschedule_dry:+--dry-run} \
  139. ${reschedule_dependers:+--deps} \
  140. ${reschedule_soft:+--soft} \
  141. $reschedule_configs
  142. fi
  143. reschedule_packages=
  144. for x; do
  145. if package_exists "$x"; then
  146. # in db
  147. reschedule_packages="$reschedule_packages $x"
  148. elif [ "$reschedule_force" = yes ]; then
  149. echo_warning "$x: Unknown package, but forcing..."
  150. reschedule_packages="$reschedule_packages $x"
  151. else
  152. echo_warning "$x: Invalid package"
  153. fi
  154. done
  155. [ $UID -eq 0 -o "$reschedule_dry" = "yes" ] ||
  156. echo_abort 1 "You have to be superuser to proceed, sorry."
  157. set -- $reschedule_packages
  158. for x in $reschedule_configs; do
  159. reschedule_package "$x" "$@"
  160. if [ "$reschedule_dependers" = "yes" ]; then
  161. $SDEROOT/bin/sde-reschedule-dependers \
  162. ${reschedule_dry:+--dry-run} \
  163. ${reschedule_soft:+--soft} \
  164. -c "$x" "$@"
  165. fi
  166. done