1
|
#!/bin/sh
|
2
|
|
3
|
# This file is part of Haketilo
|
4
|
#
|
5
|
# Copyright (C) 2021, jahoti
|
6
|
#
|
7
|
# This program is free software: you can redistribute it and/or modify
|
8
|
# it under the terms of the CC0 1.0 Universal License as published by
|
9
|
# the Creative Commons Corporation.
|
10
|
#
|
11
|
# This program is distributed in the hope that it will be useful,
|
12
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
# CC0 1.0 Universal License for more details.
|
15
|
|
16
|
set -e
|
17
|
|
18
|
# Set BROWSERPATH appropriately
|
19
|
set_browserpath () {
|
20
|
BROWSERPATH="${BINARY:-$(realpath "$1")}"
|
21
|
}
|
22
|
|
23
|
BINARY="$BROWSER_BIN"
|
24
|
BROWSERPATH=''
|
25
|
SRCDIR=''
|
26
|
TARGET=''
|
27
|
|
28
|
# Parse command line options
|
29
|
while [ "x$1" != x ]; do
|
30
|
case "$1" in
|
31
|
--srcdir=*) SRCDIR="$(echo "$1" | cut -c 10-)";;
|
32
|
--srcdir) SRCDIR="$2"; shift;;
|
33
|
BROWSER_BIN=*) BINARY="$(echo "$1" | cut -c 13-)";;
|
34
|
DESTDIR=*) DESTDIR="$(echo "$1" | cut -c 9-)";;
|
35
|
PYTEST=*) PYTEST="$(echo "$1" | cut -c 8-)";;
|
36
|
PYTHON=*) PYTHON="$(echo "$1" | cut -c 8-)";;
|
37
|
TEST_PORT=*) TEST_PORT="$(echo "$1" | cut -c 11-)";;
|
38
|
TEST_PROFILE=*) TEST_PROFILE="$(echo "$1" | cut -c 14-)";;
|
39
|
UPDATE_URL=*) UPDATE_URL="$(echo "$1" | cut -c 12-)";;
|
40
|
--host=*) TARGET="$(echo "$1" | cut -c 8-)";;
|
41
|
--host) TARGET="$2"; shift;;
|
42
|
|
43
|
# browsers
|
44
|
chromium | chrome | google-chrome | mozilla |\
|
45
|
firefox | librewolf | icecat | iceweasel | abrowser |\
|
46
|
iceweasel-uxp | tor-browser) TARGET=$1;;
|
47
|
*) echo Ignoring option "'$1'";;
|
48
|
esac
|
49
|
shift
|
50
|
done
|
51
|
|
52
|
# Autodetect srcdir
|
53
|
if [ "x$SRCDIR" = x ]; then
|
54
|
SRCDIR=..
|
55
|
if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
|
56
|
SRCDIR=.
|
57
|
fi
|
58
|
fi
|
59
|
|
60
|
# Check srcdir
|
61
|
if [ ! -f "$SRCDIR"/manifest.json ]; then
|
62
|
echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
|
63
|
exit 1
|
64
|
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
|
65
|
echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
|
66
|
exit 1
|
67
|
fi
|
68
|
|
69
|
# Autodetect target
|
70
|
if [ "x$TARGET" = x ]; then
|
71
|
echo Detecting target automatically.
|
72
|
if [ -h /etc/alternatives/x-www-browser ]; then
|
73
|
set_browserpath /etc/alternatives/x-www-browser
|
74
|
TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
|
75
|
tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
|
76
|
else
|
77
|
echo Warning: could not find target automatically. >&2
|
78
|
echo Some make rules may fail. >&2
|
79
|
fi
|
80
|
else
|
81
|
set_browserpath "$(which $TARGET)"
|
82
|
fi
|
83
|
|
84
|
# Check and standardize target
|
85
|
case "$TARGET" in
|
86
|
mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
|
87
|
librewolf | iceweasel | gnu | tor-browser) TARGET=mozilla;;
|
88
|
chromium | chrome | google-chrome | google) TARGET=chromium;;
|
89
|
"") ;;
|
90
|
*) echo Invalid target "'$TARGET'" >&2; exit 2;;
|
91
|
esac
|
92
|
|
93
|
# Autodetect DESTDIR (no check needed)
|
94
|
if [ "x$DESTDIR" = x ]; then
|
95
|
echo Guessing installation directory.
|
96
|
if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
|
97
|
DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
|
98
|
if [ $TARGET = mozilla ]; then
|
99
|
DESTDIR="$DESTDIR"/browser
|
100
|
fi
|
101
|
DESTDIR="$DESTDIR"/extensions
|
102
|
else
|
103
|
echo Warning: could not guess installation directory. >&2
|
104
|
echo Some make rules may fail. >&2
|
105
|
fi
|
106
|
fi
|
107
|
|
108
|
# Write record.conf (LEAVE SRCDIR FIRST)
|
109
|
echo srcdir = "$SRCDIR" > record.conf
|
110
|
echo default_target = "$TARGET" >> record.conf
|
111
|
echo DESTDIR = "$DESTDIR" >> record.conf
|
112
|
echo PYTEST = "${PYTEST:-$(which pytest)}" >> record.conf
|
113
|
echo PYTHON = "${PYTHON:-$(which python3)}" >> record.conf
|
114
|
echo UPDATE_URL = "$UPDATE_URL" >> record.conf
|
115
|
|
116
|
# Write test/config.py (if testing is enabled)
|
117
|
echo from .misc_constants import '*' > test/config.py
|
118
|
echo default_firefox_binary = "'${BINARY:-/usr/lib/icecat/icecat}'" >> test/config.py
|
119
|
echo default_clean_profile_dir = "'$TEST_PROFILE'" or \
|
120
|
default_clean_profile_dir >> test/config.py
|
121
|
echo default_proxy_port = "${TEST_PORT:-1337}" >> test/config.py
|
122
|
|
123
|
|
124
|
# Prepare and run write_makefile.sh (as config.status)
|
125
|
if [ ! -e config.status ]; then
|
126
|
cp "$SRCDIR"/write_makefile.sh config.status
|
127
|
fi
|
128
|
|
129
|
./config.status
|