Project

General

Profile

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

haketilo / build.sh @ 81910556

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]:   file/directory to use for building"
22
    echo "    -h, help:          print usage information and exit"
23
    echo "    -o, output=[LOC]:  output file/directory"
24
    echo "    -k, key=[LOC]:     the key to use in signing a CRX;"
25
    echo "                       builds a CRX instead of a ZIP"
26
    echo "    -s, safe:          don't delete existing directories;"
27
    echo "                       throw an error instead"
28
    echo "    -u, url=[URL]:     URL to check for updates"
29
    echo "    -z, zip:           pack the extension as a file"
30
    echo
31
    echo "environment variables (optional)"
32
    echo "    HAKETILO_ZIP:      command to use for generating ZIP files"
33
    echo "    HAKETILO_CHROMIUM: command to use for invoking Chromium"
34
    
35
    exit $EXIT_STATUS
36
}
37

    
38
. ./lib_build.sh
39

    
40
BROWSER=''
41
BUILDDIR=''
42
KEY=''
43
UPDATE_URL=''
44
MAKEZIP=0
45
FORCE=1
46

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

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

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

    
106
if [ -e "$BUILDDIR" ]; then
107
    if [ $FORCE = 0 ]; then
108
	errcho "Build directory '$BUILDDIR' exists."
109
	exit 3
110
    else
111
	rm -rf "$BUILDDIR"
112
    fi
113
fi
114

    
115
if [ -e "$OUTPUT" ]; then
116
    if [ $FORCE = 0 ]; then
117
	errcho "Output location '$OUTPUT' exists."
118
	exit 3
119
    else
120
	rm -rf "$BUILDDIR"
121
    fi
122
fi
123

    
124
mkdir "$BUILDDIR"
125
main
126
if [ $MAKEZIP = 1 ]; then
127
    make_zip
128
    mv "$PACKDIR"/build.zip "$OUTPUT"
129
    rm -rf "$PACKDIR"
130
elif [ "$BUILDDIR" != "$OUTPUT" ]; then
131
    mv "$BUILDDIR" "$OUTPUT"
132
fi
(2-2/9)