Skip to content

Commit

Permalink
build.sh: Make more robust & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hoijui committed Aug 22, 2020
1 parent 84a75b3 commit 1f40065
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
#!/bin/bash

cwd=$(pwd)
#!/usr/bin/env bash
# Creates distribution archives.
# Requires the binaries be already built (with make)
# and moved to the stageing area.

# Exit immediately on each error and unset variable;
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
#set -Eeuo pipefail
set -Eeu

argv0=$(echo "$0" | sed -e 's,\\,/,g')
script_dir=$(dirname "$(readlink "$0" || echo "$argv0")")
case "$(uname -s)" in
*CYGWIN*)
script_dir=$(cygpath -w "$script_dir")
;;
Linux)
script_dir=$(dirname "$(readlink -f "$0" || echo "$argv0")")
;;
esac
# shellcheck source=./
root="$script_dir"
cwd="$(pwd)"

BUILD_DIR=dist

BUILD_DIR_STAGING=staging

GIT_TAG_VERSION=`git describe --tag`
GIT_TAG_VERSION="$(git describe --tag)"

RELEASE_FILENAME_PREFIX=svg2shenzhen-extension
# echo "$cwd/$BUILD_DIR/$BUILD_DIR_STAGING"
# echo "$root/$BUILD_DIR/$BUILD_DIR_STAGING"
RELEASE_FILENAME_BASE="${root:?}/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}"

rm -fr $cwd/$BUILD_DIR/*
rm -fr "${root:?}/$BUILD_DIR/"*

mkdir -p "$cwd/$BUILD_DIR/$BUILD_DIR_STAGING"
mkdir -p "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"

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

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

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

cd $cwd/$BUILD_DIR/$BUILD_DIR_STAGING
cd "${root:?}/$BUILD_DIR/$BUILD_DIR_STAGING"

tar -czvf $cwd/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}.tar.gz .
zip -m -x .DS_Store -r $cwd/$BUILD_DIR/${RELEASE_FILENAME_PREFIX}-${GIT_TAG_VERSION}.zip .
tar -czvf "${RELEASE_FILENAME_BASE}.tar.gz" .
zip -m -x .DS_Store -r "${RELEASE_FILENAME_BASE}.zip" .

cd $cwd
cd "$cwd"

ls dist
ls "$BUILD_DIR"

0 comments on commit 1f40065

Please sign in to comment.