-
Notifications
You must be signed in to change notification settings - Fork 1
/
sapfile
executable file
·145 lines (135 loc) · 5.29 KB
/
sapfile
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
#!/bin/bash
# sapfile: Determine and display SAP file type
#
# Copyright 2023 Bernd Finger, Red Hat
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -o nounset
set -o pipefail
usage () {
echo "sapfile: Determine and display SAP file type. If unknown, call the file command."
echo "Usage: sapfile [OPTION...] [FILE...]"
echo "Determine type of SAP FILEs, optionally followed by type of FILEs."
echo " -h, --help display this help and exit"
echo " -l long listing: also display the file type, taken from the output of the file command"
echo ""
echo "Requires:"
echo "- lsar (contained in the unar package from the EPEL RHEL repo)"
echo "- zipinfo (contained in the unzip RHEL package)"
echo "- sapcar (SAP program to handle sapcar files; typical filename: SAPCAR_1115-70006178.EXE)"
}
_EXTENDED_OUTPUT="n"
while getopts ":lh" opt; do
case ${opt} in
l)
_EXTENDED_OUTPUT="y"
;;
h)
usage
exit 1
;;
\?)
echo "Invalid option -$OPTARG"
usage
exit 1
;;
esac
done
shift "$((OPTIND-1))"
_ARCHIVE_TYPE="other"
for _FILE in "$@"; do
_FILE_OUTPUT=$(file "${_FILE}" | sed 's,'"${_FILE}"': ,,')
if [[ ${_FILE_OUTPUT}. == "data." ]] && [[ (${_FILE##*.} == "SAR" || ${_FILE##*.} == "sar") ]]; then
_ARCHIVE_TYPE="sapcar"
_list_content="sapcar -tvf"
else
_ARCHIVE_TYPE=$(echo "${_FILE_OUTPUT}" | awk '
BEGIN{_file_type="other"}
/RAR self-extracting archive/{_file_type="rarexe"}
/RAR archive data/{_file_type="rar"}
/Zip archive data/{_file_type="zip"}
/SAPCAR archive data/{_file_type="sapcar"}
/directory/{_file_type="dir"}
END{print _file_type}')
if [[ ${_ARCHIVE_TYPE}. == "rarexe." ]]; then
_list_content="lsar"
elif [[ ${_ARCHIVE_TYPE}. == "rar." ]]; then
_list_content="lsar"
elif [[ ${_ARCHIVE_TYPE}. == "zip." ]]; then
_list_content="zipinfo -1"
elif [[ ${_ARCHIVE_TYPE}. == "sapcar." ]]; then
_list_content="sapcar -tvf"
elif [[ ${_ARCHIVE_TYPE}. == "dir." ]]; then
_list_content=""
fi
fi
printf "%-32s " "${_FILE}":
if [[ ! -e "${_FILE}" ]]; then
echo "No such file or directory."
exit 1
fi
SAP_FILE_TYPE_FROM_FILENAME=$(echo "${_FILE}" | awk '
BEGIN{_sap_file_type="look_inside"}
/SAPCAR/&&/\.EXE/{_sap_file_type="sapcar"}
!/IMDB_SERVER/&&!/IMDB_CLIENT/&&/IMDB/&&/\.SAR/{_sap_file_type="sap_db_hana_other"}
/IMDB_SERVER/&&/\.SAR/{_sap_file_type="sap_db_hana"}
/IMDB_CLIENT/&&/\.SAR/{_sap_file_type="sap_db_hana_client"}
/SWPM/&&/\.SAR/{_sap_file_type="sap_swpm"}
/SAPHOSTAGENT/&&/\.SAR/{_sap_file_type="sap_hostagent"}
/igsexe/||/igshelper/{_sap_file_type="sap_igs"}
/SAPEXE_/||/SAPEXEDB_/{_sap_file_type="sap_kernel"}
/SAPWEBDISP_/{_sap_file_type="sap_webdisp"}
/SAPJVM/{_sap_file_type="sap_jvm"}
/ASEBC/{_sap_file_type="sap_db_ase_client"}
/COMPLETE/{_sap_file_type="sap_hana_backup"}
/S4/&&/HANA/&&/LANG/{_sap_file_type="sap_s4hana_lang"}
/S4/&&/EXPORT/{_sap_file_type="sap_s4hana_export"}
/BW4/&&/EXPORT/{_sap_file_type="sap_bw4hana_export"}
/VCH/&&/\.SAR/{_sap_file_type="sap_vch_afl"}
END{print _sap_file_type}')
if [[ ${SAP_FILE_TYPE_FROM_FILENAME}. != "look_inside." ]]; then
_SAP_FILE_TYPE=${SAP_FILE_TYPE_FROM_FILENAME}
else
if [[ ${_ARCHIVE_TYPE}. == "dir." ]]; then
_SAP_FILE_TYPE=${_FILE_OUTPUT}
elif [[ ${_ARCHIVE_TYPE}. == "rarexe." ||
${_ARCHIVE_TYPE}. == "rar." ||
${_ARCHIVE_TYPE}. == "zip." ||
${_ARCHIVE_TYPE}. == "sapcar." ]]; then
_SAP_FILE_TYPE=$(eval "${_list_content}" "${_FILE}" | awk '
BEGIN{_sap_file_type="sap_unknown"}
/BD_SYBASE_ASE/{_sap_file_type="sap_db_ase"}
/ASEBC/{_sap_file_type="sap_db_ase_client"}
/MaxDB_7.9/{_sap_file_type="sap_db_maxdb"}
/19cinstall.sh/{_sap_file_type="sap_db_oracle"}
/OCL_LINUX_X86_64/{_sap_file_type="sap_db_oracle_client"}
/db2setup/{_sap_file_type="sap_db_db2"}
/db6_update_client.sh/{_sap_file_type="sap_db_db2_client"}
/db2aese_c.lic/{_sap_file_type="sap_db_db2_license"}
/DATA_UNITS\/EXPORT/{_sap_file_type="sap_ecc_export"}
/EXP[0-9]/{_sap_file_type="sap_ecc_ides_export"}
/DATA_UNITS\/EXP[0-9]/{_sap_file_type="sap_nwas_abap_export"}
/DATA_UNITS\/JAVA_EXPORT_JDMP/{_sap_file_type="sap_nwas_java_export"}
/format error in header/{_sap_file_type="format_error_in_header"}
END{print _sap_file_type}')
else
_SAP_FILE_TYPE="sap_unknown"
fi
fi
printf "%-24s " "${_SAP_FILE_TYPE}"
if [[ ${_EXTENDED_OUTPUT}. == "y." ]]; then
printf "%s\n" "${_ARCHIVE_TYPE}"
else
printf "\n"
fi
done