* fixed lightdm to build when gobject-introspection is not installed
[t2sde.git] / scripts / Emerge-Pkg
blob4f204f604bb3b2ac1b48b7fa07936f3bc6bc36d5
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Emerge-Pkg
5 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # Copyright (C) 2004 - 2006 Rene Rebe <rene@exactcode.de>
7 #
8 # This Copyright note is generated by scripts/Create-CopyPatch,
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 version 2.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 exec 2>&1
17 options=
18 dloptions=
19 config='default'
20 deps='indirect2'
21 debug=0
22 downloadonly=0
23 verbose=1
24 ignore_chksum=1
25 backup=1
26 dryrun=0
27 force=0
28 rebuild=1
29 repositories=
30 system=
31 depth=0
32 missing='only'
33 optional='ask'
35 deptree=
36 esttime=0
39 # ---- Functions
42 . scripts/functions.in
44 help_msg() {
45 spacer=" "
46 echo
47 echo "Usage: Emerge-Pkg [ -cfg <config> ] [ -dry-run ] [ -force ] [ -nobackup ]"
48 echo "$spacer [ -consider-chksum ] [ -norebuild ] [ -deps=none|fast|indirect ]"
49 echo "$spacer [ -missing=yes|no|only ] [ -optional-deps=yes|no|ask ] [ -download ]"
50 echo "$spacer [ -repository repository-name ] [ -system ] [ pkg-name(s) ]"
51 echo
52 echo "pkg-name(s) are only optional if a repository is specified."
53 echo
57 # ---- Parse options + config
60 if [ $# = 0 ]; then
61 help_msg
62 exit 1
65 while [ "$1" ]; do
66 case "$1" in
67 -cfg) options="$options $1 $2" config="$2"; shift ;;
68 -deps=*) deps=${1/-deps=/} ;;
69 -missing=*) missing=${1/-missing=/} ;;
70 -optional-deps=*) optional=${1/-optional-deps=/} ;;
71 -dry-run) dryrun=1 ;;
72 -f|-force) force=1 ;;
73 -debug) debug=1 ;;
74 -nobackup) backup=0 ;;
75 -consider-chksum) ignore_chksum=0 ;;
76 -norebuild) rebuild=0 ;;
77 -download|-download-only) downloadonly=1 ;;
78 -repository) repositories="$repositories $2"; shift ;;
79 -prefix) options="$options -prefix $2"; shift ;;
80 -v) options="$options -v" ;;
81 -noclearsrc) options="$options -noclearsrc" ;;
82 -xtrace) options="$options -xtrace" ;;
83 -system) system=1 deps=none ;;
84 -*) help_msg; exit 1 ;;
85 *) break ;;
86 esac
87 shift
88 done
90 case "$deps" in
91 fast|indirect*|none) : ;;
93 echo "Unknown dependency resolution mode. Valid are none, fast and indirect."
94 exit 1
95 esac
97 if [ ! -f config/$config/config -a $config = "default" ]; then
98 scripts/Config -oldconfig
101 . scripts/parse-config
103 noautolist=" 00-dirtree $SDECFG_DEFAULT_CC $SDECFG_LIBC ${SDECFG_LIBC}32 "
104 declare -A packages
105 declare -A scanned
106 declare -A deplist
108 read_packages() {
109 local sel pkg _
110 while read sel _ _ _ pkg _; do
111 packages[$pkg]=$sel
112 done < <(cat config/$config/packages)
115 add_if_req() {
116 local pkg=$1 msg="$2" typ=$3
117 local buildtime=$(pkgbuildtime $pkg)
119 [ "$verbose" = 1 ] && echo -n "$msg"
121 # some more check for packages not manually specified
122 if [ $depth != 0 ]; then
123 # no auto update list
124 if [ "$noautolist" != "${noautolist/ $pkg /}" ]; then
125 [ $verbose = 1 ] && echo " Vital, skipped by default."
126 return
130 if [ $depth -gt 0 ]; then
131 # optional dep, not yet installed?
132 if [ "$typ" = '[OPT]' ]; then
133 if [ "$optional" = ask ]; then
134 echo -n " Add optional dep? (y/N$(fmt_time $buildtime)) "
135 read in
136 # force further updates? TODO: limit input validation
137 [[ "$in" = *\* ]] && optional=$in
138 else
139 in="$optional"
140 [[ "$in" = y* ]] &&
141 echo " Optional added. $(fmt_time $buildtime)" ||
142 echo " Optional, skipped."
145 if [[ "$in" = y* ]]; then
146 deplist[$pkg]=1
147 esttime=$((esttime + buildtime))
148 [ "$deps" = indirect ] && dep4pkg "$pkg"
149 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
151 return
154 # missing ones? yes, no, only TODO: maybe delete
155 if [ ! -f /var/adm/packages/$pkg ]; then
156 if [ "$missing" = 'no' ]; then
157 [ $verbose = 1 ] && echo " Not missing, skipped."
158 return
160 elif [ "$missing" = 'only' ]; then
161 [ $verbose = 1 ] && echo " Only missing selected, skipped."
162 return
166 [ $verbose = 1 ] && echo " Added.$(fmt_time $buildtime)"
167 deplist[$pkg]=1
168 esttime=$((esttime + buildtime))
169 [ "$deps" = indirect ] && dep4pkg "$pkg"
170 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
173 add_if_updated() {
174 local pkg=$1
175 local typ=$2
177 if [ "${scanned[$pkg]}" = 1 ]; then
178 [ $debug = 1 ] && echo "already been at $pkg ..."
179 return
180 else
181 scanned[$pkg]=1
184 # read in pkg list?
185 [ ${#packages[@]} = 0 ] && read_packages
187 [ $verbose = 1 ] && echo -n "$deptree$pkg:"
188 confdir=
189 for x in package/*/$pkg/$pkg.desc; do
190 if [ -f "$x" ]; then
191 if [ "$confdir" ]; then
192 echo " Warning: Package in multiple trees! Skipped."
193 return
195 confdir=${x/$pkg.desc/}
197 done
198 if [ -z "$confdir" ]; then
199 if [ $depth = 0 ]; then
200 echo " Error: No such package."
201 exit 1
202 else
203 echo " Warning: No such package."
204 return
208 # TODO: keep unselected in the config, to avoid re-config for masked pkgs
209 if [ -z "${packages[$pkg]}" ]; then
210 if [ $depth = 0 ]; then
211 local desc=$(echo package/*/$pkg/$pkg.desc)
212 if [ -e "$desc" ]; then
213 echo " Package not cached, re-reading config:"
214 scripts/Config -oldconfig -cfg $config
215 read_packages
218 if [ -z "${packages[$pkg]}" ]; then
219 echo " Error: No such package."
220 exit 1
222 else
223 echo " Warning: No such package."
224 return
228 if [ "${packages[$pkg]}" != X ]; then
229 echo " Not selected."
230 return
233 if [ ! -f /var/adm/packages/$pkg ]; then
234 if [ "$typ" = "[OPT]" ]; then
235 add_if_req $pkg ' Not installed.' $typ
236 else
237 add_if_req $pkg ' Not installed.'
239 return
242 o_ver=$(grep -a '^Package Name and Version' \
243 /var/adm/packages/$pkg | cut -f6 -d' ')
244 # we avoid parse_desc here, because it is ~50x slower
245 n_ver=$(grep -a '^\[V\] ' $confdir/$pkg.desc \
246 architecture/$SDECFG_ARCH/package/$pkg/$pkg.desc \
247 target/$SDECFG_TARGET/package/$pkg/$pkg.desc \
248 2> /dev/null | cut -f2 -d' ' | tail -n 1)
249 if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
250 add_if_req $pkg " New version ($o_ver -> $n_ver)."
251 return
254 o_ck=$(grep -a '^\(ROCK Linux\|T2\) Package Source Checksum' \
255 /var/adm/packages/$pkg | sed 's,.*: ,,')
256 n_ck=$(pkgchksum package/*/$pkg)
257 if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
258 add_if_req $pkg " New source checksum."
259 return
262 if [ -f /var/adm/cache/$pkg ] &&
263 grep -a -q '\[BUILDTIME\] .* ERROR' \
264 /var/adm/cache/$pkg; then
265 [ $verbose = 1 ] && echo -n " Former build was broken."
266 if [ $rebuild = 1 ]; then
267 add_if_req $pkg ''
268 else
269 [ $verbose = 1 ] && echo " Skipped."
271 return
274 if [ $force = 1 -a $depth = 0 ]; then
275 add_if_req $pkg ' Build forced.'
276 return
279 if [ $debug = 1 ]; then
280 echo " Installed and up-to-date."
281 else
282 echo -ne \
283 "\r \r"
287 dep4pkg() {
288 ((depth++))
289 local _deptree="$deptree"
290 deptree="$deptree$1|"
292 local IFS=$'\n'
293 for dep in `grep -a '\[\(DEP\|OPT\)\]' package/*/$1/$1.cache 2>/dev/null`; do
294 add_if_updated ${dep#* } ${dep% *}
295 done
297 deptree="$_deptree"
298 ((depth--))
301 # the remaining arguments are packages to be built
302 for pkg in $*; do
303 # override previously unselected dependency scan
304 [ "${deplist[$pkg]}" ] || scanned[$pkg]=
305 add_if_updated $pkg
306 done
308 # packages from repositories
309 for x in $repositories; do
310 for pkg in `egrep -a "^X .* $x .*" config/$config/packages |
311 cut -d ' ' -f 5`; do
312 add_if_updated $pkg
313 done
314 done
316 # all installed packages if a system update
317 if [ "$system" ]; then
318 depth=-1
319 for pkg in `cd /var/adm/packages/; ls *`; do
320 add_if_updated $pkg
321 done
322 depth=0
325 # The deplist is unsorted: sort by priority and convert to string.
327 deplist=`echo -n "${!deplist[@]}" | tr '\n' ' ' | tr -s ' '`
328 deplist=$(grep -a "^. .* .* .* \\(${deplist// /\\|}\\) " \
329 config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' ')
331 if [ "$deplist" ]; then
332 echo "$(echo "$deplist" |
333 wc -w) packages scheduled to build$(fmt_time $esttime): $deplist" | fold -s
334 echo
335 else
336 echo "No package scheduled to build."
339 [ $dryrun = 1 ] && exit
340 [ $backup = 1 ] && options="$options -update"
342 for pkg in $deplist; do
343 if scripts/Download -cfg $config $dloptions $pkg; then
344 if [ $downloadonly != 1 ] &&
345 ! scripts/Build-Pkg $options $pkg; then
346 if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
347 echo "Aborting further builds due to config setting CONTINUE_ON_ERROR_AFTER."
348 exit 1
351 else
352 echo "The download for package $pkg failed!"
353 #exit 1
356 [ "${dloptions/-quiet-mirror/}" = "$dloptions" ] &&
357 var_append dloptions " " "-quiet-mirror"
358 done