aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjahoti <jahoti@tilde.team>2021-09-24 00:00:00 +0000
committerjahoti <jahoti@tilde.team>2021-09-24 00:00:00 +0000
commit853d50e5e6bfa6a27e2cbbf5a8efa724e7bee204 (patch)
tree2b916063949ca71b8e4944fc0d3a3014156a9ba1
parente7c425cc7fc5d20bb494912c7d6db9b97c22fd22 (diff)
downloadbrowser-extension-853d50e5e6bfa6a27e2cbbf5a8efa724e7bee204.tar.gz
browser-extension-853d50e5e6bfa6a27e2cbbf5a8efa724e7bee204.zip
Normalize CLI options
Use saner defaults and (where suitable) environment variables
-rwxr-xr-xbuild.sh91
-rwxr-xr-xlib_build.sh2
2 files changed, 54 insertions, 39 deletions
diff --git a/build.sh b/build.sh
index 52eed33..15bff2a 100755
--- a/build.sh
+++ b/build.sh
@@ -10,20 +10,24 @@ print_usage() {
errcho "$@"
fi
- errcho "usage: $0 [OPTION]... BROWSER"
- errcho
- errcho "the -- preceding long forms is optional"
- errcho "browsers:"
- errcho " -C, chromium: build for Chromium and derivatives"
- errcho " -M, mozilla: build for Firefox and derivatives"
- errcho "options:"
- errcho " -b, build [LOC]: set file/directory to use for building"
- errcho " -f, force: delete the build directory if it exists"
- errcho " instead of throwing an error."
- errcho " -h, help: print usage information and exit"
- errcho " -o, output [LOC]: set output file/directory"
- errcho " -z, zip_ext: pack the extension as a file"
- errcho " -7, 7zip: use the '7z' command instead of 'zip'"
+ echo "usage: $0 [OPTION]... BROWSER"
+ echo
+ echo "long options can be provided either in the form"
+ echo "'[OPTION](=[VALUE])' or '--[OPTION] (VALUE)'."
+ echo "browsers:"
+ echo " -C, chromium: build for Chromium and derivatives"
+ echo " -M, mozilla: build for Firefox and derivatives"
+ echo "options:"
+ echo " -b, build=[LOC]: set file/directory to use for building"
+ echo " -h, help: print usage information and exit"
+ echo " -o, output=[LOC]: set output file/directory"
+ echo " -s, safe: don't delete existing directories;"
+ echo " throw an error instead."
+ echo " -z, zip: pack the extension as a file"
+ echo
+ echo "environment variables (optional)"
+ echo " HAKETILO_ZIP: command to use for generating ZIP files"
+ echo " HAKETILO_CHROMIUM: command to user to invoke Chromium"
exit $EXIT_STATUS
}
@@ -33,22 +37,20 @@ print_usage() {
BROWSER=''
BUILDDIR=''
MAKEZIP=0
-FORCE=0
-ZIP_COMMAND='zip -r'
+FORCE=1
while [ "x$1" != x ]; do
case "$1" in
- -C | chromium | --chromium) BROWSER=chromium;;
- -M | mozilla | --mozilla) BROWSER=mozilla;;
- -b | output | --build) BUILDDIR="$2"
- shift;;
- -f | force | --force) FORCE=1;;
- -h | help | --help) print_usage;;
- -o | output | --output) OUTPUT="$2"
- shift;;
- -z | zip_ext | --zip_ext) MAKEZIP=1;;
- -7 | 7zip | --7zip) ZIP_COMMAND='7z a';;
- *) print_usage 2 Unrecognized option "'$1'.";;
+ -C | --chromium | chromium) BROWSER=chromium;;
+ -M | --mozilla | mozilla) BROWSER=mozilla;;
+ -b | --build) BUILDDIR="$2"; shift;;
+ build=*) BUILDDIR="$(echo "$1" | cut -c 7-)";;
+ -h | --help | help) print_usage;;
+ -o | --output) OUTPUT="$2"; shift;;
+ output=*) OUTPUT="$(echo "$1" | cut -c 8-)";;
+ -s | --safe | safe) FORCE=0;;
+ -z | --zip | zip_ext) MAKEZIP=1;;
+ *) print_usage 2 Unrecognized option "'$1'.";;
esac
shift
done
@@ -57,7 +59,24 @@ if [ "x$BROWSER" = x ]; then
print_usage 1 No browser was specified.
fi
-BUILDDIR="${BUILDDIR:-build_$BROWSER}"
+
+if [ $MAKEZIP = 1 ]; then
+ BUILDDIR="${BUILDDIR:-build_$BROWSER}"
+
+ if [ "x$OUTPUT" = x ]; then
+ case $BROWSER in
+ chromium) OUTPUT=build.crx;;
+ mozilla) OUTPUT=build.xpi;;
+ esac
+ fi
+else
+ if [ "x$BUILDDIR" = x ]; then
+ BUILDDIR="${OUTPUT:-build_$BROWSER}"
+ fi
+
+ OUTPUT="${OUTPUT:-$BUILDDIR}"
+fi
+
if [ -e "$BUILDDIR" ]; then
if [ $FORCE = 0 ]; then
errcho "Build directory '$BUILDDIR' exists."
@@ -67,17 +86,13 @@ if [ -e "$BUILDDIR" ]; then
fi
fi
-if [ "x$OUTPUT" = x ]; then
- case "$MAKEZIP$BROWSER" in
- 0*) OUTPUT=build_$BROWSER;;
- 1chromium) OUTPUT=build.crx;;
- 1mozilla) OUTPUT=build.xpi;;
- esac
-fi
-
if [ -e "$OUTPUT" ]; then
- errcho "Output location '$OUTPUT' exists."
- exit 3
+ if [ $FORCE = 0 ]; then
+ errcho "Output location '$OUTPUT' exists."
+ exit 3
+ else
+ rm -rf "$BUILDDIR"
+ fi
fi
mkdir "$BUILDDIR"
diff --git a/lib_build.sh b/lib_build.sh
index c808f03..8b2c046 100755
--- a/lib_build.sh
+++ b/lib_build.sh
@@ -294,7 +294,7 @@ EOF
make_zip() (
cd "$BUILDDIR"
case $BROWSER in
- mozilla) $ZIP_COMMAND build.zip *;;
+ mozilla) ${HAKETILO_ZIP:-zip -r} build.zip *;;
chromium) exit 92;; # Still to do
esac
)