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.

280 lines
7.2 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 - 2006 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
  47. echo " Compile/build single packages or whole repositories on the host system. By"
  48. echo " default only new/updated packages will be built. Modified files of packages"
  49. echo " (e.g. configuration files) to build will be backed up before and restored"
  50. echo " after each build."
  51. echo
  52. echo " -cfg <config> the configuration to use"
  53. echo " -dep also build packages specified packages depend on"
  54. echo " -dry-run don't actually build packages; just print what"
  55. echo " would happen"
  56. echo " -noupdate don't backup/restore modified package files"
  57. echo " -ignore-chksum ignore checksums on package source directories (i.e."
  58. echo " package/base/*/) when looking for updated packages"
  59. echo " -norebuild don't build a package if its previous build failed"
  60. echo " -repository <repository-name>"
  61. echo " build all packages in the specified repository"
  62. echo " -debug print various debug information"
  63. echo
  64. echo " pkg-name(s) are only optional if a repository is specified!"
  65. echo
  66. }
  67. #
  68. # ---- Parse options + config
  69. #
  70. if [ $# = 0 ]; then
  71. help_msg
  72. exit 1
  73. fi
  74. while [ "$1" ] ; do
  75. case "$1" in
  76. -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
  77. -debug) debug=1 ;;
  78. -dep) builddep=1 ;;
  79. -dry-run) dryrun=1 ;;
  80. -noupdate) update=0 ;;
  81. -ignore-chksum) ignore_chksum=1 ;;
  82. -norebuild) rebuild=0 ;;
  83. -repository) repositories="$repositories $2" ; shift ;;
  84. -*) help_msg ; exit 1 ;;
  85. *) break ;;
  86. esac
  87. shift
  88. done
  89. . ./scripts/parse-config
  90. check4update()
  91. {
  92. addlist=""
  93. for package in $deplist ; do
  94. [ "$debug" = 1 ] && echo "checking $package ..."
  95. confdir=""
  96. for x in package/*/$package/$package.desc ; do
  97. if [ -f "$x" ] ; then
  98. if [ -z "$confdir" ] ; then
  99. confdir=${x/$package.desc/}
  100. else
  101. confdir=X
  102. fi
  103. fi
  104. done
  105. if [ -z "$confdir" ] ; then
  106. [ $debug = 1 ] && \
  107. echo " $package: No such package."
  108. elif [ "$confdir" = X ] ; then
  109. [ $debug = 1 ] && \
  110. echo " $package: Package in multiple trees."
  111. elif [ ! -f /var/adm/packages/$package ] ; then
  112. [ $debug = 1 ] && \
  113. echo " $package: Not installed. Added."
  114. addlist="$addlist $package"
  115. else
  116. o_ver=$(grep '^Package Name and Version' \
  117. /var/adm/packages/$package | cut -f6 -d' ')
  118. n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ')
  119. if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ] ; then
  120. [ $debug = 1 ] && \
  121. echo " $package: New version ($o_ver -> $n_ver). Added."
  122. addlist="$addlist $package"
  123. else
  124. o_ck=$(grep '^ROCK Linux Package Source Checksum' \
  125. /var/adm/packages/$package | cut -f6 -d' ')
  126. n_ck=$(md5sum package/*/$package/* 2> /dev/null | \
  127. grep -v '\.cache$' | md5sum | cut -f1 -d' ')
  128. if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ] ; then
  129. [ $debug = 1 ] && \
  130. echo " $package: New source checksum ($n_ck). Added."
  131. addlist="$addlist $package"
  132. else
  133. if [ -f /var/adm/cache/$package ] ; then
  134. if ! grep -q BUILDTIME /var/adm/cache/$package ; then
  135. [ $debug = 1 ] && \
  136. echo -n " $package: Former build was broken."
  137. if [ $rebuild = 1 ] ; then
  138. [ $debug = 1 ] && echo " Added."
  139. addlist="$addlist $package"
  140. else
  141. [ $debug = 1 ] && echo " Skipped."
  142. fi
  143. fi
  144. else
  145. [ $debug = 1 ] && \
  146. echo " $package: Equal source checksum ($n_ck), skipped."
  147. fi
  148. fi
  149. fi
  150. fi
  151. done
  152. deplist="$addlist"
  153. }
  154. dep4pkg() {
  155. gawk -v package=$1 '
  156. function check_package() {
  157. found_new = 0;
  158. for ( package in build_list ) {
  159. if ( debug )
  160. print "#DEBUG PACKAGE: " package;
  161. if ( ! package in database ) {
  162. if (debug)
  163. print "# " package " not in database";
  164. }
  165. else {
  166. if (debug)
  167. print "# " package " in database";
  168. split(database[package], a);
  169. for (d in a) {
  170. # if ( a[c] == package ) continue;
  171. if ( strtonum(d) <= 3 ) continue;
  172. dep = a[d];
  173. if ( debug && 0)
  174. print "# dep: " dep;
  175. if ( dep in build_list ) {
  176. if ( debug && 0)
  177. print "# dep: " dep " already parsed";
  178. }
  179. else {
  180. if (debug)
  181. print "# dep: " dep " now added";
  182. build_list [ dep ] = (package);
  183. found_new = 1;
  184. }
  185. }
  186. }
  187. }
  188. if (found_new)
  189. check_package();
  190. }
  191. BEGIN {
  192. config="'$config'"; debug='$debug';
  193. depdb_file = "scripts/dep_db.txt";
  194. while ( (getline depline < depdb_file) > 0 )
  195. { $0 = depline; sub(/:/, "", $1); database[$1]=$0; }
  196. close(depdb_file);
  197. build_list [ package ] = 1;
  198. check_package();
  199. if (debug) {
  200. for ( bp in build_list ) {
  201. print "# " bp " (" build_list[bp] ")"
  202. }
  203. }
  204. for ( bp in build_list ) {
  205. print bp
  206. }
  207. }
  208. '
  209. }
  210. # all packages
  211. deplist="$deplist $@"
  212. # packages from repositories
  213. for x in $repositories ; do
  214. deplist="$deplist ` egrep "^X .* $x .*" config/$config/packages | \
  215. cut -d ' ' -f 5`"
  216. # only build packages that need an update
  217. check4update
  218. done
  219. if [ $builddep = 1 ] ; then
  220. # we have to create a complete dependency graph ...
  221. tmp="`mktemp`"
  222. for x in $deplist ; do
  223. dep4pkg $x >> $tmp
  224. done
  225. [ "$debug" = 1 ] && grep '^#' $tmp
  226. deplist="$deplist `grep -v '^#' $tmp`"
  227. rm $tmp
  228. # only build packages that need an update
  229. check4update
  230. fi
  231. echo "Packages scheduled to build: $deplist"
  232. [ $dryrun = 1 ] && exit
  233. # the deplist is quite unsorted (in alphabetically sorted chunks)
  234. # so we need to work arround this here ...
  235. [ $update = 1 ] && options="$options -update"
  236. for package in $deplist ; do
  237. if ./scripts/Download $package ; then
  238. ./scripts/Build-Pkg $options $package
  239. else
  240. echo "The download for package $package failed!"
  241. exit -1
  242. fi
  243. done