Skip to content

Commit 784bdd5

Browse files
committed
build.sh: Make more robust & cleanup
1 parent 84a75b3 commit 784bdd5

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

build.sh

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,56 @@
1-
#!/bin/bash
2-
3-
cwd=$(pwd)
1+
#!/usr/bin/env bash
2+
# Creates distribution archives.
3+
# Requires the binaries be already built (with make)
4+
# and moved to the stageing area.
5+
6+
# Exit immediately on each error and unset variable;
7+
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
8+
#set -Eeuo pipefail
9+
set -Eeu
10+
11+
argv0=$(echo "$0" | sed -e 's,\\,/,g')
12+
script_dir=$(dirname "$(readlink "$0" || echo "$argv0")")
13+
case "$(uname -s)" in
14+
*CYGWIN*)
15+
script_dir=$(cygpath -w "$script_dir")
16+
;;
17+
Linux)
18+
script_dir=$(dirname "$(readlink -f "$0" || echo "$argv0")")
19+
;;
20+
esac
21+
script_dir_abs="$(cd "$script_dir"; pwd)"
22+
# shellcheck source=./
23+
root="$script_dir_abs"
24+
cwd="$(pwd)"
425

526
BUILD_DIR=dist
627

728
BUILD_DIR_STAGING=staging
829

9-
GIT_TAG_VERSION=`git describe --tag`
30+
GIT_TAG_VERSION="$(git describe --tag)"
1031

1132
RELEASE_FILENAME_PREFIX=svg2shenzhen-extension
12-
# echo "$cwd/$BUILD_DIR/$BUILD_DIR_STAGING"
33+
# echo "$root/$BUILD_DIR/$BUILD_DIR_STAGING"
34+
RELEASE_FILENAME_BASE="${root:?}/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}"
1335

14-
rm -fr $cwd/$BUILD_DIR/*
36+
rm -fr "${root:?}/$BUILD_DIR/"*
1537

16-
mkdir -p "$cwd/$BUILD_DIR/$BUILD_DIR_STAGING"
38+
mkdir -p "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"
1739

18-
cp -r inkscape/* $cwd/$BUILD_DIR/$BUILD_DIR_STAGING
40+
cp -r "${root:?}/inkscape/"* "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"
1941

20-
find $cwd/$BUILD_DIR/$BUILD_DIR_STAGING -name *.inx -type f -exec sed -i.bak s/SVGSZ_VER/${GIT_TAG_VERSION}/g '{}' \;
42+
find "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING" \
43+
-name "*.inx" \
44+
-type f \
45+
-exec sed -i.bak "s/SVGSZ_VER/${GIT_TAG_VERSION}/g" '{}' \;
2146

22-
rm -fr $cwd/$BUILD_DIR/$BUILD_DIR_STAGING/*.bak
47+
rm -fr "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING/"*.bak
2348

24-
cd $cwd/$BUILD_DIR/$BUILD_DIR_STAGING
49+
cd "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"
2550

26-
tar -czvf $cwd/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}.tar.gz .
27-
zip -m -x .DS_Store -r $cwd/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}.zip .
51+
tar -czvf "${RELEASE_FILENAME_BASE}.tar.gz" .
52+
zip -m -x .DS_Store -r "${RELEASE_FILENAME_BASE}.zip" .
2853

29-
cd $cwd
54+
cd "$cwd"
3055

31-
ls dist
56+
ls "$BUILD_DIR"

0 commit comments

Comments
 (0)