Skip to content

Commit 1f40065

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

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

build.sh

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
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+
# shellcheck source=./
22+
root="$script_dir"
23+
cwd="$(pwd)"
424

525
BUILD_DIR=dist
626

727
BUILD_DIR_STAGING=staging
828

9-
GIT_TAG_VERSION=`git describe --tag`
29+
GIT_TAG_VERSION="$(git describe --tag)"
1030

1131
RELEASE_FILENAME_PREFIX=svg2shenzhen-extension
12-
# echo "$cwd/$BUILD_DIR/$BUILD_DIR_STAGING"
32+
# echo "$root/$BUILD_DIR/$BUILD_DIR_STAGING"
33+
RELEASE_FILENAME_BASE="${root:?}/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}"
1334

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

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

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

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

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

24-
cd $cwd/$BUILD_DIR/$BUILD_DIR_STAGING
48+
cd "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"
2549

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 .
50+
tar -czvf "${RELEASE_FILENAME_BASE}.tar.gz" .
51+
zip -m -x .DS_Store -r "${RELEASE_FILENAME_BASE}.zip" .
2852

29-
cd $cwd
53+
cd "$cwd"
3054

31-
ls dist
55+
ls "$BUILD_DIR"

0 commit comments

Comments
 (0)