mirror of
https://github.com/hectorm/hblock.git
synced 2026-04-22 15:06:38 +05:30
Added support for an environment file
This commit is contained in:
parent
608a4b8702
commit
3505517541
2 changed files with 15 additions and 12 deletions
20
hblock
20
hblock
|
|
@ -8,6 +8,14 @@
|
|||
set -eu
|
||||
export LC_ALL='C'
|
||||
|
||||
: "${ETCDIR=/etc}"
|
||||
|
||||
# Source environment file if exists.
|
||||
# shellcheck disable=SC1090
|
||||
if [ -f "${ETCDIR?}/hblock/environment" ]; then
|
||||
set -a; . "${ETCDIR?}/hblock/environment"; set +a
|
||||
fi
|
||||
|
||||
# Built-in header.
|
||||
if [ -z "${HBLOCK_HEADER+x}" ]; then
|
||||
HOSTNAME="${HOSTNAME-"$(uname -n)"}"
|
||||
|
|
@ -297,27 +305,27 @@ fetchUrl() {
|
|||
|
||||
main() {
|
||||
# Output file location.
|
||||
outputFileDefault="${HBLOCK_OUTPUT_FILE-/etc/hosts}"
|
||||
outputFileDefault="${HBLOCK_OUTPUT_FILE-"${ETCDIR?}/hosts"}"
|
||||
outputFile="${outputFileDefault?}"
|
||||
|
||||
# File to be included at the beginning of the output file.
|
||||
headerFileDefault="${HBLOCK_HEADER_FILE-/etc/hblock/header}"
|
||||
headerFileDefault="${HBLOCK_HEADER_FILE-"${ETCDIR?}/hblock/header"}"
|
||||
headerFile="${headerFileDefault?}"
|
||||
|
||||
# File to be included at the end of the output file.
|
||||
footerFileDefault="${HBLOCK_FOOTER_FILE-/etc/hblock/footer}"
|
||||
footerFileDefault="${HBLOCK_FOOTER_FILE-"${ETCDIR?}/hblock/footer"}"
|
||||
footerFile="${footerFileDefault?}"
|
||||
|
||||
# File with line separated URLs used to generate the blocklist.
|
||||
sourcesFileDefault="${HBLOCK_SOURCES_FILE-/etc/hblock/sources.list}"
|
||||
sourcesFileDefault="${HBLOCK_SOURCES_FILE-"${ETCDIR?}/hblock/sources.list"}"
|
||||
sourcesFile="${sourcesFileDefault?}"
|
||||
|
||||
# File with line separated entries to be removed from the blocklist.
|
||||
allowlistFileDefault="${HBLOCK_ALLOWLIST_FILE-/etc/hblock/allow.list}"
|
||||
allowlistFileDefault="${HBLOCK_ALLOWLIST_FILE-"${ETCDIR?}/hblock/allow.list"}"
|
||||
allowlistFile="${allowlistFileDefault?}"
|
||||
|
||||
# File with line separated entries to be added to the blocklist.
|
||||
denylistFileDefault="${HBLOCK_DENYLIST_FILE-/etc/hblock/deny.list}"
|
||||
denylistFileDefault="${HBLOCK_DENYLIST_FILE-"${ETCDIR?}/hblock/deny.list"}"
|
||||
denylistFile="${denylistFileDefault?}"
|
||||
|
||||
# Redirection for all entries in the blocklist.
|
||||
|
|
|
|||
|
|
@ -11,13 +11,8 @@ SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P)"
|
|||
|
||||
# Set base environment.
|
||||
export HOSTNAME='hblock'
|
||||
export HBLOCK_OUTPUT_FILE='/dev/null'
|
||||
export HBLOCK_HEADER_FILE='builtin'
|
||||
export HBLOCK_FOOTER_FILE='builtin'
|
||||
export HBLOCK_SOURCES_FILE='builtin'
|
||||
export ETCDIR="${SCRIPT_DIR:?}/etc"
|
||||
export HBLOCK_SOURCES="file://${SCRIPT_DIR:?}/sources.txt"
|
||||
export HBLOCK_ALLOWLIST_FILE='builtin'
|
||||
export HBLOCK_DENYLIST_FILE='builtin'
|
||||
|
||||
runInTestShell() {
|
||||
${TEST_SHELL:-/bin/sh} -- "${@-}" 2>&1 ||:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue