File: apply_options.sh

package info (click to toggle)
bashburn 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,140 kB
  • sloc: sh: 2,584; sed: 64; makefile: 19
file content (80 lines) | stat: -rwxr-xr-x 1,589 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
apply_options()
{
    # Write all the options out to replace the bashburnrc.
    typeset bbtempfile=$(mktemp bashburn_apply_opts.XXXXXX)
    typeset trimval
    typeset ii
    #Apply changes
    # Make sure BashBurn knows it is configured.
    
    for ii in "${BB_KEYWORDS[@]}"
    do
	read trimval <<< ${!ii}
	echo "${ii}: ${trimval}"
    done > ${bbtempfile}
    cp ${bbtempfile} $BBCONFFILE
    rm ${bbtempfile}
}

conf_set_aval()
{
    typeset -a desc
    typeset val="$2"
    typeset line
    typeset oldIFS="$IFS"
    typeset IFS="$oldIFS"
    typeset -r tmpfile=$(mktemp 'bbcfg.XXXXXX')
    typeset varname
    typeset -i found	# Set if the option was found in the changed descriptors.
    typeset -i didsomething=0	# Set if there were any mods at all.
    typeset -i ii
    typeset nvar
    typeset nval
    typeset -i size

    desc=( "$@" )
    size=$#
    #for (( ii=0; ii < size; ii++ ))
    #do
    #	echo ${desc[ii]}
    #done
    while read line
    do
	IFS=:
	set -- $line
	IFS="$oldIFS"
	varname=$1
	found=0
	for (( ii=0; ii < size; ii++ ))
	do
	    IFS='|'
	    set -- ${desc[ii]}
	    IFS="$oldIFS"
	    nvar=$1
	    nval="$2"
	    if [[ "$nvar" == "$varname" ]]
	    then
		eval $nvar=\"$nval\"
		found=1
		didsomething=1
		case $nvar in	# stub to catch special action.
		BBLANG)
		    source_language_modules
		    define_global_menus
		    ;;
		*)
		    ;;
		esac
		break
	    fi
	done
	if (( found ))
	then
	    echo "$nvar: ${!nvar}"
	else
	    echo "$line"
	fi
    done < $BBCONFFILE > $tmpfile
    (( didsomething )) && cp $tmpfile $BBCONFFILE
    rm $tmpfile
}