* updated gtk (4.14.4 -> 4.15.2)
[t2sde.git] / scripts / Emerge-Pkg
blob7f8ce98d9dd30bd5fc050a5c0210c328d3ebb9e4
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 if [ ! -f config/$config/config -a $config = "default" ]; then
91 scripts/Config -oldconfig
94 . scripts/parse-config
96 noautolist=' 00-dirtree $SDECFG_DEFAULT_CC $SDECFG_LIBC ${SDECFG_LIBC}32 '
97 declare -A scanned
98 declare -A deplist
100 add_if_req() {
101 local pkg=$1 msg="$2" typ=$3
102 local buildtime=$(pkgbuildtime $pkg)
104 [ "$verbose" = 1 ] && echo -n "$msg"
106 # some more check for packages not manually specified
107 if [ $depth != 0 ]; then
108 # no auto update list
109 if [ "$noautolist" != "${noautolist/ $pkg /}" ]; then
110 [ $verbose = 1 ] && echo " Vital, skipped by default."
111 return
114 # optional dep, not yet installed?
115 if [ "$typ" = '[OPT]' ]; then
116 if [ "$optional" = ask ]; then
117 echo -n " Add optional dep? (y/n$(fmt_time $buildtime)) "
118 read in
119 else
120 in="$optional"
121 [[ "$in" = y* ]] &&
122 echo " Optional added. $(fmt_time $buildtime)" ||
123 echo " Optional, skipped."
126 if [[ "$in" = y* ]]; then
127 deplist[$pkg]=1
128 esttime=$((esttime + buildtime))
129 [ "$deps" = indirect ] && dep4pkg "$pkg"
130 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
132 return
135 # missing ones? yes, no, only TODO: maybe delete
136 if [ ! -f /var/adm/packages/$pkg ]; then
137 if [ "$missing" = 'no' ]; then
138 [ $verbose = 1 ] && echo " Not missing, skipped."
139 return
141 elif [ "$missing" = 'only' ]; then
142 [ $verbose = 1 ] && echo " Only missing selected, skipped."
143 return
147 [ $verbose = 1 ] && echo " Added.$(fmt_time $buildtime)"
148 deplist[$pkg]=1
149 esttime=$((esttime + buildtime))
150 [ "$deps" = indirect ] && dep4pkg "$pkg"
151 [ "$deps" = indirect2 -a $depth -le 2 ] && dep4pkg "$pkg"
154 add_if_updated() {
155 local pkg=$1
156 local typ=$2
158 if [ "${scanned[$pkg]}" = 1 ]; then
159 [ $debug = 1 ] && echo "already been at $pkg ..."
160 return
161 else
162 scanned[$pkg]=1
165 [ $verbose = 1 ] && echo -n "$deptree> $pkg ..."
166 confdir=
167 for x in package/*/$pkg/$pkg.desc; do
168 if [ -f "$x" ]; then
169 if [ "$confdir" ]; then
170 echo " Warning: Package in multiple trees! Skipped."
171 return
173 confdir=${x/$pkg.desc/}
175 done
176 if [ -z "$confdir" ]; then
177 if [ $depth = 0 ]; then
178 echo " Error: No such package."
179 exit 1
180 else
181 echo " Warning: No such package."
182 return
186 if [ ! -f /var/adm/packages/$pkg ]; then
187 if [ "$typ" = "[OPT]" ]; then
188 add_if_req $pkg ' Not installed.' $typ
189 else
190 add_if_req $pkg ' Not installed.'
192 return
195 o_ver=$(grep -a '^Package Name and Version' \
196 /var/adm/packages/$pkg | cut -f6 -d' ')
197 # we avoid parse_desc here, because it is ~50x slower
198 n_ver=$(grep -a '^\[V\] ' $confdir/$pkg.desc \
199 architecture/$SDECFG_ARCH/package/$pkg/$pkg.desc \
200 target/$SDECFG_TARGET/package/$pkg/$pkg.desc \
201 2> /dev/null | cut -f2 -d' ' | tail -n 1)
202 if [ "$o_ver" != "$n_ver" -a "$n_ver" != "0000" ]; then
203 add_if_req $pkg " New version ($o_ver -> $n_ver)."
204 return
207 o_ck=$(grep -a '^\(ROCK Linux\|T2\) Package Source Checksum' \
208 /var/adm/packages/$pkg | sed 's,.*: ,,')
209 n_ck=$(pkgchksum package/*/$pkg)
210 if [ $ignore_chksum = 0 -a "$o_ck" != "$n_ck" ]; then
211 add_if_req $pkg " New source checksum."
212 return
215 if [ -f /var/adm/cache/$pkg ] &&
216 grep -a -q '\[BUILDTIME\] .* ERROR' \
217 /var/adm/cache/$pkg; then
218 [ $verbose = 1 ] && echo -n " Former build was broken."
219 if [ $rebuild = 1 ]; then
220 add_if_req $pkg ''
221 else
222 [ $verbose = 1 ] && echo " Skipped."
224 return
227 if [ $force = 1 -a $depth = 0 ]; then
228 add_if_req $pkg ' Build forced.'
229 return
232 if [ $debug = 1 ]; then
233 echo " Installed and up-to-date."
234 else
235 echo -ne \
236 "\r \r"
240 dep4pkg() {
241 ((depth++))
242 local _deptree="$deptree"
243 var_append deptree '>' "$1"
245 local IFS=$'\n'
246 for dep in `grep -a '\[\(DEP\|OPT\)\]' package/*/$1/$1.cache 2>/dev/null`; do
247 add_if_updated ${dep#* } ${dep% *}
248 done
250 deptree="$_deptree"
251 ((depth--))
254 # the remaining arguments are packages to be built
255 for pkg in $*; do
256 # override previously unselected dependency scan
257 [ "${deplist[$pkg]}" ] || scanned[$pkg]=
258 add_if_updated $pkg
259 done
261 # packages from repositories
262 for x in $repositories; do
263 for pkg in `egrep -a "^X .* $x .*" config/$config/packages |
264 cut -d ' ' -f 5`; do
265 add_if_updated $pkg
266 done
267 done
269 # all installed packages if a system update
270 if [ "$system" ]; then
271 for pkg in `cd /var/adm/packages/; ls *`; do
272 add_if_updated $pkg
273 done
276 case "$deps" in
277 fast|indirect*)
278 # we have to create a complete dependency graph ...
279 for pkg in ${!deplist[@]}; do
280 dep4pkg $pkg
281 done
283 none)
286 echo "Unknown dependency resolution mode. Valid are none, fast and indirect."
287 exit 1
288 esac
290 # The deplist is unsorted: sort by priority and convert to string.
292 deplist=`echo -n "${!deplist[@]}" | tr '\n' ' ' | tr -s ' '`
293 deplist=$(grep -a "^. .* .* .* \\(${deplist// /\\|}\\) " \
294 config/$config/packages | sort -k 3 | cut -d ' ' -f 5 | tr '\n' ' ')
296 if [ "$deplist" ]; then
297 echo "$(echo "$deplist" |
298 wc -w) packages scheduled to build$(fmt_time $esttime): $deplist" | fold -s
299 echo
300 else
301 echo "No package scheduled to build."
304 [ $dryrun = 1 ] && exit
305 [ $backup = 1 ] && options="$options -update"
307 for pkg in $deplist; do
308 if scripts/Download -cfg $config $dloptions $pkg; then
309 if [ $downloadonly != 1 ] &&
310 ! scripts/Build-Pkg $options $pkg; then
311 if [ $SDECFG_CONTINUE_ON_ERROR_AFTER -gt 8 ]; then
312 echo "Aborting further builds due to config setting CONTINUE_ON_ERROR_AFTER."
313 exit 1
316 else
317 echo "The download for package $pkg failed!"
318 #exit 1
321 [ "${dloptions/-quiet-mirror/}" = "$dloptions" ] &&
322 var_append dloptions " " "-quiet-mirror"
323 done