* updated pyxdg (0.19 -> 0.28)
[t2sde.git] / scripts / Config
blobd331f3f1c6665ff7910601e94c6cb75a3c9669db
1 #!/usr/bin/env bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: scripts/Config
5 # Copyright (C) 2004 - 2024 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
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 if [ -z "${lines:=$LINES}" -o -z "${columns:=$COLUMNS}" ]; then
16 if [ "$(type -p stty)" ]; then
17 lines="$( stty size 2> /dev/null | cut -d' ' -f1)"
18 columns="$(stty size 2> /dev/null | cut -d' ' -f2)"
20 [ -z "$lines" -o "$lines" -le 0 ] 2> /dev/null && lines=24
21 [ -z "$columns" -o "$columns" -le 0 ] 2> /dev/null && columns=80
24 eval "$(egrep '^sdever=' scripts/parse-config)"
26 config=default
27 do_config_cycle=0
28 delete_mode=0
29 oldconfig=
30 cfgtmpdir=
31 profile=
33 show_usage() {
34 echo
35 echo "Usage: $0 [ -delete | -oldconfig ] [ -cfg <config> ] [ key[=value ] ]"
36 echo
37 echo "Other options:"
38 echo " -profile create a config.profile with profiling data"
39 echo
42 while [ "$1" ]; do
43 case "$1" in
44 -cycle) do_config_cycle=1; shift ;;
45 -delete) delete_mode=1 ; shift ;;
46 -profile) profile=$1 ; shift ;;
47 -oldconfig) oldconfig=$1 ; shift ;;
48 -cfg) config="$2" ; shift; shift ;;
49 -*) show_usage ; exit 1 ;;
50 *) break ;;
51 esac
52 done
54 if [ -z "$config" ]; then
55 show_usage
56 exit 1
59 # get/set config key=value
60 for x; do
61 key=${x%%=*}
62 val=${x#$key}
63 key=${key//-/_}
64 key=${key^^}
66 if [ "$val" ]; then
67 val=${val#=}
68 sed -i "/SDECFG_$key=/{s/=.*/='$val'/}" config/$config/config
71 sed -n "/SDECFG_$key=/x; \${x; s/^[^=]*=//; s/^'\(.*\)'$/\1/; s/.\+/$key=&/p}" config/$config/config
72 done
73 [ $# -gt 0 ] && exit 0
75 if [ ! -d config/$config -a -e /etc/SDE-CONFIG/config -a $config = default ]; then
76 echo "Using /etc/SDE-CONFIG/ as default config"
77 mkdir -p config/$config
78 cp -vf /etc/SDE-CONFIG/* config/$config/
79 sed -i -E '/SDECFG_(CROSSBUILD|OPT|LTO|PARALLE|PKGSEL_TMPL|TMPFS|C_FLAGS)/d' \
80 config/$config/config
83 if [ ! -d config/$config -a -n "$oldconfig" ]; then
84 echo "Error: -oldconfig is not supported for a new config"
85 echo
86 exit 1
89 if [ $delete_mode = 1 ]; then
90 rm -rv config/$config
91 exit $?
94 cfgtmpdir=src/$config
96 if [ $do_config_cycle = 0 ]; then
97 echo "T2 $sdever configuration"
99 set -e
100 mkdir -p config/$config
101 touch config/$config/{config,packages}
102 set +e
104 echo "Aquiring config lock ..."
105 # aquire lock
106 exec 200>> config/$config/lock.pid
107 flock 200
108 echo $$ > config/$config/lock.pid
110 rm -rf $cfgtmpdir
111 mkdir -p $cfgtmpdir # src
113 if [ -z "$oldconfig" -a ! -f src/confdialog.bin ]; then
114 echo "Creating confdialog tool"
115 command="cc -O2 misc/confdialog/*.c `
116 `-Imisc/confdialog -lncurses -o src/confdialog.bin"
117 echo "$command"
118 if ! eval "$command.$$"; then
119 echo "Compilation of the dialog tool failed, ncurses-devel missing?"
120 exit 1
122 mv src/confdialog.bin.$$ src/confdialog.bin
125 # don't let Ctrl-C interrupt, because it destroys the configurations
126 trap '' INT
128 while "$0" -cfg $config $oldconfig $profile -cycle; do :; done
130 trap INT
132 rm config/$config/lock.pid
133 exit 0
136 if [ ! -f src/bash/luabash.??* ]; then
137 echo "Building src/bash/luabash"
138 j="$(nproc 2>/dev/null)"
139 make -j${j:-1} --no-print-directory -C misc/luabash \
140 X_OUTARCH=$PWD/src ${HOSTCC:+CC=$HOSTCC} ${HOSTCC:+LD=ld}
141 unset j
144 if [ ! -f src/bash/luabash.??* ]; then
145 echo "Error building the Lua bash accelerator"
146 exit 1
149 if ! enable -f $PWD/src/bash/luabash.??* luabash; then
150 echo "Error enabling the Lua bash accelerator: bash built with plugin support?"
151 exit 1
154 luabash load scripts/config-functions.lua || exit 1
156 if [ -z "$profile" ]; then
157 bprof() { :; }
158 bprof_print() { :; }
159 else
160 if [ ! -f src/bash_profiler.so -o misc/tools-source/bash_profiler.c -nt src/bash_profiler.so ]; then
161 echo "Building src/bash_profiler.so"
162 cc -O2 -shared -fPIC -Wall -o src/bash_profiler.so misc/tools-source/bash_profiler.c || exit 1
164 enable -f src/bash_profiler.so bprof || exit 1
165 bprof_print() {
166 local cprof=$cfgtmpdir/config.profile
167 bprof all print >> $cprof
168 awk '
169 $4 == "profiled" { next; }
170 $4 != "main" { count["profiled"]+=$1; time["profiled"]+=$2; }
171 { count[$4]+=$1; time[$4]+=$2; }
172 END {
173 for (id in count)
174 printf "%7d %7Ld %10.3f %s\n", count[id], time[id], time[id]/count[id], id;
176 ' < $cprof | sort -n -k2 > $cprof.new
177 mv $cprof.net $cprof
181 bprof main start
183 . scripts/config-functions.in
184 arch=`uname -m | uname2arch`
185 current=""
186 export SDECFG_ARCH="$arch" SDECFG_KERNEL="linux" SDECFG_EXPERT=0
187 menu_this=0 menu_current=0 menu_counter=0
188 menu_stack=x menu_back=-1 menu_backpos=-1
190 configtitle="$(printf ' %-50s %6s active packages ]' \
191 "T2 $sdever Configuration - $config" \
192 "[ $(echo `grep '^X' config/$config/packages | wc -l`)")"
194 bprof main stop
196 . config/$config/config
197 bprof main start
199 rm -f $cfgtmpdir/config.{dialog,data,help}
200 touch $cfgtmpdir/config.{dialog,data,help}
201 echo -e "#\n# T2 $sdever Config File\n#" > config/$config/config
202 spacer="" expert=0 tabspace="5" tabspace_list=""
203 commentnr=0 editfilenr=0
205 bprof mkpkglist start
206 cmd="scripts/Create-PkgList $SDECFG_ARCH $SDECFG_KERNEL"
207 if [ "$cmd" != "`cat $cfgtmpdir/config.pcache.cmd 2> /dev/null`" ]; then
208 $cmd | tee $cfgtmpdir/config.pcache.data > config/$config/packages
209 echo "$cmd" > $cfgtmpdir/config.pcache.cmd
210 else
211 cat $cfgtmpdir/config.pcache.data > config/$config/packages
213 bprof mkpkglist stop
215 # Create lists of .in files
216 create_dot_in_lists
218 export SDECFG_ID="$sdever"; pkgin; . scripts/config.in; pkgout
219 echo "export SDECFG_ID='$SDECFG_ID'" >> config/$config/config
220 rm -f $cfgtmpdir/*.tmp
222 cut -f1,2,4,5,8- -d' ' config/$config/packages | sed 's, [^ ]*$,,' | \
223 tr ' ' '\t' | expand -t2,15,35, > $cfgtmpdir/packages.txt
225 configtitle="$(printf ' %-50s %6s active packages ]' \
226 "T2 $sdever Configuration - $config" \
227 "[ $(echo `grep '^X' config/$config/packages | wc -l`)")"
229 bprof main stop
231 if [ -z "$oldconfig" ]; then
232 eval "src/confdialog.bin --title 'Build Config' \
233 --backtitle '$configtitle' \
234 --menu 'Arrow keys navigate the menu. Press <Enter> to activate menu items. Highlighted letters are hotkeys.' \
235 $(($lines - 4)) $(($columns - 5)) $(($lines - 12)) \
236 '$current' `tr '\n' ' ' < $cfgtmpdir/config.dialog`" 2> $cfgtmpdir/config.out
237 returncode=$? item="$(< $cfgtmpdir/config.out)"
238 else
239 returncode=1
242 bprof main start
244 [ "$returncode" = 1 -a "$menu_back" -ne -1 ] && returncode="menu-back"
246 case "$returncode" in
247 0|6)
248 command="`grep "^$item " $cfgtmpdir/config.data | cut -f2-`"
249 { echo -e "\n# Remember menu position:\ncurrent='$item'"
250 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
251 echo -e "\n# Execute this config command:\n$command"
252 } >> config/$config/config
254 menu-back)
255 { echo -e "\n# New menu position:\ncurrent='$menu_backpos'"
256 echo -e "\n# New sub-menu:\nmenu_current='$menu_back'"
257 } >> config/$config/config
259 1|255)
260 rm -rf $cfgtmpdir
261 echo "New config written to: config/$config/"
262 bprof main stop
263 bprof_print
264 exit 1 ;;
266 tempitem=$item
267 item=$(echo $item | cut -f1 -d' ') # dialog(1) bug?
268 { echo -e "\n# Remember menu position:\ncurrent='$item'"
269 echo -e "\n# Remember sub-menu:\nmenu_current='$menu_current'"
270 } >> config/$config/config
272 get_help $item > $cfgtmpdir/config.dialog
274 bprof main stop
275 src/confdialog.bin --title 'T2 Config - Help' \
276 --backtitle "T2 $sdever Configuration" \
277 --textbox $cfgtmpdir/config.dialog \
278 $(($lines - 4)) $(($columns - 5))
279 bprof main start
282 echo "unknown returncode: $returncode"
283 bprof main stop
284 bprof_print
285 exit 1 ;;
286 esac
288 bprof main stop
289 bprof_print
291 exit 0