forked from bersler/nagios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaphostagent_extract.sh
182 lines (166 loc) · 5.64 KB
/
saphostagent_extract.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
#!/bin/bash
export PS4='+(\D{%D %T} ${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -euxo pipefail
# See https://launchpad.support.sap.com/#/notes/1473974 for more details (You need S-account to see)
# ARG_OPTIONAL_SINGLE([dir],[d],[Directory with extracted hostagent executables.],['/usr/sap/hostctrl/exe/'])
# ARG_OPTIONAL_SINGLE([share],[s],[SAP shared directory.],['/export/SAP/software/saphostagent/'])
# ARG_HELP([Configure autoupdate parameters for hostagent.],[Configure autoupdate parameters for hostagent.],[?],[])
# ARG_OPTIONAL_SINGLE([download],[o],[Download directory with hostagent archive files.],['/export/SAP/software/download/'])
# ARG_VERSION_AUTO([1.0])
### 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='ds?ov'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_dir='/usr/sap/hostctrl/exe/'
_arg_share='/export/SAP/software/saphostagent/'
_arg_download='/export/SAP/software/download/'
print_help() {
printf '%s\n' "Extract hostagent archives."
printf 'Usage: %s [-d|--dir <arg>] [-s|--share <arg>] [-?|--help] [-o|--download <arg>] [-v|--version]\n' "$0"
printf '\t%s\n' "-d, --dir: Directory with extracted 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' "-?, --help: Prints help"
printf '\t%s\n' "-o, --download: Download directory with hostagent archive files. (default: ''/export/SAP/software/download/'')"
printf '\t%s\n' "-v, --version: Prints version"
printf '\n%s\n' "Extract hostagent archives."
}
parse_commandline() {
while test $# -gt 0; do
_key="$1"
case "$_key" in
-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}"
;;
-\? | --help)
print_help
exit 0
;;
-\?*)
print_help
exit 0
;;
-o | --download)
test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
_arg_download="$2"
shift
;;
--download=*)
_arg_download="${_key##--download=}"
;;
-o*)
_arg_download="${_key##-o}"
;;
-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) ### ])
m_sapcar="${_arg_dir}SAPCAR"
declare -A m_ver
declare -A m_sar
declare -A m_sarmap
# Maps material number to directory
m_sarmap["80004822"]="Linux/x86_64/"
m_sarmap["80004831"]="Linux/ppc64le/"
m_sarmap["80004756"]="AIX/powerpc/"
m_sarmap["80004757"]="HP-UX/ia64/"
m_sarmap["80004758"]="HP-UX/pa-risc/"
m_sarmap["80004821"]="Linux/ia64/"
m_sarmap["80004759"]="Linux/ppc64be/"
m_sarmap["80004830"]="zseries/64/"
m_sarmap["80004829"]="OS400/64/"
m_sarmap["80004827"]="Solaris/sparc64/"
m_sarmap["80004826"]="Solaris/x86_64/"
m_sarmap["80004825"]="Windows/x86_64/"
m_sarmap["80004828"]="zOS/64/"
removeold() {
echo "" >"${_arg_share}${m_sarmap[${1}]}.upgrading"
find "${_arg_share}${m_sarmap[${1}]}" \
! -name .upgrading \
-type f \
-regex ".*/${m_sarmap[${1}]}.*" \
-exec rm -f '{}' \;
rm -f "${_arg_share}${m_sarmap[${1}]}.upgrading"
}
extractnew() {
m_lines=$(find "${_arg_share}${m_sarmap[${1}]}" -type f | awk 'END {print NR}')
if [[ ${m_lines} == "0" ]]; then
echo "" >"${_arg_share}${m_sarmap[${1}]}.upgrading"
"${m_sapcar}" -xjf "${m_sar[${1}]}" -R "${_arg_share}${m_sarmap[${1}]}" -manifest SIGNATURE.SMF
#echo "1440random60" >"${_arg_share}${m_sarmap[${1}]}.delay"
echo "" >"${_arg_share}${m_sarmap[${1}]}.verify"
rm -f "${_arg_share}${m_sarmap[${1}]}.upgrading"
fi
}
# Find the newest available saphostagent version
while IFS= read -r m_file; do
m_key="${m_file##*-}"
m_key="${m_key%.SAR}"
m_val="${m_file##*_}"
m_val="${m_val%-*}"
if [[ -n ${m_ver[${m_key}]:-} ]]; then
if [[ ${m_ver[${m_key}]} -lt ${m_val} ]]; then
m_ver["${m_key}"]="${m_val}"
m_sar["${m_key}"]="${m_file}"
fi
else
m_ver["${m_key}"]="${m_val}"
m_sar["${m_key}"]="${m_file}"
fi
done < <(find "${_arg_download}" -type f -regex ".*SAPHOSTAGENT[0-9][0-9]_[0-9][0-9]-[0-9]*\.SAR" 2>/dev/null)
for i in "${!m_ver[@]}"; do
if [[ -f "${_arg_share}${m_sarmap[$i]}hostagent.mf" ]]; then
m_old=$(awk '/hostagent patch number:/ {c=$NF; gsub(/[^[:alnum:]]/,"",c); print c}' "${_arg_share}${m_sarmap[$i]}hostagent.mf")
if [[ ${m_ver[$i]} -gt ${m_old} ]]; then
removeold "${i}"
extractnew "${i}"
fi
else
removeold "${i}"
extractnew "${i}"
fi
done