-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial version of sapfile: Display SAP file types
- Loading branch information
1 parent
cc91fd0
commit 045749c
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |