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.

225 lines
5.1 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 - 2013 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="$(echo ${0##*/} | tr '-' ' ')"
  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. remove_package() {
  74. local root="$1" pkg="$2"
  75. local flist="$root/var/adm/flists/$pkg"
  76. local tag= f=
  77. if [ ! -s "$flist" ]; then
  78. echo_warning "$pkg: $flist not found."
  79. return
  80. fi
  81. sort -r "$flist" | while read tag f; do
  82. if [ "$tag" != "$pkg:" ]; then
  83. echo_warning "$pkg: invalid tag '$tag' in $flist"
  84. elif [ -z "$f" ]; then
  85. echo_warning "$pkg: missing filename in $flist"
  86. else
  87. f="$root/$f"
  88. if [ ! -L "$f" -a -d "$f" ]; then
  89. rmdir --ignore-fail-on-non-empty -- "$f"
  90. else
  91. rm -f -- "$f"
  92. fi
  93. fi
  94. done
  95. }
  96. reschedule_package()
  97. {
  98. local config="$1" pkg= sandbox=
  99. local logs= log=
  100. shift
  101. [ $# -gt 0 ] || return
  102. sandbox="$SDEROOT/build/$( config_id "$config" )"
  103. for pkg; do
  104. logs=$(ls -1 "$sandbox/var/adm/logs"/?-$pkg.{err,out,log} \
  105. 2> /dev/null)
  106. [ -n "$logs" -o -s "$sandbox/var/adm/packages/$pkg" ] || continue
  107. echo "$config: Removing $pkg..."
  108. if [ "$reschedule_dry" != "yes" ]; then
  109. [ "$reschedule_soft" = "yes" ] || remove_package "$sandbox" "$pkg"
  110. # in the case $SDEROOT includes spaces
  111. echo "$logs" | while read log; do
  112. rm -f "$log"
  113. done
  114. fi
  115. done
  116. }
  117. # which configs?
  118. #
  119. if [ "$reschedule_any" = "yes" ]; then
  120. reschedule_configs=$( config_list )
  121. [ -n "$reschedule_configs" ] || echo_abort 1 "No config found."
  122. elif [ -z "$reschedule_configs" ]; then
  123. # try default
  124. y="$( config_id default )"
  125. if [ -z "$y" ]; then
  126. echo_abort 1 "No config found."
  127. elif [ -d "$SDEROOT/build/$y/" ]; then
  128. reschedule_configs=default
  129. else
  130. exit 0
  131. fi
  132. else
  133. z="$reschedule_configs"
  134. reschedule_configs=
  135. for x in $z; do
  136. y=$( config_id "$x" )
  137. if [ -z "$y" ]; then
  138. echo_warning "$x: Invalid config."
  139. elif [ -d "$SDEROOT/build/$y/" ]; then
  140. reschedule_configs="$reschedule_configs $x"
  141. fi
  142. done
  143. fi
  144. # any config ?
  145. [ -n "$reschedule_configs" ] || exit 0
  146. if [ "$reschedule_all" = "yes" ]; then
  147. # every single package
  148. #
  149. for x in $reschedule_configs; do
  150. y="$SDEROOT/build/$( config_id $x )/var/adm/logs"
  151. reschedule_package "$x" $( ls -1d "$y"/* 2> /dev/null |
  152. sed -e 's|.*/.-\(.*\)\..*|\1|' )
  153. done
  154. exit $?
  155. elif [ -n "$reschedule_new" ]; then
  156. # every modified package
  157. #
  158. $SDEROOT/bin/sde-reschedule-new \
  159. ${reschedule_dry:+--dry-run} \
  160. ${reschedule_dependers:+--deps} \
  161. ${reschedule_soft:+--soft} \
  162. $reschedule_configs
  163. fi
  164. reschedule_packages=
  165. for x; do
  166. if package_exists "$x"; then
  167. # in db
  168. reschedule_packages="$reschedule_packages $x"
  169. elif [ "$reschedule_force" = yes ]; then
  170. echo_warning "$x: Unknown package, but forcing..."
  171. reschedule_packages="$reschedule_packages $x"
  172. else
  173. echo_warning "$x: Invalid package"
  174. fi
  175. done
  176. [ -n "$UID" ] || UID=$(id -u)
  177. [ "$UID" = 0 -o "$reschedule_dry" = "yes" ] ||
  178. echo_abort 1 "You have to be superuser to proceed, sorry."
  179. set -- $reschedule_packages
  180. for x in $reschedule_configs; do
  181. reschedule_package "$x" "$@"
  182. if [ "$reschedule_dependers" = "yes" ]; then
  183. $SDEROOT/bin/sde-reschedule-dependers \
  184. ${reschedule_dry:+--dry-run} \
  185. ${reschedule_soft:+--soft} \
  186. -c "$x" "$@"
  187. fi
  188. done