From 30b23a8609e5164b19ed752a78af9a2922194589 Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Fri, 12 Apr 2024 16:13:34 +0200 Subject: [PATCH] chore: added a mechanism to have specific syntax per OS on custom logic Signed-off-by: Adrian Riobo Lorenzo --- Containerfile | 2 +- Makefile | 2 +- entrypoint.sh | 5 ++++- lib/{ => common}/mamp.sh | 0 lib/{ => common}/remote.sh | 0 lib/os/darwin/os.sh | 8 ++++++++ lib/os/linux/os.sh | 8 ++++++++ lib/os/os | 4 ++++ lib/os/windows/os.sh | 9 +++++++++ 9 files changed, 35 insertions(+), 3 deletions(-) rename lib/{ => common}/mamp.sh (100%) rename lib/{ => common}/remote.sh (100%) create mode 100644 lib/os/darwin/os.sh create mode 100644 lib/os/linux/os.sh create mode 100644 lib/os/os create mode 100644 lib/os/windows/os.sh diff --git a/Containerfile b/Containerfile index f7edb98..2f7fdc0 100644 --- a/Containerfile +++ b/Containerfile @@ -4,6 +4,6 @@ LABEL org.opencontainers.image.authors="Adrian Riobo " RUN microdnf install -y openssh-clients sshpass zip jq -COPY lib/* entrypoint.sh /usr/local/bin/ +COPY lib/common/* lib/os/ entrypoint.sh /usr/local/bin/ ENTRYPOINT ["entrypoint.sh"] \ No newline at end of file diff --git a/Makefile b/Makefile index 2847937..8e942dd 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION ?= 0.0.5 +VERSION ?= 0.0.6 CONTAINER_MANAGER ?= podman IMG ?= quay.io/rhqp/deliverest:v${VERSION} diff --git a/entrypoint.sh b/entrypoint.sh index cb9ef5c..147764f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,6 +2,7 @@ # Import libs source remote.sh +source ${OS}/os.sh # Default values TARGET_CLEANUP="${TARGET_CLEANUP:-"true"}" @@ -57,5 +58,7 @@ if [[ ! -z "${TARGET_RESULTS+x}" ]]; then fi if [ "${TARGET_CLEANUP:-}" = "true" ]; then - $(ssh_cmd "rm -r ${TARGET_FOLDER}") + # This will create the cmd based on OS env with the right syntax + cmd="$(remove_folder ${TARGET_FOLDER})" + $(ssh_cmd ${cmd}) fi \ No newline at end of file diff --git a/lib/mamp.sh b/lib/common/mamp.sh similarity index 100% rename from lib/mamp.sh rename to lib/common/mamp.sh diff --git a/lib/remote.sh b/lib/common/remote.sh similarity index 100% rename from lib/remote.sh rename to lib/common/remote.sh diff --git a/lib/os/darwin/os.sh b/lib/os/darwin/os.sh new file mode 100644 index 0000000..67afc97 --- /dev/null +++ b/lib/os/darwin/os.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This lib includes common functions with specific syntax for darwin + +# #1 folder name to be removed +remove_folder () { + echo "rm -r ${1}" +} \ No newline at end of file diff --git a/lib/os/linux/os.sh b/lib/os/linux/os.sh new file mode 100644 index 0000000..4162f82 --- /dev/null +++ b/lib/os/linux/os.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# This lib includes common functions with specific syntax for linux + +# #1 folder name to be removed +remove_folder () { + echo "rm -r ${1}" +} \ No newline at end of file diff --git a/lib/os/os b/lib/os/os new file mode 100644 index 0000000..f29e0e0 --- /dev/null +++ b/lib/os/os @@ -0,0 +1,4 @@ +# This file represents the interface os should comply with + +# This will return syntax remove a folder +remove_folder($1 folder name) string \ No newline at end of file diff --git a/lib/os/windows/os.sh b/lib/os/windows/os.sh new file mode 100644 index 0000000..9e628ef --- /dev/null +++ b/lib/os/windows/os.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# This lib includes common functions with specific syntax for windows + +# #1 folder name to be removed +remove_folder () { + echo "Remove-Item \"${1}\" -Recurse -Force" +} +