#!/bin/sh # Copyright (C) 2021 jahoti # Redistribution terms are gathered in the `copyright' file. print_usage() { EXIT_STATUS=${1:-0} if [ "x$1" != x ]; then shift 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'" exit $EXIT_STATUS } . ./lib_build.sh BROWSER='' BUILDDIR='' MAKEZIP=0 FORCE=0 ZIP_COMMAND='zip -r' 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'.";; esac shift done if [ "x$BROWSER" = x ]; then print_usage 1 No browser was specified. fi BUILDDIR="${BUILDDIR:-build_$BROWSER}" if [ -e "$BUILDDIR" ]; then if [ $FORCE = 0 ]; then errcho "Build directory '$BUILDDIR' exists." exit 3 else rm -rf "$BUILDDIR" 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 fi mkdir "$BUILDDIR" main if [ $MAKEZIP = 1 ]; then make_zip mv "$BUILDDIR"/build.zip "$OUTPUT" rm -rf "$BUILDDIR" elif [ "$BUILDDIR" != "$OUTPUT" ]; then mv "$BUILDDIR" "$OUTPUT" fi