From 34c0540ec953e10f50203ed25fcc9419ec9451ab Mon Sep 17 00:00:00 2001 From: BlackDex Date: Wed, 15 Feb 2023 21:50:55 +0100 Subject: [PATCH] Make scripts compatible with macOS/BSD All the scripts used by this repo were more focused on Linux based systems. They did not work on macOS or other BSD based systems because of flags or commands which are not available. This PR resolves those items by adjusting the failed commands so they work on both Linux and macOS/BSD systems. Fixes #112 --- Dockerfile | 2 +- scripts/apply_patches.sh | 2 +- scripts/build_web_vault.sh | 4 ++-- scripts/checkout_web_vault.sh | 2 +- scripts/generate_patch_file.sh | 2 +- scripts/package_web_vault.sh | 2 +- scripts/patch_web_vault.sh | 2 +- scripts/tar_web_vault.sh | 14 ++++++++++---- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index feb4697..c9140a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,7 @@ WORKDIR /vault/apps/web RUN npm run dist:oss:selfhost RUN printf '{"version":"%s"}' \ - $(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/dani-garcia/bw_web_builds.git 'v*' | tail -n1 | sed -E 's#.*?refs/tags/v##') \ + $(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/dani-garcia/bw_web_builds.git 'v*' | tail -n1 | grep -Eo '[^\/]*$') \ > build/vw-version.json # Delete debugging map files, optional diff --git a/scripts/apply_patches.sh b/scripts/apply_patches.sh index 291eefe..a735972 100755 --- a/scripts/apply_patches.sh +++ b/scripts/apply_patches.sh @@ -10,7 +10,7 @@ if [[ -z ${PATCH_NAME} ]]; then else echo "Patch file not found, using latest" # If not, use the latest one - PATCH_NAME="$(find ../patches -printf "%f\\n" | sort -V | tail -n1)" + PATCH_NAME="$(find ../patches -type f -print0 | xargs -0 basename -a | sort -V | tail -n1)" fi fi diff --git a/scripts/build_web_vault.sh b/scripts/build_web_vault.sh index a862ef6..7cea847 100755 --- a/scripts/build_web_vault.sh +++ b/scripts/build_web_vault.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") # Error handling handle_error() { @@ -30,7 +30,7 @@ npm run dist:oss:selfhost # Create vw-version.json with the latest tag from the remote repo. printf '{"version":"%s"}' \ - "$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/dani-garcia/bw_web_builds.git 'v*' | tail -n1 | sed -E 's#.*?refs/tags/v##')" \ + "$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/dani-garcia/bw_web_builds.git 'v*' | tail -n1 | grep -Eo '[^\/]*$')" \ > build/vw-version.json popd diff --git a/scripts/checkout_web_vault.sh b/scripts/checkout_web_vault.sh index 1628d24..5e4e4d4 100755 --- a/scripts/checkout_web_vault.sh +++ b/scripts/checkout_web_vault.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") # Error handling handle_error() { diff --git a/scripts/generate_patch_file.sh b/scripts/generate_patch_file.sh index 88709b7..98c8d9b 100755 --- a/scripts/generate_patch_file.sh +++ b/scripts/generate_patch_file.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") # Error handling handle_error() { diff --git a/scripts/package_web_vault.sh b/scripts/package_web_vault.sh index ff53aa9..aefeb1c 100755 --- a/scripts/package_web_vault.sh +++ b/scripts/package_web_vault.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") handle_error() { read -n1 -r -p "FAILED: line $1, exit code $2. Press any key to exit..." _ diff --git a/scripts/patch_web_vault.sh b/scripts/patch_web_vault.sh index ee296a3..358f030 100755 --- a/scripts/patch_web_vault.sh +++ b/scripts/patch_web_vault.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") # Error handling handle_error() { diff --git a/scripts/tar_web_vault.sh b/scripts/tar_web_vault.sh index e296dba..12d7961 100755 --- a/scripts/tar_web_vault.sh +++ b/scripts/tar_web_vault.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -o pipefail -o errexit -BASEDIR=$(dirname "$(readlink -f "$0")") +BASEDIR=$(RL=$(readlink -n "$0"); SP="${RL:-$0}"; dirname "$(cd "$(dirname "${SP}")"; pwd)/$(basename "${SP}")") # Error handling handle_error() { @@ -24,7 +24,7 @@ DATE_FORMAT="${DATE_FORMAT:-%Y-%m-%dT%H:%M:%S%z}" # Preserve previous output if [[ -f "${OUTPUT_NAME}.tar.gz" ]]; then - DATE_SUFFIX=$(date +"${DATE_FORMAT}" -r "${OUTPUT_NAME}.tar.gz") + DATE_SUFFIX=$(date -r "${OUTPUT_NAME}.tar.gz" +"${DATE_FORMAT}") mv "${OUTPUT_NAME}.tar.gz" "${OUTPUT_NAME}_${DATE_SUFFIX}.tar.gz" fi @@ -36,10 +36,16 @@ fi mv build web-vault # Tar the web-vault -tar -czvf "${OUTPUT_NAME}.tar.gz" web-vault --owner=0 --group=0 +# Check if we are using bsdtar or gnu-tar, bsdtar does not support --owner/--group +if [[ "$(tar --version)" =~ .*bsdtar.* ]]; +then + tar -czvf "${OUTPUT_NAME}.tar.gz" web-vault +else + tar -czvf "${OUTPUT_NAME}.tar.gz" web-vault --owner=0 --group=0 +fi # Copy the web-vault -cp -dpr web-vault "${OUTPUT_NAME}" +cp -pR web-vault "${OUTPUT_NAME}" mv web-vault build popd