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
|
BROWSERPATH=''
|
19
|
SRCDIR=''
|
20
|
TARGET=''
|
21
|
BROWSER_BINARY=''
|
22
|
CLEAN_PROFILE=''
|
23
|
DRIVER=''
|
24
|
PYTEST=''
|
25
|
|
26
|
# Parse command line options
|
27
|
while [ "x$1" != x ]; do
|
28
|
case "$1" in
|
29
|
--srcdir=*) SRCDIR="$(printf %s "$1" | cut -c 10-)";;
|
30
|
--srcdir) SRCDIR="$2"; shift;;
|
31
|
--browser-binary=*) BROWSER_BINARY="$(printf %s "$1" | cut -c 18-)";;
|
32
|
--browser-binary) BROWSER_BINARY="$2"; shift;;
|
33
|
--clean-profile=*) CLEAN_PROFILE="$(printf %s "$1" | cut -c 17-)";;
|
34
|
--clean-profile) CLEAN_PROFILE="$2"; shift;;
|
35
|
--driver=*) DRIVER="$(printf %s "$1" | cut -c 10-)";;
|
36
|
--driver) DRIVER="$2"; shift;;
|
37
|
--pytest=*) PYTEST="$(printf %s "$1" | cut -c 10-)";;
|
38
|
--pytest) PYTEST="$2"; shift;;
|
39
|
--srcdir) SRCDIR="$2"; shift;;
|
40
|
"DESTDIR"=*) DESTDIR="$(printf %s "$1" | cut -c 9-)";;
|
41
|
"UPDATE_URL"=*) UPDATE_URL="$(printf %s "$1" | cut -c 12-)";;
|
42
|
--host=*) TARGET="$(printf %s "$1" | cut -c 8-)";;
|
43
|
--host) TARGET="$2"; shift;;
|
44
|
|
45
|
# browsers
|
46
|
chromium | chrome | google-chrome | mozilla |\
|
47
|
firefox | librewolf | icecat | iceweasel | abrowser |\
|
48
|
iceweasel-uxp | tor-browser) TARGET=$1;;
|
49
|
*) echo Ignoring option "'$1'";;
|
50
|
esac
|
51
|
shift
|
52
|
done
|
53
|
|
54
|
# Autodetect srcdir
|
55
|
if [ "x$SRCDIR" = x ]; then
|
56
|
SRCDIR=..
|
57
|
if [ -f manifest.json ] && [ -f write_makefile.sh ]; then
|
58
|
SRCDIR=.
|
59
|
fi
|
60
|
fi
|
61
|
|
62
|
# Check srcdir
|
63
|
if [ ! -f "$SRCDIR"/manifest.json ]; then
|
64
|
echo Invalid source directory "'$SRCDIR'": missing manifest.json >&2
|
65
|
exit 1
|
66
|
elif [ ! -f "$SRCDIR"/write_makefile.sh ]; then
|
67
|
echo Invalid source directory "'$SRCDIR'": missing write_makefile.sh >&2
|
68
|
exit 1
|
69
|
fi
|
70
|
|
71
|
# Autodetect target
|
72
|
if [ "x$TARGET" = x ]; then
|
73
|
echo Detecting target automatically.
|
74
|
if [ -h /etc/alternatives/x-www-browser ]; then
|
75
|
BROWSERPATH="$(realpath /etc/alternatives/x-www-browser)"
|
76
|
TARGET="$(/etc/alternatives/x-www-browser --version 2> /dev/null |
|
77
|
tail -n 1 | awk '{ print $1 }' | tr [A-Z] [a-z])"
|
78
|
else
|
79
|
echo Warning: could not find target automatically. >&2
|
80
|
echo Some make rules may fail. >&2
|
81
|
fi
|
82
|
else
|
83
|
BROWSERPATH="$(realpath "$(which $TARGET)")"
|
84
|
fi
|
85
|
|
86
|
# Autodetect browser binary (needed for Selenium)
|
87
|
if [ "x$BROWSER_BINARY" = x ]; then
|
88
|
if [ "x$TARGET" = xabrowser ]; then
|
89
|
# Trisquel's path to Abrowser
|
90
|
BROWSER_BINARY=/usr/lib/abrowser/abrowser
|
91
|
elif [ "x$TARGET" = xlibrewolf ]; then
|
92
|
# Debian's path to Librewolf
|
93
|
BROWSER_BINARY=/usr/share/librewolf/librewolf
|
94
|
elif [ "x$TARGET" = xiceweasel ]; then
|
95
|
# Parabola's path to Iceweasel
|
96
|
BROWSER_BINARY=/usr/lib/iceweasel/iceweasel
|
97
|
elif [ "x$TARGET" = xicecat ]; then
|
98
|
# Parabola's path to IceCat
|
99
|
BROWSER_BINARY=/usr/lib/icecat/icecat
|
100
|
fi
|
101
|
fi
|
102
|
|
103
|
# Check and standardize target
|
104
|
case "$TARGET" in
|
105
|
mozilla | firefox | abrowser | icecat | iceweasel-uxp |\
|
106
|
librewolf | iceweasel | gnu | tor-browser) TARGET=mozilla;;
|
107
|
chromium | chrome | google-chrome | google) TARGET=chromium;;
|
108
|
"") ;;
|
109
|
*) echo Invalid target "'$TARGET'" >&2; exit 2;;
|
110
|
esac
|
111
|
|
112
|
# Autodetect Selenium driver
|
113
|
if [ "x$DRIVER" = x ]; then
|
114
|
if [ "x$TARGET" = mozilla ]; then
|
115
|
DRIVER=geckodriver
|
116
|
fi
|
117
|
fi
|
118
|
|
119
|
# Autodetect clean profile directory for use in selenium tests
|
120
|
if [ "x$CLEAN_PROFILE" = x ]; then
|
121
|
if [ "x$TARGET" = mozilla ]; then
|
122
|
CLEAN_PROFILE="$SRCDIR"/test/default_profile/icecat_empty
|
123
|
fi
|
124
|
fi
|
125
|
|
126
|
# Autodetect pytest
|
127
|
for PYTEST_GUESS in pytest pytest-3 pytest3; do
|
128
|
if [ "x$PYTEST" = x ]; then
|
129
|
PYTEST="$(which $PYTEST_GUESS || true)"
|
130
|
fi
|
131
|
done
|
132
|
|
133
|
# Autodetect DESTDIR (no check needed)
|
134
|
if [ "x$DESTDIR" = x ]; then
|
135
|
echo Guessing installation directory.
|
136
|
if [ -n "$BROWSERPATH" ] && [ -n "$TARGET" ]; then
|
137
|
DESTDIR="$(dirname "$BROWSERPATH")" # TODO: a hack for Debian?
|
138
|
if [ $TARGET = mozilla ]; then
|
139
|
DESTDIR="$DESTDIR"/browser
|
140
|
fi
|
141
|
DESTDIR="$DESTDIR"/extensions
|
142
|
else
|
143
|
echo Warning: could not guess installation directory. >&2
|
144
|
echo Some make rules may fail. >&2
|
145
|
fi
|
146
|
fi
|
147
|
|
148
|
# Write record.conf (LEAVE SRCDIR FIRST)
|
149
|
printf '%s\n' "srcdir = $SRCDIR" > record.conf
|
150
|
printf '%s\n' "default_target = $TARGET" >> record.conf
|
151
|
printf '%s\n' "DESTDIR = $DESTDIR" >> record.conf
|
152
|
printf '%s\n' "UPDATE_URL = $UPDATE_URL" >> record.conf
|
153
|
printf '%s\n' "DRIVER = $DRIVER" >> record.conf
|
154
|
printf '%s\n' "BROWSER_BINARY = $BROWSER_BINARY" >> record.conf
|
155
|
printf '%s\n' "CLEAN_PROFILE = $CLEAN_PROFILE" >> record.conf
|
156
|
printf '%s\n' "PYTEST = $PYTEST" >> record.conf
|
157
|
|
158
|
# Prepare and run write_makefile.sh (as config.status)
|
159
|
if [ ! -e config.status ]; then
|
160
|
cp "$SRCDIR"/write_makefile.sh config.status
|
161
|
fi
|
162
|
|
163
|
./config.status
|