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.

237 lines
5.7 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. #
  33. # ---- Functions
  34. #
  35. . scripts/functions
  36. help_msg() {
  37. spacer=" "
  38. echo
  39. echo "Usage: ./scripts/Emerge-Pkg" \
  40. "[ -cfg <config> ] [ -dep ] [ -dry-run ]"
  41. echo "$spacer [ -noupdate ] [ -debug ] pkg-name(s)"
  42. echo
  43. echo "Type './scripts/Help Emerge-Pkg' for details."
  44. echo
  45. }
  46. #
  47. # ---- Parse options + config
  48. #
  49. if [ $# = 0 ]; then
  50. help_msg
  51. exit 1
  52. fi
  53. while [ "$1" ] ; do
  54. case "$1" in
  55. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  56. -debug) debug=1 ;;
  57. -dep) builddep=1 ;;
  58. -dry-run) dryrun=1 ;;
  59. -noupdate) update=0 ;;
  60. -*) help_msg ; exit 1 ;;
  61. *) break ;;
  62. esac
  63. shift
  64. done
  65. . ./scripts/parse-config
  66. check4update()
  67. {
  68. addlist=""
  69. for package in $deplist ; do
  70. [ "$debug" = 1 ] && echo "checking $package ..."
  71. confdir=""
  72. for x in package/*/$package/$package.desc ; do
  73. if [ -f "$x" ] ; then
  74. if [ -z "$confdir" ] ; then
  75. confdir=${x/$package.desc/}
  76. else
  77. confdir=X
  78. fi
  79. fi
  80. done
  81. if [ -z "$confdir" ] ; then
  82. [ $debug = 1 ] && \
  83. echo " $package: No such package."
  84. elif [ "$confdir" = X ] ; then
  85. [ $debug = 1 ] && \
  86. echo " $package: Package in multiple trees."
  87. elif [ ! -f /var/adm/packages/$package ] ; then
  88. [ $debug = 1 ] && \
  89. echo " $package: Not installed. Added."
  90. addlist="$addlist $package"
  91. else
  92. o_ver=$(grep '^Package Name and Version' \
  93. /var/adm/packages/$package | cut -f6 -d' ')
  94. n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ')
  95. if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ] ; then
  96. [ $debug = 1 ] && \
  97. echo " $package: New version ($o_ver -> $n_ver). Added."
  98. addlist="$addlist $package"
  99. else
  100. if [ $ignore_chksum = 0 ] ; then
  101. o_ck=$(grep '^ROCK Linux Package Source Checksum' \
  102. /var/adm/packages/$package | cut -f6 -d' ')
  103. n_ck=$(md5sum package/*/$package/* 2> /dev/null | \
  104. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  105. if [ "$o_ck" != "$n_ck" ] ; then
  106. [ $debug = 1 ] && \
  107. echo " $package: New source checksum ($n_ck). Added."
  108. addlist="$addlist $package"
  109. else
  110. if [ -f /var/adm/cache/$package ] ; then
  111. if ! grep -q BUILDTIME /var/adm/cache/$package ; then
  112. [ $debug = 1 ] && \
  113. echo " $package: Former build was broken."
  114. addlist="$addlist $package"
  115. fi
  116. else
  117. [ $debug = 1 ] && \
  118. echo " $package: Equal source checksum ($n_ck), skipped."
  119. fi
  120. fi
  121. fi
  122. fi
  123. fi
  124. done
  125. deplist="$addlist"
  126. }
  127. dep4pkg() {
  128. gawk -v package=$1 '
  129. function check_package() {
  130. found_new = 0;
  131. for ( package in build_list ) {
  132. if ( debug )
  133. print "#DEBUG PACKAGE: " package;
  134. if ( ! package in database ) {
  135. if (debug)
  136. print "# " package " not in database";
  137. }
  138. else {
  139. if (debug)
  140. print "# " package " in database";
  141. split(database[package], a);
  142. for (d in a) {
  143. # if ( a[c] == package ) continue;
  144. if ( strtonum(d) <= 3 ) continue;
  145. dep = a[d];
  146. if ( debug && 0)
  147. print "# dep: " dep;
  148. if ( dep in build_list ) {
  149. if ( debug && 0)
  150. print "# dep: " dep " already parsed";
  151. }
  152. else {
  153. if (debug)
  154. print "# dep: " dep " now added";
  155. build_list [ dep ] = (package);
  156. found_new = 1;
  157. }
  158. }
  159. }
  160. }
  161. if (found_new)
  162. check_package();
  163. }
  164. BEGIN {
  165. config="'$config'"; debug='$debug';
  166. depdb_file = "scripts/dep_db.txt";
  167. while ( (getline depline < depdb_file) > 0 )
  168. { $0 = depline; sub(/:/, "", $1); database[$1]=$0; }
  169. close(depdb_file);
  170. build_list [ package ] = 1;
  171. check_package();
  172. if (debug) {
  173. for ( bp in build_list ) {
  174. print "# " bp " (" build_list[bp] ")"
  175. }
  176. }
  177. for ( bp in build_list ) {
  178. print bp
  179. }
  180. }
  181. '
  182. }
  183. if [ $builddep = 1 ] ; then
  184. # we have to create a complete dependency graph ...
  185. tmp="`mktemp`"
  186. dep4pkg $1 > $tmp
  187. [ "$debug" = 1 ] && grep '^#' $tmp
  188. deplist="`grep -v '^#' $tmp`"
  189. rm $tmp
  190. check4update
  191. else
  192. deplist="$@"
  193. fi
  194. echo "Packages scheduled to build: $deplist"
  195. [ $dryrun = 1 ] && exit
  196. # the deplist is quite unsorted (in alphabetically sorted chunks)
  197. # so we need to work arround this here ...
  198. [ $update = 1 ] && options="$options -update"
  199. for package in $deplist ; do
  200. if ./scripts/Download -package $package ; then
  201. ./scripts/Build-Pkg $options $package
  202. else
  203. echo "The download for package $package failed!"
  204. exit -1
  205. fi
  206. done