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.

250 lines
5.7 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: scripts/Emerge-Pkg
  6. # Copyright (C) 2006 - 2011 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. #
  9. # More information can be found in the files COPYING and README.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; version 2 of the License. A copy of the
  14. # GNU General Public License can be found in the file COPYING.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. exec 2>&1
  17. blacklist=" fhs binutils gcc glibc uclibc linux24 linux linux-header "
  18. options=
  19. config=default
  20. deps=fast
  21. debug=0
  22. downloadonly=0
  23. verbose=1
  24. ignore_chksum=1
  25. update=1
  26. dryrun=0
  27. force=0
  28. rebuild=1
  29. repositories=
  30. system=0
  31. depth=0
  32. #
  33. # ---- Functions
  34. #
  35. . lib/functions.in
  36. help_msg() {
  37. spacer=" "
  38. echo
  39. echo "Usage: Emerge-Pkg [ -cfg <config> ] [ -dry-run ] [ -force ] [ -noupdate ]"
  40. echo "$spacer [ -consider-chksum ] [ -norebuild ]"
  41. echo "$spacer [ -deps=none|fast|indirect ] [ -download-only ]"
  42. echo "$spacer [ -repository repository-name ] [ -system ] [ pkg-name(s) ]"
  43. echo
  44. echo "pkg-name(s) are only optional if a repository is specified."
  45. echo
  46. }
  47. #
  48. # ---- Parse options + config
  49. #
  50. if [ $# = 0 ]; then
  51. help_msg
  52. exit 1
  53. fi
  54. while [ "$1" ] ; do
  55. case "$1" in
  56. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  57. -deps=*) deps=${1/-deps=/} ;;
  58. -dry-run) dryrun=1 ;;
  59. -force) force=1 ;;
  60. -debug) debug=1 ;;
  61. -noupdate) update=0 ;;
  62. -consider-chksum) ignore_chksum=0 ;;
  63. -norebuild) rebuild=0 ;;
  64. -download-only) downloadonly=1 ;;
  65. -repository) repositories="$repositories $2"
  66. deps=none ; shift ;;
  67. -prefix) options="$options -prefix $2" ; shift ;;
  68. -system) system=1 ; deps=none ;;
  69. -*) help_msg ; exit 1 ;;
  70. *) break ;;
  71. esac
  72. shift
  73. done
  74. . lib/parse-config
  75. add_if_req()
  76. {
  77. [ "$verbose" = 1 ] && echo -n "$1"
  78. if [ $depth != 0 -a "$blacklist" != "${blacklist/ $package /}" ]; then
  79. [ $verbose = 1 ] && echo " Automatic update avoided."
  80. else
  81. [ $verbose = 1 ] && echo " Added."
  82. var_append deplist " " "$package"
  83. [ $deps = indirect ] && dep4pkg "$package"
  84. fi
  85. }
  86. add_if_updated()
  87. {
  88. local package=$1
  89. # some variable name mangling ...
  90. local var=__BEEN_HERE_${package//-/_}
  91. var=${var//+/_}
  92. eval local x=\$$var
  93. if [ "$x" = 1 ]; then
  94. [ $debug = 1 ] && echo "already been at $package ..."
  95. return
  96. else
  97. eval $var=1
  98. fi
  99. [ $verbose = 1 ] && echo -n "checking $package ..."
  100. confdir=
  101. for x in package/*/$package/$package.desc; do
  102. if [ -f "$x" ]; then
  103. if [ "$confdir" ]; then
  104. echo " Error: Package in multiple trees!"
  105. return
  106. fi
  107. confdir=${x/$package.desc/}
  108. fi
  109. done
  110. if [ -z "$confdir" ]; then
  111. echo " Error: No such package."
  112. return
  113. fi
  114. if [ ! -f /var/adm/packages/$package ]; then
  115. add_if_req ' Not installed.'
  116. return
  117. fi
  118. o_ver=$(grep '^Package Name and Version' \
  119. /var/adm/packages/$package | cut -f6 -d' ')
  120. n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ')
  121. if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
  122. add_if_req " New version ($o_ver -> $n_ver)."
  123. return
  124. fi
  125. o_ck=$(grep '^\(ROCK Linux\|T2\|OpenSDE\) Package Source Checksum' \
  126. /var/adm/packages/$package | sed 's,.*: ,,')
  127. n_ck=$( pkgchksum package/*/$package )
  128. if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
  129. add_if_req " New source checksum."
  130. return
  131. fi
  132. if [ -f /var/adm/cache/$package ] &&
  133. grep -q '\[BUILDTIME\] .* ERROR' \
  134. /var/adm/cache/$package; then
  135. [ $verbose = 1 ] && echo -n " Former build was broken."
  136. if [ $rebuild = 1 ]; then
  137. add_if_req ''
  138. else
  139. [ $verbose = 1 ] && echo " Skipped."
  140. fi
  141. return
  142. fi
  143. if [ $force = 1 -a $depth = 0 ]; then
  144. add_if_req ' Build forced.'
  145. return
  146. fi
  147. if [ $debug = 1 ]; then
  148. echo " Installed and up-to-date."
  149. else
  150. echo -ne \
  151. "\r \r"
  152. fi
  153. }
  154. dep4pkg()
  155. {
  156. : $(( depth++ ))
  157. for x in `grep '\[DEP\]' package/*/$1/$1.cache 2>/dev/null |
  158. cut -d ' ' -f 2`; do
  159. add_if_updated $x
  160. done
  161. : $(( depth-- ))
  162. }
  163. # the remaining arguments are packages to be built
  164. for x in $*; do
  165. add_if_updated $x
  166. done
  167. # packages from repositories
  168. for x in $repositories ; do
  169. for x in `egrep "^X .* $x .*" config/$config/packages |
  170. cut -d ' ' -f 5`; do
  171. add_if_updated $x
  172. done
  173. done
  174. # all packages if a system update
  175. if [ $system -eq 1 ]; then
  176. for x in `grep "^X" config/$config/packages | cut -d ' ' -f 5`; do
  177. add_if_updated $x
  178. done
  179. fi
  180. case $deps in
  181. fast|indirect)
  182. # we have to create a complete dependency graph ...
  183. tmp=`mktemp`
  184. for x in $deplist ; do
  185. dep4pkg $x
  186. done
  187. ;;
  188. none)
  189. ;;
  190. *)
  191. echo "Unknown dependency resolution mode. Valid are none and fast."
  192. exit 1
  193. esac
  194. # sort by priority
  195. deplist=`echo -n $deplist | tr '\n' ' ' | tr -s ' '`
  196. deplist=`grep "^. .* .* .* \\(${deplist// /\\|}\\) " \
  197. config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' '`
  198. echo "Packages scheduled to build: ${deplist:-none}"
  199. [ $dryrun = 1 ] && exit
  200. # the deplist is quite unsorted (in alphabetically sorted chunks)
  201. # so we need to work arround this here ...
  202. [ $update = 1 ] && options="$options -update"
  203. . config/$config/config
  204. for package in $deplist ; do
  205. if ./bin/sde-download $package ; then [ $downloadonly != 1 ] && \
  206. if ! ./scripts/Build-Pkg $options $package; then
  207. if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
  208. echo "Aborting further builds, check SDECFG_CONTINUE_ON_ERROR_AFTER."
  209. exit 1
  210. fi
  211. fi
  212. else
  213. echo "The download for package $package failed!"
  214. exit 1
  215. fi
  216. done