-
Notifications
You must be signed in to change notification settings - Fork 10
/
informix_update_wl_file.sh
executable file
·106 lines (90 loc) · 1.84 KB
/
informix_update_wl_file.sh
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
#!/bin/bash
#
# name: informix_udpate_onconfig.sh:
# description: Make modifications to onconfig file
# Called by: informix_entry.sh
# MODFILE = $1 - the modification file to use
# FILENAME = $1 - the configuration file to modify
ADD=1
UPDATE=2
DELETE=3
MOD=0
MODFILE=$1
FILENAME=$2
SEP=$3
TRUE=0
FALSE=1
PARAM_LIST=""
IFS=" "
MSGLOG ">>> MODIFY CONFIG: $MODFILE" N
MSGLOG ">>> MODIFY CONFIG: $FILENAME" N
function deleteLine()
{
LINE=$1
MSGLOG ">>> CONFIG MOD DEL = $LINE" N
SED "/^${LINE}/d" $FILENAME
}
function getLineNumber()
{
LINE=$1
ln=`grep -n -m 1 "^${LINE}" $FILENAME |cut -f1 -d:`
if [[ $ln == "" ]]
then
ln="-1"
fi
echo $ln
}
function addLine()
{
LINE=$1
LNUM=$2
MSGLOG ">>> CONFIG MOD ADD = $LINE" N
if [[ $LNUM == "-1" ]]
then
#MSGLOG ">>> CONFIG MOD ADD - Append end" N
RUNAS root "echo '$LINE' >> $FILENAME"
else
#MSGLOG ">>> CONFIG MOD ADD - Inserting LN=$LNUM" N
SED "${LNUM}i${LINE}" $FILENAME
fi
}
function paramAlreadySeen()
{
PARAM=$1
for i in $PARAM_LIST
do
if [[ $i == "$PARAM" ]]
then
MSGLOG ">>> CONFIG MOD: PARAM $PARAM ALready seen"
return $TRUE
fi
done
return $FALSE
}
######################################
while IFS= read -r line || [ -n "$line" ]
do
#toks=( $line )
IFS="$SEP"
read -ra toks <<< "$line"
PARAM=${toks[0]}
if [[ $line == "" ]]
then
continue
fi
if [[ ${line:0:1} == "#" ]]
then
continue
fi
if ( paramAlreadySeen $PARAM)
then
LN=$(getLineNumber ${PARAM})
addLine "$line" "$LN"
else
PARAM_LIST=${PARAM_LIST}" $PARAM"
LN=$(getLineNumber ${PARAM})
deleteLine $PARAM
addLine "$line" "$LN"
fi
MSGLOG ">>> CONFIG MOD: PARAM_LIST = $PARAM_LIST"
done < $MODFILE