aboutsummaryrefslogtreecommitdiff
#!/bin/sh

# This file is part of Haketilo
#
# Copyright (C) 2021, Wojtek Kosior
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 Universal License as published by
# the Creative Commons Corporation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# CC0 1.0 Universal License for more details.

set -e

print_usage() {
    printf 'usage:  %s mozilla|chromium [source directory] [update url]\n' \
	   "$0" >&2
}

call_awk() {
    local BROWSER_UPCASE="$(printf %s "$BROWSER" | tr '[:lower:]' '[:upper:]')"
    awk -f compute_scripts.awk -- -M manifest.json -D "$BROWSER_UPCASE" \
	-D MV2 --output=files-to-copy --write-js-deps --write-html-deps \
	--output-dir="$BUILDDIR"
}

main() {
    if [ "x$1" = "xmozilla" -o "x$1" = "xchromium" ]; then
	BROWSER=$1
    else
	print_usage
	exit 1
    fi

    SRCDIR="${2:-.}"
    if [ -d "$SRCDIR" ]; then
	BUILDDIR="$(realpath $BROWSER-unpacked)"
	rm -rf "$BUILDDIR"
	mkdir "$BUILDDIR"
	cd "$SRCDIR"
    else
	print_usage
	exit 2
    fi

    UPDATE_URL="$3"
    if [ -n "$3" ]; then
	printf 'possibility of using an update url is currently unimplemented' \
	       >&2
	exit 1
    fi

    FILES_TO_COPY="$(call_awk)"
    for FILE in $FILES_TO_COPY; do
	FILEDIR="$(printf %s "$FILE" | sed 's_[^/]*$_/_')"
	if [ -n "$FILEDIR" -a ! -d "$BUILDDIR/$FILEDIR" ]; then
	    mkdir -p "$BUILDDIR/$FILEDIR"
	fi
	cp "$FILE" "$BUILDDIR/$FILE"
    done

    cp -r copyright licenses/ "$BUILDDIR"
}

main "$@"