forked from lunar-linux/lunar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.lunar
135 lines (106 loc) · 2.94 KB
/
config.lunar
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
############################################################
# #
# This code is written for Lunar Linux, see #
# http://lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/config #
# set_config, get_config, unset_config #
# set_local_config, get_local_config, unset_local_config #
# set_module_config, get_module_config, unset_module_config#
# #
############################################################
# #
# Copyrighted Auke Kok 2004 under GPLv2 #
# #
############################################################
set_config() {
local LINE NEW FILE VAR
debug_msg "set_config ($@)"
FILE=$1
VAR=$(trim "$2")
LINE=$(grep -w "$VAR=.*" "$FILE")
shift 2
if [ "$FILE" == "$LOCAL_CONFIG" ] ; then
NEW="$(printf "%16s" "$VAR")=\"$@\""
else
NEW="$VAR=\"$@\""
fi
# on-demand creation
if [ ! -f $FILE ] ; then
touch $FILE
fi
lock_file $FILE &&
if [ -n "$LINE" ] ; then
sedit "/^\s*$VAR=/d" $FILE
fi
echo "$NEW" >> $FILE
unlock_file $FILE
}
unset_config() {
debug_msg "unset_config ($@)"
# on-demand creation
if [ ! -f $1 ] ; then
touch $1
fi
lock_file $1 &&
if [ -n "$2" ] ; then
# make sure we escape those ':' characters:
sedit "/^[ ]*$2=/d" $1
fi
unlock_file $1
}
get_config() {
if [[ -f $1 ]] ; then
grep -w "$2=.*" "$1" | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//'
fi
}
set_local_config() {
debug_msg "set_local_config ($@)"
local VAR
VAR=$1
shift
set_config "$LOCAL_CONFIG" "$VAR" "$@"
}
unset_local_config() {
debug_msg "unset_local_config ($@)"
unset_config "$LOCAL_CONFIG" "$1"
}
get_local_config() {
get_config "$LOCAL_CONFIG" "$1"
}
set_module_config() {
debug_msg "set_module_config ($@)"
if [ -n "$MODULE" ] ; then
set_config "$DEPENDS_CONFIG/$MODULE" "$1" "$2"
fi
}
unset_module_config() {
debug_msg "unset_module_config ($@)"
if [ -n "$MODULE" ] ; then
unset_config "$DEPENDS_CONFIG/$MODULE" "$1"
fi
}
get_module_config() {
debug_msg "get_module_config ($@)"
if [ -n "$MODULE" ] ; then
get_config "$DEPENDS_CONFIG/$MODULE" "$1"
fi
}
get_other_module_config() {
debug_msg "get_other_module_config ($@)"
if [ -n "$1" ] ; then
get_config "$DEPENDS_CONFIG/$1" "$2"
fi
}
# function : trim
# usage : trim <string>
# purpose : remove leading and trailing whitespaces from a string
trim() {
local str="$*"
str="${str#"${str%%[![:space:]]*}"}"
str="${str%"${str##*[![:space:]]}"}"
printf "%s" "$str"
}