mirror of the now-defunct rocklinux.org
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.

264 lines
6.4 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Emerge-Pkg
  11. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. exec 2>&1
  25. options=''
  26. config=default
  27. builddep=0
  28. debug=0
  29. ignore_chksum=0
  30. update=1
  31. dryrun=0
  32. rebuild=1
  33. repositories=""
  34. #
  35. # ---- Functions
  36. #
  37. . scripts/functions
  38. help_msg() {
  39. spacer=" "
  40. echo
  41. echo "Usage: ./scripts/Emerge-Pkg" \
  42. "[ -cfg <config> ] [ -dep ] [ -dry-run ]"
  43. echo "$spacer [ -noupdate ] [ -ignore-chksum ] [ -norebuild ]"
  44. echo "$spacer [ -repository repository-name ] [ -debug ]"
  45. echo "$spacer [ pkg-name(s) ]"
  46. echo "pkg-name(s) are only optional if a repository is specified!"
  47. echo
  48. echo "Type './scripts/Help Emerge-Pkg' for details."
  49. echo
  50. }
  51. #
  52. # ---- Parse options + config
  53. #
  54. if [ $# = 0 ]; then
  55. help_msg
  56. exit 1
  57. fi
  58. while [ "$1" ] ; do
  59. case "$1" in
  60. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  61. -debug) debug=1 ;;
  62. -dep) builddep=1 ;;
  63. -dry-run) dryrun=1 ;;
  64. -noupdate) update=0 ;;
  65. -ignore-chksum) ignore_chksum=1 ;;
  66. -norebuild) rebuild=0 ;;
  67. -repository) repositories="$repositories $2" ; shift ;;
  68. -*) help_msg ; exit 1 ;;
  69. *) break ;;
  70. esac
  71. shift
  72. done
  73. . ./scripts/parse-config
  74. check4update()
  75. {
  76. addlist=""
  77. for package in $deplist ; do
  78. [ "$debug" = 1 ] && echo "checking $package ..."
  79. confdir=""
  80. for x in package/*/$package/$package.desc ; do
  81. if [ -f "$x" ] ; then
  82. if [ -z "$confdir" ] ; then
  83. confdir=${x/$package.desc/}
  84. else
  85. confdir=X
  86. fi
  87. fi
  88. done
  89. if [ -z "$confdir" ] ; then
  90. [ $debug = 1 ] && \
  91. echo " $package: No such package."
  92. elif [ "$confdir" = X ] ; then
  93. [ $debug = 1 ] && \
  94. echo " $package: Package in multiple trees."
  95. elif [ ! -f /var/adm/packages/$package ] ; then
  96. [ $debug = 1 ] && \
  97. echo " $package: Not installed. Added."
  98. addlist="$addlist $package"
  99. else
  100. o_ver=$(grep '^Package Name and Version' \
  101. /var/adm/packages/$package | cut -f6 -d' ')
  102. n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ')
  103. if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ] ; then
  104. [ $debug = 1 ] && \
  105. echo " $package: New version ($o_ver -> $n_ver). Added."
  106. addlist="$addlist $package"
  107. else
  108. o_ck=$(grep '^ROCK Linux Package Source Checksum' \
  109. /var/adm/packages/$package | cut -f6 -d' ')
  110. n_ck=$(md5sum package/*/$package/* 2> /dev/null | \
  111. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  112. if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ] ; then
  113. [ $debug = 1 ] && \
  114. echo " $package: New source checksum ($n_ck). Added."
  115. addlist="$addlist $package"
  116. else
  117. if [ -f /var/adm/cache/$package ] ; then
  118. if ! grep -q BUILDTIME /var/adm/cache/$package ; then
  119. [ $debug = 1 ] && \
  120. echo -n " $package: Former build was broken."
  121. if [ $rebuild = 1 ] ; then
  122. [ $debug = 1 ] && echo " Added."
  123. addlist="$addlist $package"
  124. else
  125. [ $debug = 1 ] && echo " Skipped."
  126. fi
  127. fi
  128. else
  129. [ $debug = 1 ] && \
  130. echo " $package: Equal source checksum ($n_ck), skipped."
  131. fi
  132. fi
  133. fi
  134. fi
  135. done
  136. deplist="$addlist"
  137. }
  138. dep4pkg() {
  139. gawk -v package=$1 '
  140. function check_package() {
  141. found_new = 0;
  142. for ( package in build_list ) {
  143. if ( debug )
  144. print "#DEBUG PACKAGE: " package;
  145. if ( ! package in database ) {
  146. if (debug)
  147. print "# " package " not in database";
  148. }
  149. else {
  150. if (debug)
  151. print "# " package " in database";
  152. split(database[package], a);
  153. for (d in a) {
  154. # if ( a[c] == package ) continue;
  155. if ( strtonum(d) <= 3 ) continue;
  156. dep = a[d];
  157. if ( debug && 0)
  158. print "# dep: " dep;
  159. if ( dep in build_list ) {
  160. if ( debug && 0)
  161. print "# dep: " dep " already parsed";
  162. }
  163. else {
  164. if (debug)
  165. print "# dep: " dep " now added";
  166. build_list [ dep ] = (package);
  167. found_new = 1;
  168. }
  169. }
  170. }
  171. }
  172. if (found_new)
  173. check_package();
  174. }
  175. BEGIN {
  176. config="'$config'"; debug='$debug';
  177. depdb_file = "scripts/dep_db.txt";
  178. while ( (getline depline < depdb_file) > 0 )
  179. { $0 = depline; sub(/:/, "", $1); database[$1]=$0; }
  180. close(depdb_file);
  181. build_list [ package ] = 1;
  182. check_package();
  183. if (debug) {
  184. for ( bp in build_list ) {
  185. print "# " bp " (" build_list[bp] ")"
  186. }
  187. }
  188. for ( bp in build_list ) {
  189. print bp
  190. }
  191. }
  192. '
  193. }
  194. # all packages
  195. deplist="$deplist $@"
  196. # packages from repositories
  197. for x in $repositories ; do
  198. deplist="$deplist ` egrep "^X .* $x .*" config/$config/packages | \
  199. cut -d ' ' -f 5`"
  200. # only build packages that need an update
  201. check4update
  202. done
  203. if [ $builddep = 1 ] ; then
  204. # we have to create a complete dependency graph ...
  205. tmp="`mktemp`"
  206. for x in $deplist ; do
  207. dep4pkg $x >> $tmp
  208. done
  209. [ "$debug" = 1 ] && grep '^#' $tmp
  210. deplist="$deplist `grep -v '^#' $tmp`"
  211. rm $tmp
  212. # only build packages that need an update
  213. check4update
  214. fi
  215. echo "Packages scheduled to build: $deplist"
  216. [ $dryrun = 1 ] && exit
  217. # the deplist is quite unsorted (in alphabetically sorted chunks)
  218. # so we need to work arround this here ...
  219. [ $update = 1 ] && options="$options -update"
  220. for package in $deplist ; do
  221. if ./scripts/Download -package $package ; then
  222. ./scripts/Build-Pkg $options $package
  223. else
  224. echo "The download for package $package failed!"
  225. exit -1
  226. fi
  227. done