|
Line
Link Here
|
|
-- scripts/functions.netconfig |
|
|
|
Lines 51-57
function get_variable()
Link Here
|
| 51 |
local line |
51 |
local line |
| 52 |
while read line; do |
52 |
while read line; do |
| 53 |
eval $line |
53 |
eval $line |
| 54 |
done < <(grep "^[[:space:]]*$1" $2 2>/dev/null) |
54 |
done < <(grep "^[[:space:]]*$1=" $2 2>/dev/null) |
| 55 |
} |
55 |
} |
| 56 |
|
56 |
|
| 57 |
function read_symlink() |
57 |
function read_symlink() |
|
Lines 191-196
netconfig_check_md5_and_move()
Link Here
|
| 191 |
return $RET |
191 |
return $RET |
| 192 |
} |
192 |
} |
| 193 |
|
193 |
|
|
|
194 |
netconfig_kv_filter() |
| 195 |
{ |
| 196 |
awk -- '/^[[:space:]]*$/ { next; } |
| 197 |
/^[[:space:]]*[a-z_][a-z0-9_]*='"'"'[^'"'"']*'"'"'[[:space:]]*$/ && \ |
| 198 |
!/^[[:space:]]*_+=/ { |
| 199 |
sub("^[[:space:]]+", "", $0); |
| 200 |
sub("[[:space:]]+$", "", $0); |
| 201 |
equ=index($0, "="); |
| 202 |
key=substr($0, 1, equ - 1); |
| 203 |
val=substr($0, equ + 2, length($0) - equ - 2) |
| 204 |
print key"="val; |
| 205 |
next; |
| 206 |
} |
| 207 |
{ print "="NR; exit(NR); }' $@ |
| 208 |
} |
| 209 |
|
| 194 |
# |
210 |
# |
| 195 |
# try to open a lock (4 times) and wait if it failes |
211 |
# try to open a lock (4 times) and wait if it failes |
| 196 |
# for the specified time |
212 |
# for the specified time |
| 197 |
-- scripts/netconfig |
|
|
|
Lines 53-74
function modify() {
Link Here
|
| 53 |
exit 1 |
53 |
exit 1 |
| 54 |
fi |
54 |
fi |
| 55 |
|
55 |
|
| 56 |
CURRENTSTATE="SERVICE='$SERVICE'" |
56 |
if test "x${LEASEFILE}" != x -a ! -r "${LEASEFILE}" ; then |
| 57 |
CREATETIME=`date +%s` |
57 |
echo "Unable to read specified input file '${LEASEFILE}'" >&2 |
|
|
58 |
exit 1 |
| 59 |
fi |
| 58 |
|
60 |
|
| 59 |
local _INTERFACE="" |
61 |
local a b |
|
|
62 |
IFS=. read a b < /proc/uptime |
| 63 |
local CREATETIME=$a |
| 64 |
local _INTERFACE='' _SERVICE='' |
| 65 |
local -a KEYS VALS |
| 60 |
|
66 |
|
| 61 |
if [ "$INPUTFORMAT" == "dhcpcd" ]; then |
67 |
if [ "$INPUTFORMAT" == "dhcpcd" ]; then |
| 62 |
while IFS== read val1 val2 ; do |
68 |
local key val err=0 |
| 63 |
|
69 |
# add CREATETIME at index 0 !! |
| 64 |
CURRENTSTATE="$CURRENTSTATE\n$val1=$val2" |
70 |
KEYS=('CREATETIME' 'SERVICE') |
| 65 |
if [ "x$val1" = "xINTERFACE" ]; then |
71 |
VALS=("$CREATETIME" "$SERVICE") |
| 66 |
_INTERFACE="$val2" |
72 |
while IFS== read -sr key val ; do |
| 67 |
fi |
73 |
test -n "$key" || { |
| 68 |
done < <(cat ${LEASEFILE}) |
74 |
test -n "$val" || continue |
|
|
75 |
err=$val ; break |
| 76 |
} |
| 77 |
case $key in |
| 78 |
(CREATETIME) continue ;; |
| 79 |
(SERVICE|INTERFACE) |
| 80 |
eval "_$key='$val'" |
| 81 |
if test "x${!key}" != x -a "x${!key}" != "x$val" ; then |
| 82 |
echo "Input value $key conflicts with command line argument" >&1 |
| 83 |
exit 1 |
| 84 |
fi |
| 85 |
;; |
| 86 |
esac |
| 87 |
for k in ${KEYS[@]} ; do |
| 88 |
test "x$k" = "x$key" && continue 2 |
| 89 |
done |
| 90 |
KEYS[${#KEYS[@]}]=$key |
| 91 |
VALS[${#VALS[@]}]=$val |
| 92 |
done < <(netconfig_kv_filter ${LEASEFILE:+"$LEASEFILE"}) |
| 93 |
if test $err -ne 0 ; then |
| 94 |
echo "Invalid syntax in ${LEASEFILE:+${LEASEFILE}, }line $err" >&2 |
| 95 |
exit 1 |
| 96 |
fi |
| 69 |
else |
97 |
else |
| 70 |
echo "Unsupported lease file / input format '$INPUTFORMAT'" >&2 |
98 |
echo "Unsupported lease file / input format '$INPUTFORMAT'" >&2 |
| 71 |
exit 1 |
99 |
exit 1 |
| 72 |
fi |
100 |
fi |
| 73 |
|
101 |
|
| 74 |
# NetworkManager policy merged |
102 |
# NetworkManager policy merged |
|
Lines 80-94
function modify() {
Link Here
|
| 80 |
CFGFILE="$STATEDIR/NetworkManager.netconfig" |
108 |
CFGFILE="$STATEDIR/NetworkManager.netconfig" |
| 81 |
|
109 |
|
| 82 |
# first get the createtime. we want to keep it. |
110 |
# first get the createtime. we want to keep it. |
| 83 |
get_variable "CREATETIME" $CFGFILE |
111 |
get_variable "CREATETIME" "$CFGFILE" |
|
|
112 |
KEYS[0]='CREATETIME' |
| 113 |
VALS[0]="$CREATETIME" |
| 84 |
|
114 |
|
| 85 |
# remove it also in modify. |
115 |
# remove it also in modify. |
| 86 |
# We want to create it with the same name again. |
116 |
# We want to create it with the same name again. |
| 87 |
rm -f $CFGFILE |
117 |
rm -f "$CFGFILE" |
| 88 |
|
|
|
| 89 |
CURRENTSTATE="CREATETIME='$CREATETIME'\n$CURRENTSTATE" |
| 90 |
else |
118 |
else |
| 91 |
# use interface name from config |
119 |
# use interface name from config if provided |
| 92 |
if [ "x$INTERFACE" = "x" -a "x$_INTERFACE" != "x" ]; then |
120 |
if [ "x$INTERFACE" = "x" -a "x$_INTERFACE" != "x" ]; then |
| 93 |
INTERFACE="$_INTERFACE" |
121 |
INTERFACE="$_INTERFACE" |
| 94 |
fi |
122 |
fi |
|
Lines 110-124
function modify() {
Link Here
|
| 110 |
local CFGFILE=`find_cfgfile "$INTERFACE" "$SERVICE"` |
138 |
local CFGFILE=`find_cfgfile "$INTERFACE" "$SERVICE"` |
| 111 |
if [ "x$CFGFILE" != "x" ]; then |
139 |
if [ "x$CFGFILE" != "x" ]; then |
| 112 |
# first get the createtime. we want to keep it. |
140 |
# first get the createtime. we want to keep it. |
| 113 |
get_variable "CREATETIME" $CFGFILE |
141 |
get_variable CREATETIME "$CFGFILE" |
| 114 |
|
142 |
|
| 115 |
# remove it also in modify. |
143 |
# remove it also in modify. |
| 116 |
# We want to create it with the same name again. |
144 |
# We want to create it with the same name again. |
| 117 |
rm -f $CFGFILE |
145 |
rm -f "$CFGFILE" |
| 118 |
fi |
146 |
fi |
| 119 |
|
147 |
|
| 120 |
CURRENTSTATE="$CURRENTSTATE\nCREATETIME='$CREATETIME'" |
|
|
| 121 |
|
| 122 |
if [ "x$CFGFILE" = "x" ]; then |
148 |
if [ "x$CFGFILE" = "x" ]; then |
| 123 |
local CFGNAME=`get_new_cfgname` |
149 |
local CFGNAME=`get_new_cfgname` |
| 124 |
CFGFILE="$STATEDIR/$INTERFACE/$CFGNAME" |
150 |
CFGFILE="$STATEDIR/$INTERFACE/$CFGNAME" |
|
Lines 126-132
function modify() {
Link Here
|
| 126 |
fi |
152 |
fi |
| 127 |
|
153 |
|
| 128 |
debug "write new STATE file $CFGFILE" |
154 |
debug "write new STATE file $CFGFILE" |
| 129 |
echo -e "$CURRENTSTATE" > "$CFGFILE" |
155 |
for((i=0; i<${#KEYS[@]} && i<${#VALS[@]}; i++)) ; do |
|
|
156 |
printf "%s='%s'\n" "${KEYS[$i]}" "${VALS[$i]}" |
| 157 |
done > "$CFGFILE" |
| 158 |
|
| 130 |
return 0 |
159 |
return 0 |
| 131 |
} |
160 |
} |
| 132 |
|
161 |
|
|
Lines 203-209
function get_new_cfgname() {
Link Here
|
| 203 |
} |
232 |
} |
| 204 |
|
233 |
|
| 205 |
function run_plugins() { |
234 |
function run_plugins() { |
| 206 |
local errors="" |
235 |
local errors=() |
| 207 |
local msg="" |
236 |
local msg="" |
| 208 |
local ret=0 |
237 |
local ret=0 |
| 209 |
|
238 |
|
|
Lines 222-238
function run_plugins() {
Link Here
|
| 222 |
if [ ! -x $PLUGINDIR/$plg ]; then |
251 |
if [ ! -x $PLUGINDIR/$plg ]; then |
| 223 |
continue |
252 |
continue |
| 224 |
fi |
253 |
fi |
| 225 |
msg=`$PLUGINDIR/$plg` |
254 |
msg=`$PLUGINDIR/$plg 2>&1` |
| 226 |
if [ -n "$msg" ]; then |
255 |
if [ "x$msg" != x ]; then |
| 227 |
errors="$errors\n$msg" |
256 |
errors[${#errors[@]}]="$msg" |
| 228 |
fi |
257 |
fi |
| 229 |
if [ "$?" != "0" ]; then |
258 |
if [ "$?" != "0" ]; then |
| 230 |
ret=$? |
259 |
ret=$? |
| 231 |
fi |
260 |
fi |
| 232 |
done |
261 |
done |
| 233 |
|
262 |
|
| 234 |
if [ -n "$errors" ]; then |
263 |
if [ ${#errors[@]} -gt 0 ]; then |
| 235 |
echo -e "$errors" |
264 |
for msg in ${errors[@]} ; do |
|
|
265 |
echo "$msg" |
| 266 |
done |
| 236 |
fi |
267 |
fi |
| 237 |
return $ret |
268 |
return $ret |
| 238 |
} |
269 |
} |
|
Lines 270-276
function usage ()
Link Here
|
| 270 |
|
301 |
|
| 271 |
EOT |
302 |
EOT |
| 272 |
if [ -n "$1" ] ; then |
303 |
if [ -n "$1" ] ; then |
| 273 |
echo >&2 |
304 |
echo "" >&2 |
| 274 |
ERROR=" ERROR: " |
305 |
ERROR=" ERROR: " |
| 275 |
echo -e "$*\n" | while read line; do |
306 |
echo -e "$*\n" | while read line; do |
| 276 |
echo "${ERROR}${line}" >&2 |
307 |
echo "${ERROR}${line}" >&2 |
|
Lines 280-297
EOT
Link Here
|
| 280 |
exit 1 |
311 |
exit 1 |
| 281 |
} |
312 |
} |
| 282 |
|
313 |
|
| 283 |
|
|
|
| 284 |
COMMANDLINE="$@" |
314 |
COMMANDLINE="$@" |
| 285 |
ACTION="" |
315 |
ACTION="" |
|
|
316 |
SERVICE="" |
| 317 |
INTERFACE="" |
| 286 |
VARIABLE="" |
318 |
VARIABLE="" |
| 287 |
while true ; do |
319 |
while true ; do |
|
|
320 |
# Interface is checked against sysfs before the data is used; |
| 321 |
# reject just the most the ugliest characters... |
| 322 |
REGEX='' |
| 288 |
case "$1" in |
323 |
case "$1" in |
| 289 |
-s|--service) VARIABLE=SERVICE;; |
324 |
-s|--service) VARIABLE=SERVICE ; |
| 290 |
-f|--force-replace) FORCE_REPLACE="true";; |
325 |
REGEX='^[a-zA-Z0-9_-]+$' ;; |
| 291 |
-v|--verbose) VERBOSE="yes";; |
326 |
-i|--interface) VARIABLE=INTERFACE ; |
| 292 |
-i|--interface) VARIABLE=INTERFACE;; |
327 |
REGEX='^[^'"'"'`"\\/[:space:][:cntrl:]]+$' ;; |
| 293 |
-l|--lease-file) VARIABLE=LEASEFILE;; |
328 |
-l|--lease-file) VARIABLE=LEASEFILE;; |
| 294 |
-F|--input-format) VARIABLE=INPUTFORMAT;; |
329 |
-F|--input-format) VARIABLE=INPUTFORMAT;; |
|
|
330 |
-f|--force-replace) FORCE_REPLACE="true";; |
| 331 |
-v|--verbose) VERBOSE="yes";; |
| 295 |
-h|--help) usage;; |
332 |
-h|--help) usage;; |
| 296 |
"") break ;; |
333 |
"") break ;; |
| 297 |
--) |
334 |
--) |
|
Lines 311-317
while true ; do
Link Here
|
| 311 |
-*) usage Unknown option $1;; |
348 |
-*) usage Unknown option $1;; |
| 312 |
esac |
349 |
esac |
| 313 |
if [ -n "$VARIABLE" ] ; then |
350 |
if [ -n "$VARIABLE" ] ; then |
| 314 |
test -z "$2" && usage Option $1 needs an argument |
351 |
case $2 in |
|
|
352 |
(""|-*) usage "Option $1 needs an argument" ;; |
| 353 |
esac |
| 354 |
if [ -n "$REGEX" ] ; then |
| 355 |
if ! [[ ${1} =~ ${REGEX} ]] ; then |
| 356 |
usage "Invalid character in value for option $VARIABLE" |
| 357 |
fi |
| 358 |
fi |
| 315 |
eval $VARIABLE=\$2 |
359 |
eval $VARIABLE=\$2 |
| 316 |
shift |
360 |
shift |
| 317 |
VARIABLE="" |
361 |
VARIABLE="" |
|
Lines 385-388
unLock "$PROGNAME"
Link Here
|
| 385 |
|
429 |
|
| 386 |
exit $EXITVAL |
430 |
exit $EXITVAL |
| 387 |
|
431 |
|
| 388 |
|
432 |
# vim: set ts=8 sts=4 sw=4 ai et: |