forked from bersler/nagios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaphostagent_autoupdate.sh
195 lines (179 loc) · 5.42 KB
/
saphostagent_autoupdate.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# ARG_OPTIONAL_SINGLE([host],[h],[Hostname. (Default: hostname command result.)])
# ARG_OPTIONAL_SINGLE([dir],[d],[Directory with hostagent executables.],['/usr/sap/hostctrl/exe/'])
# ARG_OPTIONAL_SINGLE([share],[s],[SAP shared directory.],['/export/SAP/software/saphostagent/'])
# ARG_OPTIONAL_SINGLE([delay],[e],[Autoupgrade delay in minutes.],[5])
# ARG_OPTIONAL_SINGLE([tmp],[t],[Temporary directory.],['/tmp/'])
# ARG_HELP([Configure autoupdate parameters for hostagent.],[Configure autoupdate parameters for hostagent.],[?],[])
# ARG_VERSION_AUTO([1.0])
export PS4='+(\D{%D %T} ${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -euxo pipefail
### START OF CODE GENERATED BY Argbash v2.9.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info
# Generated online by https://argbash.io/generate
die() {
local _ret="${2:-1}"
test "${_PRINT_HELP:-no}" = yes && print_help >&2
echo "$1" >&2
exit "${_ret}"
}
begins_with_short_option() {
local first_option all_short_options='hdset?v'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_host=$(hostname)
_arg_dir='/usr/sap/hostctrl/exe/'
_arg_share='/export/SAP/software/saphostagent/'
_arg_delay="5"
_arg_tmp='/tmp/'
print_help() {
printf '%s\n' "Configure autoupdate parameters for hostagent."
printf 'Usage: %s [-h|--host <arg>] [-d|--dir <arg>] [-s|--share <arg>] [-e|--delay <arg>] [-t|--tmp <arg>] [-?|--help] [-v|--version]\n' "$0"
printf '\t%s\n' "-h, --host: Hostname. (Default: hostname command result.)"
printf '\t%s\n' "-d, --dir: Directory with hostagent executables. (default: /usr/sap/hostctrl/exe/)"
printf '\t%s\n' "-s, --share: SAP shared directory. (default: /export/SAP/software/saphostagent/)"
printf '\t%s\n' "-e, --delay: Autoupgrade delay in minutes. (default: 5)"
printf '\t%s\n' "-t, --tmp: Temporary directory. (default: /tmp/)"
printf '\t%s\n' "-?, --help: Prints help"
printf '\t%s\n' "-v, --version: Prints version"
printf '\n%s\n' "Configure autoupdate parameters for hostagent."
}
parse_commandline() {
while test $# -gt 0; do
_key="$1"
case "$_key" in
-h | --host)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_host="$2"
shift
;;
--host=*)
_arg_host="${_key##--host=}"
;;
-h*)
_arg_host="${_key##-h}"
;;
-d | --dir)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_dir="$2"
shift
;;
--dir=*)
_arg_dir="${_key##--dir=}"
;;
-d*)
_arg_dir="${_key##-d}"
;;
-s | --share)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_share="$2"
shift
;;
--share=*)
_arg_share="${_key##--share=}"
;;
-s*)
_arg_share="${_key##-s}"
;;
-e | --delay)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_delay="$2"
shift
;;
--delay=*)
_arg_delay="${_key##--delay=}"
;;
-e*)
_arg_delay="${_key##-e}"
;;
-t | --tmp)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_tmp="$2"
shift
;;
--tmp=*)
_arg_tmp="${_key##--tmp=}"
;;
-t*)
_arg_tmp="${_key##-t}"
;;
-\? | --help)
print_help
exit 0
;;
-\?*)
print_help
exit 0
;;
-v | --version)
printf '%s %s\n\n%s\n' "" "1.0" 'Configure autoupdate parameters for hostagent.'
exit 0
;;
-v*)
printf '%s %s\n\n%s\n' "" "1.0" 'Configure autoupdate parameters for hostagent.'
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
# OTHER STUFF GENERATED BY Argbash
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# [ <-- needed because of Argbash
m_hostexec="${_arg_dir}saphostexec"
m_profile="${_arg_dir}host_profile"
m_autodir="${_arg_share}$(uname)/$(uname -p)"
m_link="${_arg_share}${_arg_host}"
m_entry_delay="hostexec/autoupgrade_delay = ${_arg_delay}"
m_entry_dirnew="DIR_NEW = ${m_link}"
m_flag_dirnew=0
m_flag_delay=0
m_uid_root="root"
m_uid_sapadm=20004
m_uid_sapsys=20000
# set unique string
m_epoch=$(date +"%s")
m_sfx=$(printf "%X\n" "${m_epoch}")
m_tmp="${_arg_tmp}host_profile.${m_sfx}"
# set-up autoupdate parameters in host_profile
while IFS= read -r M_LINE; do
case "${M_LINE}" in
DIR_NEW*)
echo "${m_entry_dirnew}"
m_flag_dirnew=1
;;
hostexec/autoupgrade_delay*)
echo "${m_entry_delay}"
m_flag_delay=1
;;
*)
echo "${M_LINE}"
;;
esac
done <"${m_profile}" >"${m_tmp}"
{
if [[ ${m_flag_dirnew} == 0 ]]; then
echo "${m_entry_dirnew}"
fi
if [[ ${m_flag_delay} == 0 ]]; then
echo "${m_entry_delay}"
fi
} >>"${m_tmp}"
ln -s -f "${m_autodir}" "${m_link}"
# The agreed upon user IDs for SAP users
# are not honored by all installs
# this causes also problems on shared
# filesystems therefore use numerical IDs
chown -h ${m_uid_sapadm}:${m_uid_sapsys} "${m_link}"
# switch to the new configuration
mv "${m_profile}" "${_arg_tmp}"
mv "${m_tmp}" "${m_profile}"
chown ${m_uid_root}:${m_uid_sapsys} "${m_profile}"
"${m_hostexec}" -restart pf="${m_profile}"