early: fixed modprobe
[opensde-nopast.git] / scripts / Emerge-Pkg
blob5d70a1292c2c4568f06ee0f17a25373315fd88e5
1 #!/bin/bash
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: scripts/Emerge-Pkg
6 # Copyright (C) 2006 - 2008 The OpenSDE Project
7 # Copyright (C) 2004 - 2006 The T2 SDE Project
9 # More information can be found in the files COPYING and README.
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 ---
17 exec 2>&1
19 blacklist=" 00-dirtree binutils gcc glibc glibc32 uclibc linux24 linux26 linux-header "
21 options=
22 config=default
23 deps=fast
24 debug=0
25 downloadonly=0
26 verbose=1
27 ignore_chksum=1
28 update=1
29 dryrun=0
30 force=0
31 rebuild=1
32 repositories=
33 system=0
34 depth=0
37 # ---- Functions
40 . lib/functions.in
42 help_msg() {
43 spacer=" "
44 echo
45 echo "Usage: Emerge-Pkg [ -cfg <config> ] [ -dry-run ] [ -force ] [ -noupdate ]"
46 echo "$spacer [ -consider-chksum ] [ -norebuild ]"
47 echo "$spacer [ -deps=none|fast|indirect ] [ -download-only ]"
48 echo "$spacer [ -repository repository-name ] [ -system ] [ pkg-name(s) ]"
49 echo
50 echo "pkg-name(s) are only optional if a repository is specified."
51 echo
55 # ---- Parse options + config
58 if [ $# = 0 ]; then
59 help_msg
60 exit 1
63 while [ "$1" ] ; do
64 case "$1" in
65 -cfg) options="$options $1 $2" ; config="$2" ; shift ;;
66 -deps=*) deps=${1/-deps=/} ;;
67 -dry-run) dryrun=1 ;;
68 -force) force=1 ;;
69 -debug) debug=1 ;;
70 -noupdate) update=0 ;;
71 -consider-chksum) ignore_chksum=0 ;;
72 -norebuild) rebuild=0 ;;
73 -download-only) downloadonly=1 ;;
74 -repository) repositories="$repositories $2"
75 deps=none ; shift ;;
76 -prefix) options="$options -prefix $2" ; shift ;;
77 -system) system=1 ; deps=none ;;
78 -*) help_msg ; exit 1 ;;
79 *) break ;;
80 esac
81 shift
82 done
84 . lib/parse-config
86 add_if_req()
88 [ "$verbose" = 1 ] && echo -n "$1"
90 if [ $depth != 0 -a "$blacklist" != "${blacklist/ $package /}" ]; then
91 [ $verbose = 1 ] && echo " Automatic update avoided."
92 else
93 [ $verbose = 1 ] && echo " Added."
94 var_append deplist " " "$package"
95 [ $deps = indirect ] && dep4pkg "$package"
99 add_if_updated()
101 local package=$1
103 # some variable name mangling ...
104 local var=__BEEN_HERE_${package//-/_}
105 var=${var//+/_}
106 eval local x=\$$var
107 if [ "$x" = 1 ]; then
108 [ $debug = 1 ] && echo "already been at $package ..."
109 return
110 else
111 eval $var=1
114 [ $verbose = 1 ] && echo -n "checking $package ..."
115 confdir=
116 for x in package/*/$package/$package.desc; do
117 if [ -f "$x" ]; then
118 if [ "$confdir" ]; then
119 echo " Error: Package in multiple trees!"
120 return
122 confdir=${x/$package.desc/}
124 done
125 if [ -z "$confdir" ]; then
126 echo " Error: No such package."
127 return
130 if [ ! -f /var/adm/packages/$package ]; then
131 add_if_req ' Not installed.'
132 return
135 o_ver=$(grep '^Package Name and Version' \
136 /var/adm/packages/$package | cut -f6 -d' ')
137 n_ver=$(grep '^\[V\] ' $confdir/$package.desc | cut -f2 -d' ')
138 if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
139 add_if_req " New version ($o_ver -> $n_ver)."
140 return
143 o_ck=$(grep '^\(ROCK Linux\|T2\|OpenSDE\) Package Source Checksum' \
144 /var/adm/packages/$package | sed 's,.*: ,,')
145 n_ck=$( pkgchksum package/*/$package )
146 if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
147 add_if_req " New source checksum."
148 return
151 if [ -f /var/adm/cache/$package ] &&
152 grep -q '\[BUILDTIME\] .* ERROR' \
153 /var/adm/cache/$package; then
154 [ $verbose = 1 ] && echo -n " Former build was broken."
155 if [ $rebuild = 1 ]; then
156 add_if_req ''
157 else
158 [ $verbose = 1 ] && echo " Skipped."
160 return
163 if [ $force = 1 -a $depth = 0 ]; then
164 add_if_req ' Build forced.'
165 return
168 if [ $debug = 1 ]; then
169 echo " Installed and up-to-date."
170 else
171 echo -ne \
172 "\r \r"
176 dep4pkg()
178 : $(( depth++ ))
179 for x in `grep '\[DEP\]' package/*/$1/$1.cache 2>/dev/null |
180 cut -d ' ' -f 2`; do
181 add_if_updated $x
182 done
183 : $(( depth-- ))
186 # the remaining arguments are packages to be built
187 for x in $*; do
188 add_if_updated $x
189 done
191 # packages from repositories
192 for x in $repositories ; do
193 for x in `egrep "^X .* $x .*" config/$config/packages |
194 cut -d ' ' -f 5`; do
195 add_if_updated $x
196 done
197 done
199 # all packages if a system update
200 if [ $system -eq 1 ]; then
201 for x in `grep "^X" config/$config/packages | cut -d ' ' -f 5`; do
202 add_if_updated $x
203 done
206 case $deps in
207 fast|indirect)
208 # we have to create a complete dependency graph ...
209 tmp=`mktemp`
210 for x in $deplist ; do
211 dep4pkg $x
212 done
214 none)
217 echo "Unknown dependency resolution mode. Valid are none and fast."
218 exit 1
219 esac
221 # sort by priority
222 deplist=`echo -n $deplist | tr '\n' ' ' | tr -s ' '`
223 deplist=`grep "^. .* .* .* \\(${deplist// /\\|}\\) " \
224 config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' '`
226 echo "Packages scheduled to build: ${deplist:-none}"
228 [ $dryrun = 1 ] && exit
230 # the deplist is quite unsorted (in alphabetically sorted chunks)
231 # so we need to work arround this here ...
233 [ $update = 1 ] && options="$options -update"
235 . config/$config/config
237 for package in $deplist ; do
238 if ./bin/sde-download $package ; then [ $downloadonly != 1 ] && \
239 if ! ./scripts/Build-Pkg $options $package; then
240 if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
241 echo "Aborting further builds, check SDECFG_CONTINUE_ON_ERROR_AFTER."
242 exit 1
245 else
246 echo "The download for package $package failed!"
247 exit 1
249 done