forked from sap-linuxlab/tool.sap_shell_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsapfile
110 lines (102 loc) · 4.01 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
#!/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 errexit
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 " -i also display the output of the plain file command for this FILE"
}
if [[ $# == 0 || ${1}. == "-h." || ${1}. == "--help." ]]; then
usage
exit 1
fi
if [[ ${1}. == "-i." ]]; then
_RUN_FILE_COMMAND="y"
shift 1
else
_RUN_FILE_COMMAND="n"
fi
for _FILE in "$@"; do
if [[ ${_RUN_FILE_COMMAND}. = "y." ]]; then
_FILE_OUTPUT=$(file "${_FILE}" | sed 's,'"${_FILE}"': ,,')
else
_FILE_OUTPUT=""
fi
printf "%-32s " "${_FILE}":
if [[ ! -e "${_FILE}" ]]; then
echo "No such file or directory."
exit 1
fi
if [[ -d "${_FILE}" ]]; then
printf "%-24s%s\n" "directory" "${_FILE_OUTPUT}"
exit 1
fi
_FILE_TYPE=$(echo "${_FILE}" | awk '
BEGIN{_sap_file_type="look_inside"}
/SAPCAR/&&/\.EXE/{_sap_file_type="sapcar"}
/IMDB/&&/\.SAR/{_sap_file_type="sap_hana"}
/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"}
/DBATL/{_sap_file_type="sap_db_oracle"}
/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 [[ ${_FILE_TYPE}. != "look_inside." ]]; then
printf "%-24s%s\n" "${_FILE_TYPE}" "${_FILE_OUTPUT}"
else
_FILE_TYPE=$(file "${_FILE}" | awk '
BEGIN{_file_type="generic"}
/RAR self-extracting archive/||/RAR archive data/{_file_type="rar"}
/Zip archive data/{_file_type="zip"}
/SAPCAR archive data/{_file_type="sapcar"}
END{print _file_type}')
if [[ ${_FILE_TYPE}. = "rar." ]]; then
_list_content="lsar"
elif [[ ${_FILE_TYPE}. = "zip." ]]; then
_list_content="zipinfo -1"
elif [[ ${_FILE_TYPE}. = "sapcar." ]]; then
_list_content="sapcar -tvf"
elif [[ ${_FILE_TYPE}. = "generic." ]]; then
printf "%-24s%s\n" "sap_unknown" "${_FILE_OUTPUT}"
fi
if [[ ${_FILE_TYPE}. != "generic." ]]; then
_SAP_FILE_TYPE=$(eval "${_list_content}" "${_FILE}" | awk '
BEGIN{_sap_file_type="sap_unknown"}
/BD_SYBASE_ASE/{_sap_file_type="sap_db_ase"}
/MaxDB_7.9/{_sap_file_type="sap_db_maxdb"}
/19cinstall.sh/||/OCL_LINUX_X86_64/{_sap_file_type="sap_db_oracle"}
/db2setup/||/db6_update_client.sh/||/db2aese_c.lic/{_sap_file_type="sap_db_db2"}
/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"}
END{print _sap_file_type}')
printf "%-24s%s\n" "${_SAP_FILE_TYPE}" "${_FILE_OUTPUT}"
fi
fi
done