Project

General

Profile

Download (3.39 KB) Statistics
| Branch: | Tag: | Revision:

haketilo / build.sh @ fbf0503f

1
#!/bin/sh
2

    
3
# Copyright (C) 2021 jahoti <jahoti@tilde.team>
4
# Redistribution terms are gathered in the `copyright' file.
5

    
6
print_usage() {
7
    EXIT_STATUS=${1:-0}
8
    if [ "x$1" != x ]; then
9
	shift
10
	errcho "$@"
11
    fi
12
    
13
    echo "usage:  $0 [OPTION]... BROWSER"
14
    echo
15
    echo "long options can be provided either in the form"
16
    echo "'[OPTION](=[VALUE])' or '--[OPTION] (VALUE)'."
17
    echo "browsers:"
18
    echo "    -C, chromium:      build for Chromium and derivatives"
19
    echo "    -M, mozilla:       build for Firefox and derivatives"
20
    echo "options:"
21
    echo "    -b, build=[LOC]:   set file/directory to use for building"
22
    echo "    -h, help:          print usage information and exit"
23
    echo "    -o, output=[LOC]:  set output file/directory"
24
    echo "    -k, key=[LOC]:     select a key to use in building and"
25
    echo "                       signing a CRX"
26
    echo "    -s, safe:          don't delete existing directories;"
27
    echo "                       throw an error instead"
28
    echo "    -z, zip:           pack the extension as a file"
29
    echo
30
    echo "environment variables (optional)"
31
    echo "    HAKETILO_ZIP: command to use for generating ZIP files"
32
    echo "    HAKETILO_CHROMIUM: command to user to invoke Chromium"
33
    
34
    exit $EXIT_STATUS
35
}
36

    
37
. ./lib_build.sh
38

    
39
BROWSER=''
40
BUILDDIR=''
41
MAKEZIP=0
42
FORCE=1
43

    
44
while [ "x$1" != x ]; do
45
    case "$1" in
46
	-C | --chromium | chromium) BROWSER=chromium;;
47
	-M | --mozilla | mozilla)    BROWSER=mozilla;;
48
	-b | --build)           BUILDDIR="$2"; shift;;
49
	build=*) BUILDDIR="$(echo "$1" | cut -c 7-)";;
50
	-h | --help | help)              print_usage;;
51
	-k | --key)                  KEY="$2"; shift;;
52
	key=*)        KEY="$(echo "$1" | cut -c 5-)";;
53
	-o | --output)            OUTPUT="$2"; shift;;
54
	output=*)  OUTPUT="$(echo "$1" | cut -c 8-)";;
55
	-s | --safe | safe)                  FORCE=0;;
56
	-z | --zip | zip_ext)              MAKEZIP=1;;
57
	*) print_usage 2 Unrecognized option "'$1'.";;
58
    esac
59
    shift
60
done
61

    
62
if [ "x$BROWSER" = x ]; then
63
    print_usage 1 No browser was specified.
64
elif [ "x$KEY" != x ]; then
65
    if [ $BROWSER != chromium ]; then
66
	print_usage 4 The "'key'" option applies only to builds 'for' Chromium.
67
    elif [ $MAKEZIP = 0 ]; then
68
	print_usage 4 The "'key'" option must be used in conjunction with the "'zip'" option.
69
    elif [ ! -e "$KEY" ]; then
70
	print_usage 5 The specified key file "'$KEY'" does not exist.
71
    fi
72
    KEY="$(realpath "$KEY")"
73
fi
74

    
75
if [ "x$KEY" != x ]; then
76
    PACKDIR="${BUILDDIR:-build_$BROWSER}"
77
    BUILDDIR="$PACKDIR"/inner
78
    OUTPUT="${OUTPUT:-build.crx}"
79
    
80
    mkdir "$PACKDIR"
81
elif [ $MAKEZIP = 1 ]; then
82
    BUILDDIR="${BUILDDIR:-build_$BROWSER}"
83
    PACKDIR="$BUILDDIR"
84
    
85
    if [ "x$OUTPUT" = x ]; then
86
	case $BROWSER in
87
	    chromium)  OUTPUT=build.zip;;
88
	    mozilla)   OUTPUT=build.xpi;;
89
	esac
90
    fi
91
else
92
    if [ "x$BUILDDIR" = x ]; then
93
	BUILDDIR="${OUTPUT:-build_$BROWSER}"
94
    fi
95
    
96
    OUTPUT="${OUTPUT:-$BUILDDIR}"
97
fi
98

    
99
if [ -e "$BUILDDIR" ]; then
100
    if [ $FORCE = 0 ]; then
101
	errcho "Build directory '$BUILDDIR' exists."
102
	exit 3
103
    else
104
	rm -rf "$BUILDDIR"
105
    fi
106
fi
107

    
108
if [ -e "$OUTPUT" ]; then
109
    if [ $FORCE = 0 ]; then
110
	errcho "Output location '$OUTPUT' exists."
111
	exit 3
112
    else
113
	rm -rf "$BUILDDIR"
114
    fi
115
fi
116

    
117
mkdir "$BUILDDIR"
118
main
119
if [ $MAKEZIP = 1 ]; then
120
    make_zip
121
    mv "$PACKDIR"/build.zip "$OUTPUT"
122
    rm -rf "$PACKDIR"
123
elif [ "$BUILDDIR" != "$OUTPUT" ]; then
124
    mv "$BUILDDIR" "$OUTPUT"
125
fi
(2-2/9)