summaryrefslogtreecommitdiff
path: root/backend/modules/config
blob: d0735804cdebd4b23aded8e7216410025eb53fda (plain)
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
#!/bin/bash

declare -A cfg flags

function cfg_get()
{
	while [ "$1" ];
	do
		send data value
		echo "${cfg["$1"]}"
		send cfg "$1"
		shift
	done
}

function cfg_set()
{
	var="$1"
	shift
	cfg["$var"]="$@"
	cfg_get "$var" # inform the frontend about the change
	var="$(tr '[:upper:]' '[:lower:]' <<<"$var" | tr -d '\n' | tr -c '[:alnum:]' _)"
	export cfg_${var}="$@"
}

function flag()
{
	[ "${flags["$1"]}" ] && return 0 || return 1
}

function flag_set()
{
	send flag set "$1" # inform the frontend about the change
	flags["$1"]=1
}

function flag_unset()
{
	send flag unset "$1" # inform the frontend about the change
	unset flags["$1"]
}

function hdmap_set()
{
	cfg_set hdmap "$( ( echo "$@"; ( echo "$@"; echo "$cfg_hdmap" ) | sort -u -t: -k1,1 ) | sort -u -t: -k2,2 | grep .)"
}

# Synopsis: hdmap_get <"device"|"mountpoint"|"filesystem"|"automount"> of <"device"|"mountpoint"> <device|mountpoint>
#
# This function returns the given value from the hdmap table
function hdmap_get()
{
	[ "$2" == "of" ] || return 1
	case "$1" in
	device) col=1;;
	mountpoint) col=2;;
	filesystem) col=3;;
	automount) col=4;;
	*) return 1;;
	esac
	case "$3" in
	device) of_col=1;;
	mountpoint) of_col=2;;
	*) return 1;;
	esac
	gawk "BEGIN{FS=\":\"}{if(\$$of_col==\"$4\"){print \$$col}}" <<<"$cfg_hdmap"
}