summaryrefslogtreecommitdiff
path: root/deploy/build_common.sh
diff options
context:
space:
mode:
Diffstat (limited to 'deploy/build_common.sh')
-rw-r--r--deploy/build_common.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/deploy/build_common.sh b/deploy/build_common.sh
new file mode 100644
index 0000000..acac5da
--- /dev/null
+++ b/deploy/build_common.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+set -e
+
+INDIR=
+OUTDIR=
+
+error() {
+ >&2 echo "error: $@"
+}
+
+warning() {
+ >&2 echo "warning: $@"
+}
+
+die() {
+ error "$@"
+ exit 1
+}
+
+usage() {
+ local code="$1"
+ cat <<EOF
+usage: $PROGNAME [OPTIONS]
+
+Options:
+ -o output directory
+ -i input directory
+ -h show this help
+EOF
+ exit $code
+}
+
+input_args() {
+ [ -z "$1" ] && usage
+
+ while [[ $# -gt 0 ]]; do
+ case $1 in
+ -o)
+ OUTDIR="$2"
+ shift
+ ;;
+ -i)
+ INDIR="$2"
+ shift
+ ;;
+ -h)
+ usage
+ ;;
+ *)
+ die "unexpected argument: $1"
+ ;;
+ esac
+ shift
+ done
+}
+
+check_args() {
+ [ -z "$OUTDIR" ] && {
+ error "output directory not specified"
+ usage 1
+ }
+ [ -z "$INDIR" ] && {
+ error "input directory not specified"
+ usage 1
+ }
+
+ if [ ! -d "$OUTDIR" ]; then
+ mkdir "$OUTDIR"
+ else
+ warning "$OUTDIR already exists, erasing it"
+ rm "$OUTDIR"/*
+ fi
+} \ No newline at end of file