Skip to content

Commit

Permalink
Merge pull request sap-linuxlab#529 from berndfinger/issue-523-new
Browse files Browse the repository at this point in the history
sap_install_media_detect: Leave non-role directories untouched
  • Loading branch information
berndfinger authored Nov 23, 2023
2 parents a233540 + 8f02c21 commit 114d0e6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
18 changes: 16 additions & 2 deletions roles/sap_install_media_detect/files/tmp/sapfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
set -o nounset
set -o pipefail

usage () {
usage() {
echo "sapfile: Determine and display SAP file type. If unknown, call the file command."
echo "Usage: sapfile [OPTION...] [FILE...]"
echo "Determine and display type of SAP FILEs, optionally followed by additional information."
echo " -h|--help display this help and exit"
echo " -H|--header display a column header"
echo " -l|--long long listing: also display the file type, taken from the output of the file command"
echo " -e|--extra-long extra long listing: display all information required by role sap_install_media_detect"
echo " -s|--show-file-types show all supported file types"
echo " --lsar_file=<FILE> the name of the program to list the content of a RAR file, if different from 'lsar',"
echo " either as the name of a file in one of the PATH directories or as an FQPN."
echo " When specifying the 'unrar' program, it will be called with option 'lb'."
Expand All @@ -38,6 +39,11 @@ usage () {
echo "- sapcar (SAP program to handle sapcar files; typical filename: SAPCAR_1115-70006178.EXE)"
}

show_file_types() {
awk '!/BEGIN/&&!/END/&&/_sap_file_type=/{gsub (" ", ""); gsub ("\\{_sap_file_type=\"", ": "); gsub ("\"\\}", ""); print $NF}' $0 | \
sort | uniq
}

# defaults:
_DELIMITER=";"

Expand All @@ -53,7 +59,7 @@ if [[ ${#} == 0 ]]; then
exit 1
fi

options=":leHh-:"
options=":leHsh-:"
while getopts "$options" opt; do
case ${opt} in
-)
Expand All @@ -64,6 +70,10 @@ while getopts "$options" opt; do
extra-long)
_DISPLAY_ALL_INFO="y"
;;
show-file-types)
show_file_types
exit 0
;;
header)
_DISPLAY_HEADER="y"
;;
Expand Down Expand Up @@ -109,6 +119,10 @@ while getopts "$options" opt; do
e)
_DISPLAY_ALL_INFO="y"
;;
s)
show_file_types
exit 0
;;
H)
_DISPLAY_HEADER="y"
;;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@

# If any files have been moved to non-extract subdirectories already, move them back to the top level, making the role idempotent
# Reason for noqa: When using pipefail and there is no result from the grep -v, this tail will fail but it should never fail
- name: SAP Install Media Detect - Prepare - Find existing non-extract subdirectories # noqa risky-shell-pipe
ansible.builtin.shell: ls -d {{ __sap_install_media_detect_software_main_directory }}/*/ | grep -v '_extracted'
- name: SAP Install Media Detect - Prepare - Find the relevant non-extract subdirectories # noqa risky-shell-pipe
ansible.builtin.shell:
cmd: >
ls -d sap_hana sap_swpm_download_basket $({{ __sap_install_media_detect_sapfile_path }} -s) 2>/dev/null |
awk '{print ("'{{ __sap_install_media_detect_software_main_directory }}'/"$0"/")}'
chdir: "{{ __sap_install_media_detect_software_main_directory }}"
register: __sap_install_media_detect_register_subdirectories_phase_1b
changed_when: false
failed_when: false

# Reason for noqa: When using pipefail and there is no result from the grep -v, this tail will fail but it should never fail
- name: SAP Install Media Detect - Prepare - Find existing extract subdirectories # noqa risky-shell-pipe
ansible.builtin.shell: ls -d {{ __sap_install_media_detect_software_main_directory }}/*/ | grep '_extracted/$'
register: __sap_install_media_detect_register_subdirectories_phase_1b_extracted
changed_when: false
failed_when: false

- name: SAP Install Media Detect - Prepare - Display the relevant non-extract subdirectories
ansible.builtin.debug:
var: __sap_install_media_detect_register_subdirectories_phase_1b.stdout_lines

- name: SAP Install Media Detect - Prepare - Display existing extract subdirectories
ansible.builtin.debug:
var: __sap_install_media_detect_register_subdirectories_phase_1b_extracted.stdout_lines

- name: SAP Install Media Detect - Prepare - Create list of all files one level below '{{ __sap_install_media_detect_software_main_directory }}'
ansible.builtin.find:
paths: "{{ line_item }}"
Expand All @@ -38,10 +57,18 @@
loop_control:
loop_var: line_item

- name: SAP Install Media Detect - Prepare - Remove the subdirectories
- name: SAP Install Media Detect - Prepare - Remove the relevant non-extract subdirectories
ansible.builtin.file:
path: "{{ line_item }}"
state: absent
loop: "{{ __sap_install_media_detect_register_subdirectories_phase_1b.stdout_lines }}"
loop_control:
loop_var: line_item

- name: SAP Install Media Detect - Prepare - Remove the extract subdirectories
ansible.builtin.file:
path: "{{ line_item }}"
state: absent
loop: "{{ __sap_install_media_detect_register_subdirectories_phase_1b_extracted.stdout_lines }}"
loop_control:
loop_var: line_item

0 comments on commit 114d0e6

Please sign in to comment.