[fix] apply shell formating / shfmt (make format.shell)

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2025-07-16 17:52:32 +02:00 committed by Markus Heiser
parent cd062d7349
commit 8c2c3430da
16 changed files with 492 additions and 419 deletions

View file

@ -37,16 +37,16 @@ setup_ownership() {
local type="$2"
case "$type" in
file | directory) ;;
*)
cat <<EOF
file | directory) ;;
*)
cat <<EOF
!!!
!!! ERROR
!!! "$type" is not a valid type, exiting...
!!!
EOF
exit 1
;;
exit 1
;;
esac
target_ownership=$(stat -c %U:%G "$target")

58
manage
View file

@ -58,7 +58,7 @@ while IFS= read -r line; do
if [ "$line" != "tests/unit/settings/syntaxerror_settings.yml" ]; then
YAMLLINT_FILES+=("$line")
fi
done <<< "$(git ls-files './tests/*.yml' './searx/*.yml' './utils/templates/etc/searxng/*.yml' '.github/*.yml' '.github/*/*.yml')"
done <<<"$(git ls-files './tests/*.yml' './searx/*.yml' './utils/templates/etc/searxng/*.yml' '.github/*.yml' '.github/*/*.yml')"
RST_FILES=(
'README.rst'
@ -129,7 +129,6 @@ dev.env() {
fi
}
if [ "$VERBOSE" = "1" ]; then
SPHINX_VERBOSE="-v"
PYLINT_VERBOSE="-v"
@ -142,14 +141,14 @@ webapp.run() {
local parent_proc="$$"
(
if [ "${LIVE_THEME}" ]; then
( themes.live "${LIVE_THEME}" )
(themes.live "${LIVE_THEME}")
kill $parent_proc
fi
)&
) &
(
sleep 3
xdg-open http://127.0.0.1:8888/
)&
) &
SEARXNG_DEBUG=1 \
GRANIAN_RELOAD="true" \
GRANIAN_RELOAD_IGNORE_WORKER_FAILURE="true" \
@ -172,10 +171,11 @@ gecko.driver() {
build_msg INSTALL "gecko.driver"
# run installation in a subprocess and activate pyenv
( set -e
(
set -e
pyenv.activate
INSTALLED_VERSION=$(geckodriver -V 2> /dev/null | head -1 | awk '{ print "v" $2}') || INSTALLED_VERSION=""
INSTALLED_VERSION=$(geckodriver -V 2>/dev/null | head -1 | awk '{ print "v" $2}') || INSTALLED_VERSION=""
set +e
if [ "${INSTALLED_VERSION}" = "${GECKODRIVER_VERSION}" ]; then
build_msg INSTALL "geckodriver already installed"
@ -183,13 +183,13 @@ gecko.driver() {
fi
PLATFORM="$(python -c 'import platform; print(platform.system().lower(), platform.architecture()[0])')"
case "$PLATFORM" in
"linux 32bit" | "linux2 32bit") ARCH="linux32";;
"linux 64bit" | "linux2 64bit") ARCH="linux64";;
"windows 32 bit") ARCH="win32";;
"windows 64 bit") ARCH="win64";;
"mac 64bit") ARCH="macos";;
"linux 32bit" | "linux2 32bit") ARCH="linux32" ;;
"linux 64bit" | "linux2 64bit") ARCH="linux64" ;;
"windows 32 bit") ARCH="win32" ;;
"windows 64 bit") ARCH="win64" ;;
"mac 64bit") ARCH="macos" ;;
esac
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz";
GECKODRIVER_URL="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-$ARCH.tar.gz"
build_msg GECKO "Installing ${PY_ENV_BIN}/geckodriver from $GECKODRIVER_URL"
@ -204,13 +204,14 @@ gecko.driver() {
py.build() {
build_msg BUILD "python package ${PYDIST}"
pyenv.cmd python setup.py \
sdist -d "${PYDIST}" \
bdist_wheel --bdist-dir "${PYBUILD}" -d "${PYDIST}"
sdist -d "${PYDIST}" \
bdist_wheel --bdist-dir "${PYBUILD}" -d "${PYDIST}"
}
py.clean() {
build_msg CLEAN pyenv
( set -e
(
set -e
pyenv.drop
[ "$VERBOSE" = "1" ] && set -x
rm -rf "${PYDIST}" "${PYBUILD}" "${PY_ENV}" ./.tox ./*.egg-info
@ -221,7 +222,7 @@ py.clean() {
}
pyenv.check() {
cat <<EOF
cat <<EOF
import yaml
print('import yaml --> OK')
EOF
@ -230,13 +231,14 @@ EOF
pyenv.install() {
if ! pyenv.OK; then
py.clean > /dev/null
py.clean >/dev/null
fi
if pyenv.install.OK > /dev/null; then
if pyenv.install.OK >/dev/null; then
return 0
fi
( set -e
(
set -e
pyenv
build_msg PYENV "[install] pip install --use-pep517 --no-build-isolation -e 'searx${PY_SETUP_EXTRAS}'"
"${PY_ENV_BIN}/python" -m pip install --use-pep517 --no-build-isolation -e ".${PY_SETUP_EXTRAS}"
@ -249,8 +251,8 @@ pyenv.install() {
pyenv.uninstall() {
build_msg PYENV "[pyenv.uninstall] uninstall packages: ${PYOBJECTS}"
pyenv.cmd python setup.py develop --uninstall 2>&1 \
| prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
pyenv.cmd python setup.py develop --uninstall 2>&1 |
prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
}
@ -272,7 +274,7 @@ docs.prebuild() {
set -e
[ "$VERBOSE" = "1" ] && set -x
mkdir -p "${DOCS_BUILD}/includes"
./utils/searxng.sh searxng.doc.rst > "${DOCS_BUILD}/includes/searxng.rst"
./utils/searxng.sh searxng.doc.rst >"${DOCS_BUILD}/includes/searxng.rst"
pyenv.cmd searxng_extra/docs_prebuild
)
dump_return $?
@ -282,7 +284,8 @@ docs.prebuild() {
main() {
local _type
local cmd="$1"; shift
local cmd="$1"
shift
if [ "$cmd" == "" ]; then
help
@ -291,8 +294,11 @@ main() {
fi
case "$cmd" in
--getenv) var="$1"; echo "${!var}";;
--help) help;;
--getenv)
var="$1"
echo "${!var}"
;;
--help) help ;;
--*)
help
err_msg "unknown option $cmd"

View file

@ -27,6 +27,6 @@ build.env.export() {
}
pushd "${REPO_ROOT}" &> /dev/null
pushd "${REPO_ROOT}" &>/dev/null
build.env.export
popd &> /dev/null
popd &>/dev/null

View file

@ -4,11 +4,20 @@
# shellcheck disable=SC2059,SC1117
# ubuntu, debian, arch, fedora, centos ...
DIST_ID=$(source /etc/os-release; echo "$ID");
DIST_ID=$(
source /etc/os-release
echo "$ID"
)
# shellcheck disable=SC2034
DIST_VERS=$(source /etc/os-release; echo "$VERSION_ID");
DIST_VERS=$(
source /etc/os-release
echo "$VERSION_ID"
)
# shellcheck disable=SC2034
DIST_VERSION_CODENAME=$(source /etc/os-release; echo "$VERSION_CODENAME");
DIST_VERSION_CODENAME=$(
source /etc/os-release
echo "$VERSION_CODENAME"
)
ADMIN_NAME="${ADMIN_NAME:-$(git config user.name)}"
ADMIN_NAME="${ADMIN_NAME:-$USER}"
@ -18,10 +27,10 @@ ADMIN_EMAIL="${ADMIN_EMAIL:-$USER@$(hostname)}"
if [[ -z "${REPO_ROOT}" ]]; then
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")
while [ -h "${REPO_ROOT}" ] ; do
while [ -h "${REPO_ROOT}" ]; do
REPO_ROOT=$(readlink "${REPO_ROOT}")
done
REPO_ROOT=$(cd "${REPO_ROOT}/.." && pwd -P )
REPO_ROOT=$(cd "${REPO_ROOT}/.." && pwd -P)
fi
if [[ -z ${TEMPLATES} ]]; then
@ -34,7 +43,7 @@ fi
if [[ -z ${DIFF_CMD} ]]; then
DIFF_CMD="diff -u"
if command -v colordiff >/dev/null; then
if command -v colordiff >/dev/null; then
DIFF_CMD="colordiff -u"
fi
fi
@ -53,7 +62,7 @@ source_dot_config() {
sudo_or_exit() {
# usage: sudo_or_exit
if [ ! "$(id -u)" -eq 0 ]; then
if [ ! "$(id -u)" -eq 0 ]; then
err_msg "this command requires root (sudo) privilege!" >&2
exit 42
fi
@ -87,7 +96,7 @@ set_terminal_colors() {
_hide_cursor='\e[?25l'
# SGR (Select Graphic Rendition) parameters
_creset='\e[0m' # reset all attributes
_creset='\e[0m' # reset all attributes
# original specification only had 8 colors
_colors=8
@ -128,9 +137,9 @@ rst_title() {
# usage: rst_title <header-text> [part|chapter|section]
case ${2-chapter} in
part) printf "\n${_BGreen}${1//?/=}${_creset}\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n";;
chapter) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n";;
section) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/-}${_creset}\n";;
part) printf "\n${_BGreen}${1//?/=}${_creset}\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n" ;;
chapter) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n" ;;
section) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/-}${_creset}\n" ;;
*)
err_msg "invalid argument '${2}' in line $(caller)"
return 42
@ -150,16 +159,16 @@ rst_para() {
}
die() {
echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${2-died ${1-1}}" >&2;
echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${2-died ${1-1}}" >&2
exit "${1-1}"
}
die_caller() {
echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[2]}: line ${BASH_LINENO[1]}: ${FUNCNAME[1]}(): ${2-died ${1-1}}" >&2;
echo -e "${_BRed}ERROR:${_creset} ${BASH_SOURCE[2]}: line ${BASH_LINENO[1]}: ${FUNCNAME[1]}(): ${2-died ${1-1}}" >&2
exit "${1-1}"
}
err_msg() { echo -e "${_BRed}ERROR:${_creset} $*" >&2; }
err_msg() { echo -e "${_BRed}ERROR:${_creset} $*" >&2; }
warn_msg() { echo -e "${_BBlue}WARN:${_creset} $*" >&2; }
info_msg() { echo -e "${_BYellow}INFO:${_creset} $*" >&2; }
@ -181,11 +190,11 @@ dump_return() {
clean_stdin() {
if [[ $(uname -s) != 'Darwin' ]]; then
while read -r -n1 -t 0.1; do : ; done
while read -r -n1 -t 0.1; do :; done
fi
}
wait_key(){
wait_key() {
# usage: wait_key [<timeout in sec>]
clean_stdin
@ -233,7 +242,8 @@ ask_yn() {
# shellcheck disable=SC2086,SC2229
read -r -n1 $_t
if [[ -z $REPLY ]]; then
printf "$default\n"; break
printf "$default\n"
break
elif [[ $REPLY =~ ^[Yy]$ ]]; then
exit_val=${EXIT_YES}
printf "\n"
@ -250,7 +260,7 @@ ask_yn() {
return $exit_val
}
tee_stderr () {
tee_stderr() {
# usage::
# tee_stderr 1 <<EOF | python -i
@ -260,23 +270,23 @@ tee_stderr () {
# >>> print("hello")
# hello
local _t="0";
if [[ -n $1 ]] ; then _t="$1"; fi
local _t="0"
if [[ -n $1 ]]; then _t="$1"; fi
(while read -r line; do
# shellcheck disable=SC2086,SC2229
sleep $_t
echo -e "$line" >&2
echo "$line"
# shellcheck disable=SC2086,SC2229
sleep $_t
echo -e "$line" >&2
echo "$line"
done)
}
prefix_stdout () {
prefix_stdout() {
# usage: <cmd> | prefix_stdout [prefix]
local prefix="${_BYellow}-->|${_creset}"
if [[ -n $1 ]] ; then prefix="$1"; fi
if [[ -n $1 ]]; then prefix="$1"; fi
# shellcheck disable=SC2162
(while IFS= read line; do
@ -296,7 +306,7 @@ append_line() {
local LINE=$1
local FILE=$2
grep -qFs -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
grep -qFs -- "$LINE" "$FILE" || echo "$LINE" >>"$FILE"
}
cache_download() {
@ -311,7 +321,7 @@ cache_download() {
mkdir -p "${CACHE}"
fi
if [[ -f "${CACHE}/$2" ]] ; then
if [[ -f "${CACHE}/$2" ]]; then
info_msg "already cached: $1"
info_msg " --> ${CACHE}/$2"
fi
@ -320,9 +330,11 @@ cache_download() {
info_msg "caching: $1"
info_msg " --> ${CACHE}/$2"
if [[ -n ${SUDO_USER} ]]; then
sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1"
exit_value=$?
else
wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
wget --progress=bar -O "${CACHE}/$2" "$1"
exit_value=$?
fi
if [[ ! $exit_value = 0 ]]; then
err_msg "failed to download: $1"
@ -350,7 +362,7 @@ choose_one() {
local default=${DEFAULT_SELECT-1}
local REPLY
local env_name=$1 && shift
local choice=$1;
local choice=$1
local max="${#@}"
local _t
[[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
@ -358,7 +370,7 @@ choose_one() {
list=("$@")
echo -e "${_BGreen}Menu::${_creset}"
for ((i=1; i<= $((max -1)); i++)); do
for ((i = 1; i <= $((max - 1)); i++)); do
if [[ "$i" == "$default" ]]; then
echo -e " ${_BGreen}$i.${_creset}) ${list[$i]} [default]"
else
@ -369,7 +381,7 @@ choose_one() {
clean_stdin
printf "$1 [${_BGreen}$default${_creset}] "
if (( 10 > max )); then
if ((10 > max)); then
# shellcheck disable=SC2086,SC2229
read -r -n1 $_t
else
@ -377,7 +389,7 @@ choose_one() {
read -r $_t
fi
# selection fits
[[ $REPLY =~ ^-?[0-9]+$ ]] && (( REPLY > 0 )) && (( REPLY < max )) && break
[[ $REPLY =~ ^-?[0-9]+$ ]] && ((REPLY > 0)) && ((REPLY < max)) && break
# take default
[[ -z $REPLY ]] && REPLY=$default && break
@ -414,8 +426,14 @@ install_template() {
for i in "$@"; do
case $i in
--no-eval) do_eval=0; shift ;;
--variant=*) variant=":${i#*=}"; shift ;;
--no-eval)
do_eval=0
shift
;;
--variant=*)
variant=":${i#*=}"
shift
;;
*) pos_args+=("$i") ;;
esac
done
@ -431,7 +449,7 @@ install_template() {
info_msg "install (eval=$do_eval): ${dst}"
[[ -n $variant ]] && info_msg "variant --> ${variant}"
if [[ ! -f "${template_origin}" ]] ; then
if [[ ! -f "${template_origin}" ]]; then
err_msg "${template_origin} does not exists"
err_msg "... can't install $dst"
wait_key 30
@ -440,15 +458,15 @@ install_template() {
if [[ "$do_eval" == "1" ]]; then
template_file="${CACHE}${dst}${variant}"
info_msg "BUILD ${template_file}"
info_msg "BUILD using template ${template_origin}"
info_msg "BUILD ${template_file}"
info_msg "BUILD using template ${template_origin}"
if [[ -n ${SUDO_USER} ]]; then
sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")"
else
mkdir -p "$(dirname "${template_file}")"
fi
# shellcheck disable=SC2086
eval "echo \"$(cat ${template_origin})\"" > "${template_file}"
eval "echo \"$(cat ${template_origin})\"" >"${template_file}"
if [[ -n ${SUDO_USER} ]]; then
chown "${SUDO_USER}:${SUDO_USER}" "${template_file}"
fi
@ -461,11 +479,11 @@ install_template() {
if [[ ! -f "${dst}" ]]; then
info_msg "install: ${template_file}"
sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
"${template_file}" "${dst}" | prefix_stdout
"${template_file}" "${dst}" | prefix_stdout
return $?
fi
if [[ -f "${dst}" ]] && cmp --silent "${template_file}" "${dst}" ; then
if [[ -f "${dst}" ]] && cmp --silent "${template_file}" "${dst}"; then
info_msg "file ${dst} already installed"
return 0
fi
@ -474,16 +492,16 @@ install_template() {
while true; do
choose_one _reply "choose next step with file $dst" \
"replace file" \
"leave file unchanged" \
"interactive shell" \
"diff files"
"replace file" \
"leave file unchanged" \
"interactive shell" \
"diff files"
case $_reply in
"replace file")
info_msg "install: ${template_file}"
sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
"${template_file}" "${dst}" | prefix_stdout
"${template_file}" "${dst}" | prefix_stdout
break
;;
"leave file unchanged")
@ -503,6 +521,7 @@ install_template() {
;;
"diff files")
$DIFF_CMD "${dst}" "${template_file}" | prefix_stdout
;;
esac
done
}
@ -514,14 +533,14 @@ service_is_available() {
[[ -z $1 ]] && die_caller 42 "missing argument <URL>"
local URL="$1"
http_code=$(curl -H 'Cache-Control: no-cache' \
--silent -o /dev/null --head --write-out '%{http_code}' --insecure \
"${URL}")
--silent -o /dev/null --head --write-out '%{http_code}' --insecure \
"${URL}")
exit_val=$?
if [[ $exit_val = 0 ]]; then
info_msg "got $http_code from ${URL}"
fi
case "$http_code" in
404|410|423) exit_val=$http_code;;
404 | 410 | 423) exit_val=$http_code ;;
esac
return "$exit_val"
}
@ -549,7 +568,7 @@ PYBUILD="${PYBUILD:=build/py${PY}}"
#PY_SETUP_EXTRAS='[develop,test]'
PY_SETUP_EXTRAS="${PY_SETUP_EXTRAS:=[develop,test]}"
PIP_BOILERPLATE=( pip wheel setuptools )
PIP_BOILERPLATE=(pip wheel setuptools)
# shellcheck disable=SC2120
pyenv() {
@ -563,28 +582,28 @@ pyenv() {
# files.
required_commands \
sha256sum "${PYTHON}" \
|| exit
sha256sum "${PYTHON}" ||
exit
local pip_req=()
if ! pyenv.OK > /dev/null; then
if ! pyenv.OK >/dev/null; then
rm -f "${PY_ENV}/${PY_ENV_REQ}.sha256"
pyenv.drop > /dev/null
pyenv.drop >/dev/null
build_msg PYENV "[virtualenv] installing ${PY_ENV_REQ} into ${PY_ENV}"
"${PYTHON}" -m venv "$@" "${PY_ENV}"
"${PY_ENV_BIN}/python" -m pip install -U "${PIP_BOILERPLATE[@]}"
for i in ${PY_ENV_REQ}; do
pip_req=( "${pip_req[@]}" "-r" "$i" )
pip_req=("${pip_req[@]}" "-r" "$i")
done
(
[ "$VERBOSE" = "1" ] && set -x
# shellcheck disable=SC2086
"${PY_ENV_BIN}/python" -m pip install "${pip_req[@]}" \
&& sha256sum ${PY_ENV_REQ} > "${PY_ENV}/requirements.sha256"
"${PY_ENV_BIN}/python" -m pip install "${pip_req[@]}" &&
sha256sum ${PY_ENV_REQ} >"${PY_ENV}/requirements.sha256"
)
fi
pyenv.OK
@ -602,17 +621,17 @@ pyenv.OK() {
return 1
fi
if [ ! -f "${PY_ENV}/requirements.sha256" ] \
|| ! sha256sum -c "${PY_ENV}/requirements.sha256" > /dev/null 2>&1; then
if [ ! -f "${PY_ENV}/requirements.sha256" ] ||
! sha256sum -c "${PY_ENV}/requirements.sha256" >/dev/null 2>&1; then
build_msg PYENV "[virtualenv] requirements.sha256 failed"
sed 's/^/ [virtualenv] - /' <"${PY_ENV}/requirements.sha256"
return 1
fi
if [ "$VERBOSE" = "1" ]; then
pyenv.check \
| "${PY_ENV_BIN}/python" 2>&1 \
| prefix_stdout "${_Blue}PYENV ${_creset}[check] "
pyenv.check |
"${PY_ENV_BIN}/python" 2>&1 |
prefix_stdout "${_Blue}PYENV ${_creset}[check] "
else
pyenv.check | "${PY_ENV_BIN}/python" 1>/dev/null
fi
@ -648,7 +667,7 @@ pyenv.check() {
imp="$imp, $i"
done
cat <<EOF
cat <<EOF
import ${imp#,*}
EOF
@ -657,16 +676,16 @@ EOF
pyenv.install() {
if ! pyenv.OK; then
py.clean > /dev/null
py.clean >/dev/null
fi
if ! pyenv.install.OK > /dev/null; then
if ! pyenv.install.OK >/dev/null; then
build_msg PYENV "[install] ${PYOBJECTS}"
if ! pyenv.OK >/dev/null; then
pyenv
fi
for i in ${PYOBJECTS}; do
build_msg PYENV "[install] pip install --use-pep517 --no-build-isolation -e '$i${PY_SETUP_EXTRAS}'"
"${PY_ENV_BIN}/python" -m pip install --use-pep517 --no-build-isolation -e "$i${PY_SETUP_EXTRAS}"
build_msg PYENV "[install] pip install --use-pep517 --no-build-isolation -e '$i${PY_SETUP_EXTRAS}'"
"${PY_ENV_BIN}/python" -m pip install --use-pep517 --no-build-isolation -e "$i${PY_SETUP_EXTRAS}"
done
fi
pyenv.install.OK
@ -708,19 +727,19 @@ pyenv.uninstall() {
build_msg PYENV "[uninstall] ${PYOBJECTS}"
if [ "." = "${PYOBJECTS}" ]; then
pyenv.cmd python setup.py develop --uninstall 2>&1 \
| prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
pyenv.cmd python setup.py develop --uninstall 2>&1 |
prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
else
# shellcheck disable=SC2086
pyenv.cmd python -m pip uninstall --yes ${PYOBJECTS} 2>&1 \
| prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
pyenv.cmd python -m pip uninstall --yes ${PYOBJECTS} 2>&1 |
prefix_stdout "${_Blue}PYENV ${_creset}[pyenv.uninstall] "
fi
}
pyenv.cmd() {
pyenv.install
( set -e
(
set -e
# shellcheck source=/dev/null
source "${PY_ENV_BIN}/activate"
[ "$VERBOSE" = "1" ] && set -x
@ -728,14 +747,12 @@ pyenv.cmd() {
)
}
pyenv.activate() {
pyenv.install
# shellcheck source=/dev/null
source "${PY_ENV_BIN}/activate"
}
# Sphinx doc
# ----------
@ -750,18 +767,18 @@ docs.html() {
# shellcheck disable=SC2086
PATH="${PY_ENV_BIN}:${PATH}" pyenv.cmd sphinx-build \
${SPHINX_VERBOSE} ${SPHINXOPTS} \
-b html -c ./docs -d "${DOCS_BUILD}/.doctrees" ./docs "${DOCS_DIST}"
-b html -c ./docs -d "${DOCS_BUILD}/.doctrees" ./docs "${DOCS_DIST}"
dump_return $?
}
docs.live() {
build_msg SPHINX "autobuild ./docs --> file://$(readlink -e "$(pwd)/$DOCS_DIST")"
build_msg SPHINX "autobuild ./docs --> file://$(readlink -e "$(pwd)/$DOCS_DIST")"
pyenv.install
docs.prebuild
# shellcheck disable=SC2086
PATH="${PY_ENV_BIN}:${PATH}" pyenv.cmd sphinx-autobuild \
${SPHINX_VERBOSE} ${SPHINXOPTS} --open-browser --host 0.0.0.0 \
-b html -c ./docs -d "${DOCS_BUILD}/.doctrees" ./docs "${DOCS_DIST}"
-b html -c ./docs -d "${DOCS_BUILD}/.doctrees" ./docs "${DOCS_DIST}"
dump_return $?
}
@ -804,25 +821,25 @@ docs.gh-pages() {
(
git worktree remove -f "${GH_PAGES}"
git branch -D gh-pages
) &> /dev/null || true
) &>/dev/null || true
git worktree add --no-checkout "${GH_PAGES}" "${remote}/master"
pushd "${GH_PAGES}" &> /dev/null
pushd "${GH_PAGES}" &>/dev/null
git checkout --orphan gh-pages
git rm -rfq .
popd &> /dev/null
popd &>/dev/null
cp -r "${DOCS_DIST}"/* "${GH_PAGES}"/
touch "${GH_PAGES}/.nojekyll"
cat > "${GH_PAGES}/404.html" <<EOF
cat >"${GH_PAGES}/404.html" <<EOF
<html><head><META http-equiv='refresh' content='0;URL=index.html'></head></html>
EOF
pushd "${GH_PAGES}" &> /dev/null
pushd "${GH_PAGES}" &>/dev/null
git add --all .
git commit -q -m "gh-pages build from: ${branch}@${head} (${remote_url})"
git push -f "${remote}" gh-pages
popd &> /dev/null
popd &>/dev/null
set +x
build_msg GH-PAGES "deployed"
@ -850,7 +867,7 @@ drop_service_account() {
fi
}
interactive_shell(){
interactive_shell() {
# usage: interactive_shell "${SERVICE_USER}"
@ -858,7 +875,6 @@ interactive_shell(){
sudo -H -u "${1}" -i
}
# systemd
# -------
@ -883,7 +899,7 @@ systemd_remove_service() {
return 42
fi
systemd_deactivate_service "${1}"
rm "${2}" 2>&1 | prefix_stdout
rm "${2}" 2>&1 | prefix_stdout
}
systemd_activate_service() {
@ -927,7 +943,6 @@ systemctl status --no-pager ${1}.service
EOF
}
# nginx
# -----
@ -945,14 +960,14 @@ nginx_distro_setup() {
NGINX_APPS_AVAILABLE="/etc/nginx/default.apps-available"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
NGINX_PACKAGES="nginx"
NGINX_DEFAULT_SERVER=/etc/nginx/sites-available/default
;;
arch-*)
NGINX_PACKAGES="nginx-mainline"
;;
fedora-*|centos-7)
fedora-* | centos-7)
NGINX_PACKAGES="nginx"
;;
*)
@ -961,11 +976,11 @@ nginx_distro_setup() {
esac
}
install_nginx(){
install_nginx() {
info_msg "installing nginx ..."
pkg_install "${NGINX_PACKAGES}"
case $DIST_ID-$DIST_VERS in
arch-*|fedora-*|centos-7)
arch-* | fedora-* | centos-7)
systemctl enable nginx
systemctl start nginx
;;
@ -981,8 +996,8 @@ nginx_reload() {
info_msg "reload nginx .."
echo
if ! nginx -t; then
err_msg "testing nginx configuration failed"
return 42
err_msg "testing nginx configuration failed"
return 42
fi
systemctl restart nginx
}
@ -998,16 +1013,16 @@ nginx_install_app() {
for i in "$@"; do
case $i in
-*) template_opts+=("$i");;
*) pos_args+=("$i");;
-*) template_opts+=("$i") ;;
*) pos_args+=("$i") ;;
esac
done
nginx_include_apps_enabled "${NGINX_DEFAULT_SERVER}"
install_template "${template_opts[@]}" \
"${NGINX_APPS_AVAILABLE}/${pos_args[1]}" \
root root 644
"${NGINX_APPS_AVAILABLE}/${pos_args[1]}" \
root root 644
nginx_enable_app "${pos_args[1]}"
info_msg "installed nginx app: ${pos_args[1]}"
}
@ -1042,8 +1057,7 @@ nginx_include_apps_enabled() {
(
local line
local stage=0
while IFS= read -r line
do
while IFS= read -r line; do
echo "$line"
if [[ $stage = 0 ]]; then
if [[ $line =~ ^[[:space:]]*server*[[:space:]]*\{ ]]; then
@ -1057,8 +1071,8 @@ nginx_include_apps_enabled() {
echo ""
stage=2
fi
done < "${server_conf}.bak"
) > "${server_conf}"
done <"${server_conf}.bak"
) >"${server_conf}"
}
@ -1095,14 +1109,13 @@ nginx_disable_app() {
nginx_reload
}
# Apache
# ------
apache_distro_setup() {
# shellcheck disable=SC2034
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
# debian uses the /etc/apache2 path, while other distros use
# the apache default at /etc/httpd
APACHE_SITES_AVAILABLE="/etc/apache2/sites-available"
@ -1116,7 +1129,7 @@ apache_distro_setup() {
APACHE_MODULES="modules"
APACHE_PACKAGES="apache"
;;
fedora-*|centos-7)
fedora-* | centos-7)
APACHE_SITES_AVAILABLE="/etc/httpd/sites-available"
APACHE_SITES_ENABLED="/etc/httpd/sites-enabled"
APACHE_MODULES="modules"
@ -1128,13 +1141,13 @@ apache_distro_setup() {
esac
}
install_apache(){
install_apache() {
info_msg "installing apache ..."
pkg_install "$APACHE_PACKAGES"
case $DIST_ID-$DIST_VERS in
arch-*|fedora-*|centos-7)
arch-* | fedora-* | centos-7)
if ! grep "IncludeOptional sites-enabled" "/etc/httpd/conf/httpd.conf"; then
echo "IncludeOptional sites-enabled/*.conf" >> "/etc/httpd/conf/httpd.conf"
echo "IncludeOptional sites-enabled/*.conf" >>"/etc/httpd/conf/httpd.conf"
fi
systemctl enable httpd
systemctl start httpd
@ -1144,9 +1157,9 @@ install_apache(){
apache_is_installed() {
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*) (command -v apachectl) &>/dev/null;;
arch-*) (command -v httpd) &>/dev/null;;
fedora-*|centos-7) (command -v httpd) &>/dev/null;;
ubuntu-* | debian-*) (command -v apachectl) &>/dev/null ;;
arch-*) (command -v httpd) &>/dev/null ;;
fedora-* | centos-7) (command -v httpd) &>/dev/null ;;
esac
}
@ -1155,11 +1168,11 @@ apache_reload() {
info_msg "reload apache .."
echo
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
sudo -H apachectl configtest
sudo -H systemctl force-reload apache2
;;
arch-*|fedora-*|centos-7)
arch-* | fedora-* | centos-7)
sudo -H httpd -t
sudo -H systemctl force-reload httpd
;;
@ -1177,14 +1190,14 @@ apache_install_site() {
for i in "$@"; do
case $i in
-*) template_opts+=("$i");;
*) pos_args+=("$i");;
-*) template_opts+=("$i") ;;
*) pos_args+=("$i") ;;
esac
done
install_template "${template_opts[@]}" \
"${APACHE_SITES_AVAILABLE}/${pos_args[1]}" \
root root 644
"${APACHE_SITES_AVAILABLE}/${pos_args[1]}" \
root root 644
apache_enable_site "${pos_args[1]}"
info_msg "installed apache site: ${pos_args[1]}"
}
@ -1207,7 +1220,7 @@ apache_enable_site() {
info_msg "enable apache site: ${CONF}"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
sudo -H a2ensite -q "${CONF}"
;;
arch-*)
@ -1215,7 +1228,7 @@ apache_enable_site() {
rm -f "${APACHE_SITES_ENABLED}/${CONF}"
ln -s "${APACHE_SITES_AVAILABLE}/${CONF}" "${APACHE_SITES_ENABLED}/${CONF}"
;;
fedora-*|centos-7)
fedora-* | centos-7)
mkdir -p "${APACHE_SITES_ENABLED}"
rm -f "${APACHE_SITES_ENABLED}/${CONF}"
ln -s "${APACHE_SITES_AVAILABLE}/${CONF}" "${APACHE_SITES_ENABLED}/${CONF}"
@ -1233,13 +1246,13 @@ apache_disable_site() {
info_msg "disable apache site: ${CONF}"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
sudo -H a2dissite -q "${CONF}"
;;
arch-*)
rm -f "${APACHE_SITES_ENABLED}/${CONF}"
;;
fedora-*|centos-7)
fedora-* | centos-7)
rm -f "${APACHE_SITES_ENABLED}/${CONF}"
;;
esac
@ -1256,7 +1269,7 @@ uWSGI_SETUP="${uWSGI_SETUP:=/etc/uwsgi}"
uWSGI_distro_setup() {
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
# init.d --> /usr/share/doc/uwsgi/README.Debian.gz
# For uWSGI debian uses the LSB init process, this might be changed
# one day, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833067
@ -1273,7 +1286,7 @@ uWSGI_distro_setup() {
uWSGI_APPS_ENABLED="${uWSGI_SETUP}"
uWSGI_PACKAGES="uwsgi"
;;
fedora-*|centos-7)
fedora-* | centos-7)
# systemd --> /usr/lib/systemd/system/uwsgi.service
# Fedora runs uWSGI in emperor-tyrant mode: in Tyrant mode the
# Emperor will run the vassal using the UID/GID of the vassal
@ -1287,14 +1300,14 @@ uWSGI_distro_setup() {
*)
err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
;;
esac
esac
}
install_uwsgi(){
install_uwsgi() {
info_msg "installing uwsgi ..."
pkg_install "$uWSGI_PACKAGES"
case $DIST_ID-$DIST_VERS in
fedora-*|centos-7)
fedora-* | centos-7)
# enable & start should be called once at uWSGI installation time
systemctl enable uwsgi
systemctl restart uwsgi
@ -1311,7 +1324,7 @@ uWSGI_restart() {
[[ -z $CONF ]] && die_caller 42 "missing argument <myapp.ini>"
info_msg "restart uWSGI service"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
# the 'service' method seems broken in that way, that it (re-)starts
# the whole uwsgi process.
service uwsgi restart "${CONF%.*}"
@ -1324,7 +1337,7 @@ uWSGI_restart() {
info_msg "[uWSGI:systemd-template] ${CONF} not installed (no need to restart)"
fi
;;
fedora-*|centos-7)
fedora-* | centos-7)
# in emperor mode, just touch the file to restart
if uWSGI_app_enabled "${CONF}"; then
touch "${uWSGI_APPS_ENABLED}/${CONF}"
@ -1360,14 +1373,14 @@ uWSGI_install_app() {
for i in "$@"; do
case $i in
-*) template_opts+=("$i");;
*) pos_args+=("$i");;
-*) template_opts+=("$i") ;;
*) pos_args+=("$i") ;;
esac
done
mkdir -p "${uWSGI_APPS_AVAILABLE}"
install_template "${template_opts[@]}" \
"${uWSGI_APPS_AVAILABLE}/${pos_args[1]}" \
"${pos_args[2]:-root}" "${pos_args[3]:-root}" "${pos_args[4]:-644}"
"${uWSGI_APPS_AVAILABLE}/${pos_args[1]}" \
"${pos_args[2]:-root}" "${pos_args[3]:-root}" "${pos_args[4]:-644}"
uWSGI_enable_app "${pos_args[1]}"
uWSGI_restart "${pos_args[1]}"
info_msg "uWSGI app: ${pos_args[1]} is installed"
@ -1394,7 +1407,7 @@ uWSGI_app_enabled() {
[[ -z $CONF ]] && die_caller 42 "missing argument <myapp.ini>"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
[[ -f "${uWSGI_APPS_ENABLED}/${CONF}" ]]
exit_val=$?
;;
@ -1402,7 +1415,7 @@ uWSGI_app_enabled() {
systemctl -q is-enabled "uwsgi@${CONF%.*}"
exit_val=$?
;;
fedora-*|centos-7)
fedora-* | centos-7)
[[ -f "${uWSGI_APPS_ENABLED}/${CONF}" ]]
exit_val=$?
;;
@ -1424,7 +1437,7 @@ uWSGI_enable_app() {
[[ -z $CONF ]] && die_caller 42 "missing argument <myapp.ini>"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
mkdir -p "${uWSGI_APPS_ENABLED}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
@ -1437,7 +1450,7 @@ uWSGI_enable_app() {
systemctl enable "uwsgi@${CONF%.*}"
info_msg "enabled uWSGI app: ${CONF} (restart required)"
;;
fedora-*|centos-7)
fedora-* | centos-7)
mkdir -p "${uWSGI_APPS_ENABLED}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
@ -1458,7 +1471,7 @@ uWSGI_disable_app() {
[[ -z $CONF ]] && die_caller 42 "missing argument <myapp.ini>"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
service uwsgi stop "${CONF%.*}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
info_msg "disabled uWSGI app: ${CONF} (restart uWSGI required)"
@ -1468,7 +1481,7 @@ uWSGI_disable_app() {
systemctl disable "uwsgi@${CONF%.*}"
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
;;
fedora-*|centos-7)
fedora-* | centos-7)
# in emperor mode, just remove the app.ini file
rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
;;
@ -1497,7 +1510,7 @@ pkg_install() {
return 42
fi
case $DIST_ID in
ubuntu|debian)
ubuntu | debian)
if [[ $_apt_pkg_info_is_updated == 0 ]]; then
export _apt_pkg_info_is_updated=1
apt update
@ -1513,7 +1526,7 @@ pkg_install() {
# shellcheck disable=SC2068
dnf install -y $@
;;
centos)
centos)
# shellcheck disable=SC2068
yum install -y $@
;;
@ -1533,7 +1546,7 @@ pkg_remove() {
return 42
fi
case $DIST_ID in
ubuntu|debian)
ubuntu | debian)
# shellcheck disable=SC2068
apt-get purge --autoremove --ignore-missing -y $@
;;
@ -1545,7 +1558,7 @@ pkg_remove() {
# shellcheck disable=SC2068
dnf remove -y $@
;;
centos)
centos)
# shellcheck disable=SC2068
yum remove -y $@
;;
@ -1557,20 +1570,20 @@ pkg_is_installed() {
# usage: pkg_is_install foopkg || pkg_install foopkg
case $DIST_ID in
ubuntu|debian)
dpkg -l "$1" &> /dev/null
ubuntu | debian)
dpkg -l "$1" &>/dev/null
return $?
;;
arch)
pacman -Qsq "$1" &> /dev/null
pacman -Qsq "$1" &>/dev/null
return $?
;;
fedora)
dnf list -q --installed "$1" &> /dev/null
dnf list -q --installed "$1" &>/dev/null
return $?
;;
centos)
yum list -q --installed "$1" &> /dev/null
centos)
yum list -q --installed "$1" &>/dev/null
return $?
;;
esac
@ -1609,16 +1622,16 @@ git_clone() {
[[ -z $user ]] && [[ -n "${SUDO_USER}" ]] && user="${SUDO_USER}"
[[ -n $user ]] && bash_cmd="sudo -H -u $user -i"
if [[ -d "${dest}" ]] ; then
if [[ -d "${dest}" ]]; then
info_msg "already cloned: $dest"
tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
cd "${dest}"
git checkout -m -B "$branch" --track "$remote/$branch"
git pull --all
EOF
else
info_msg "clone into: $dest"
tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
mkdir -p "$(dirname "$dest")"
cd "$(dirname "$dest")"
git clone --branch "$branch" --origin "$remote" "$url" "$(basename "$dest")"
@ -1626,11 +1639,10 @@ EOF
fi
}
# IP
# --
global_IPs(){
global_IPs() {
# usage: global_IPS
#
# print list of host's SCOPE global addresses and adapters e.g::
@ -1647,18 +1659,18 @@ primary_ip() {
case $DIST_ID in
arch)
ip -o addr show \
| sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\2/p' \
| head -n 1
ip -o addr show |
sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\2/p' |
head -n 1
;;
*) hostname -I | cut -d' ' -f1 ;;
*) hostname -I | cut -d' ' -f1 ;;
esac
}
# URL
# ---
url_replace_hostname(){
url_replace_hostname() {
# usage: url_replace_hostname <url> <new hostname>

View file

@ -17,7 +17,7 @@ declare main_cmd
NVM_LOCAL_FOLDER=.nvm
[[ -z "${NVM_GIT_URL}" ]] && NVM_GIT_URL="https://github.com/nvm-sh/nvm.git"
[[ -z "${NVM_GIT_URL}" ]] && NVM_GIT_URL="https://github.com/nvm-sh/nvm.git"
[[ -z "${NVM_MIN_NODE_VER}" ]] && NVM_MIN_NODE_VER="16.13.0"
# initialize nvm environment
@ -105,7 +105,7 @@ nvm.install() {
info_msg "install (update) NVM at ${NVM_DIR}"
if nvm.is_installed; then
info_msg "already cloned at: ${NVM_DIR}"
pushd "${NVM_DIR}" &> /dev/null
pushd "${NVM_DIR}" &>/dev/null
git fetch --all | prefix_stdout " ${_Yellow}||${_creset} "
else
# delete any leftovers from previous installations
@ -114,14 +114,14 @@ nvm.install() {
fi
info_msg "clone: ${NVM_GIT_URL}"
git clone "${NVM_GIT_URL}" "${NVM_DIR}" 2>&1 | prefix_stdout " ${_Yellow}||${_creset} "
pushd "${NVM_DIR}" &> /dev/null
pushd "${NVM_DIR}" &>/dev/null
git config --local advice.detachedHead false
fi
NVM_VERSION_TAG="$(git rev-list --tags --max-count=1)"
NVM_VERSION_TAG="$(git describe --abbrev=0 --tags --match "v[0-9]*" "${NVM_VERSION_TAG}")"
info_msg "checkout ${NVM_VERSION_TAG}"
git checkout "${NVM_VERSION_TAG}" 2>&1 | prefix_stdout " ${_Yellow}||${_creset} "
popd &> /dev/null
popd &>/dev/null
if [ -f "${REPO_ROOT}/.nvm_packages" ]; then
cp "${REPO_ROOT}/.nvm_packages" "${NVM_DIR}/default-packages"
fi

View file

@ -12,7 +12,7 @@ REDIS_GROUP="searxng-redis"
REDIS_SERVICE_NAME="searxng-redis"
REDIS_SYSTEMD_UNIT="${SYSTEMD_UNITS}/${REDIS_SERVICE_NAME}.service"
redis.help(){
redis.help() {
cat <<EOF
redis.:
remove : delete user (${REDIS_USER}) and remove service (${REDIS_SERVICE_NAME})
@ -21,7 +21,6 @@ redis.:
EOF
}
redis.remove() {
sudo_or_exit
(
@ -36,7 +35,6 @@ redis.shell() {
interactive_shell "${REDIS_USER}"
}
redis.userdel() {
sudo_or_exit
drop_service_account "${REDIS_USER}"

View file

@ -41,28 +41,28 @@ container.build() {
# Setup arch specific
case $parch in
"X64" | "x86_64" | "amd64")
dockerfile="Dockerfile"
arch="amd64"
variant=""
platform="linux/$arch"
;;
"ARM64" | "aarch64" | "arm64")
dockerfile="Dockerfile"
arch="arm64"
variant=""
platform="linux/$arch"
;;
"ARMV7" | "armhf" | "armv7l" | "armv7")
dockerfile="Dockerfile"
arch="arm"
variant="v7"
platform="linux/$arch/$variant"
;;
*)
err_msg "Unsupported architecture; $parch"
exit 1
;;
"X64" | "x86_64" | "amd64")
dockerfile="Dockerfile"
arch="amd64"
variant=""
platform="linux/$arch"
;;
"ARM64" | "aarch64" | "arm64")
dockerfile="Dockerfile"
arch="arm64"
variant=""
platform="linux/$arch"
;;
"ARMV7" | "armhf" | "armv7l" | "armv7")
dockerfile="Dockerfile"
arch="arm"
variant="v7"
platform="linux/$arch/$variant"
;;
*)
err_msg "Unsupported architecture; $parch"
exit 1
;;
esac
info_msg "Selected platform: $platform"
@ -161,25 +161,25 @@ container.test() {
# Setup arch specific
case $parch in
"X64" | "x86_64" | "amd64")
arch="amd64"
variant=""
platform="linux/$arch"
;;
"ARM64" | "aarch64" | "arm64")
arch="arm64"
variant=""
platform="linux/$arch"
;;
"ARMV7" | "armhf" | "armv7l" | "armv7")
arch="arm"
variant="v7"
platform="linux/$arch/$variant"
;;
*)
err_msg "Unsupported architecture; $parch"
exit 1
;;
"X64" | "x86_64" | "amd64")
arch="amd64"
variant=""
platform="linux/$arch"
;;
"ARM64" | "aarch64" | "arm64")
arch="arm64"
variant=""
platform="linux/$arch"
;;
"ARMV7" | "armhf" | "armv7l" | "armv7")
arch="arm"
variant="v7"
platform="linux/$arch/$variant"
;;
*)
err_msg "Unsupported architecture; $parch"
exit 1
;;
esac
build_msg CONTAINER "Selected platform: $platform"
@ -224,25 +224,25 @@ container.push() {
for arch in "${release_archs[@]}"; do
case $arch in
"X64" | "x86_64" | "amd64")
archs+=("amd64")
variants+=("")
platforms+=("linux/${archs[-1]}")
;;
"ARM64" | "aarch64" | "arm64")
archs+=("arm64")
variants+=("")
platforms+=("linux/${archs[-1]}")
;;
"ARMV7" | "armv7" | "armhf" | "arm")
archs+=("arm")
variants+=("v7")
platforms+=("linux/${archs[-1]}/${variants[-1]}")
;;
*)
err_msg "Unsupported architecture; $arch"
exit 1
;;
"X64" | "x86_64" | "amd64")
archs+=("amd64")
variants+=("")
platforms+=("linux/${archs[-1]}")
;;
"ARM64" | "aarch64" | "arm64")
archs+=("arm64")
variants+=("")
platforms+=("linux/${archs[-1]}")
;;
"ARMV7" | "armv7" | "armhf" | "arm")
archs+=("arm")
variants+=("v7")
platforms+=("linux/${archs[-1]}/${variants[-1]}")
;;
*)
err_msg "Unsupported architecture; $arch"
exit 1
;;
esac
done

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
data.help(){
data.help() {
cat <<EOF
data.:
all : update searx/sxng_locales.py and searx/data/*
@ -13,12 +13,13 @@ EOF
}
data.all() {
( set -e
(
set -e
pyenv.activate
data.traits
data.useragents
data.locales
data.locales
build_msg DATA "update searx/data/osm_keys_tags.json"
pyenv.cmd python searxng_extra/update/update_osm_keys_tags.py
@ -35,9 +36,9 @@ data.all() {
)
}
data.traits() {
( set -e
(
set -e
pyenv.activate
build_msg DATA "update searx/data/engine_traits.json"
python searxng_extra/update/update_engine_traits.py
@ -53,7 +54,8 @@ data.useragents() {
}
data.locales() {
( set -e
(
set -e
pyenv.activate
build_msg DATA "update searx/data/locales.json"
python searxng_extra/update/update_locales.py
@ -61,8 +63,9 @@ data.locales() {
dump_return $?
}
data.currencies(){
( set -e
data.currencies() {
(
set -e
pyenv.activate
build_msg DATA "update searx/data/currencies.json"
python searxng_extra/update/update_currencies.py

View file

@ -6,7 +6,7 @@ declare _creset
export NODE_MINIMUM_VERSION="18.17.0"
node.help(){
node.help() {
cat <<EOF
node.:
env : download & install SearXNG's npm dependencies locally
@ -24,7 +24,8 @@ nodejs.ensure() {
node.env() {
nodejs.ensure
( set -e
(
set -e
build_msg INSTALL "[npm] ./client/simple/package.json"
npm --prefix client/simple install
)
@ -43,20 +44,22 @@ node.clean() {
return 0
fi
build_msg CLEAN "themes -- locally installed npm dependencies"
( set -e
npm --prefix client/simple run clean \
| prefix_stdout "${_Blue}CLEAN ${_creset} "
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
(
set -e
npm --prefix client/simple run clean |
prefix_stdout "${_Blue}CLEAN ${_creset} "
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
return 1
fi
fi
)
build_msg CLEAN "locally installed developer and CI tools"
( set -e
npm --prefix . run clean \
| prefix_stdout "${_Blue}CLEAN ${_creset} "
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
(
set -e
npm --prefix . run clean |
prefix_stdout "${_Blue}CLEAN ${_creset} "
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
return 1
fi
fi
)
dump_return $?
}

View file

@ -1,7 +1,6 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
STATIC_BUILD_COMMIT="[build] /static"
STATIC_BUILT_PATHS=(
'searx/templates/simple/icons.html'
@ -9,7 +8,7 @@ STATIC_BUILT_PATHS=(
'client/simple/package-lock.json'
)
static.help(){
static.help() {
cat <<EOF
static.build.: ${STATIC_BUILD_COMMIT}
commit : build & commit /static folder
@ -57,8 +56,8 @@ static.build.drop() {
# get only last (option -n1) local commit not in remotes
branch="$(git branch --show-current)"
last_commit_id="$(git log -n1 "${branch}" --pretty=format:'%h'\
--not --exclude="${branch}" --branches --remotes)"
last_commit_id="$(git log -n1 "${branch}" --pretty=format:'%h' \
--not --exclude="${branch}" --branches --remotes)"
if [ -z "${last_commit_id}" ]; then
err_msg "there are no local commits"
@ -96,7 +95,8 @@ static.build.commit() {
# drop existing commit from previous build
static.build.drop &>/dev/null
( set -e
(
set -e
# fix & build the themes
themes.fix
themes.lint

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
test.help(){
test.help() {
cat <<EOF
test.:
yamllint : lint YAML files (YAMLLINT_FILES)
@ -28,7 +28,8 @@ test.yamllint() {
}
test.pylint() {
( set -e
(
set -e
pyenv.activate
PYLINT_OPTIONS="--rcfile .pylintrc"
@ -41,10 +42,10 @@ test.pylint() {
build_msg TEST "[pylint] ./searx ./searxng_extra ./tests"
# shellcheck disable=SC2086
pylint ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \
--ignore=searx/engines \
searx searx/searxng.msg \
searxng_extra searxng_extra/docs_prebuild \
tests
--ignore=searx/engines \
searx searx/searxng.msg \
searxng_extra searxng_extra/docs_prebuild \
tests
)
dump_return $?
}
@ -60,13 +61,13 @@ test.pyright() {
build_msg TEST "[pyright/types] suppress warnings related to intentional monkey patching"
# We run Pyright in the virtual environment because pyright executes
# "python" to determine the Python version.
pyenv.cmd npx --no-install pyright -p pyrightconfig.json \
| grep -E '\.py:[0-9]+:[0-9]+'\
| grep -v '/engines/.*.py.* - warning: "logger" is not defined'\
| grep -v '/plugins/.*.py.* - error: "logger" is not defined'\
| grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' \
| grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' \
| grep -v '/engines/.*.py.* - warning: "categories" is not defined'
pyenv.cmd npx --no-install pyright -p pyrightconfig.json |
grep -E '\.py:[0-9]+:[0-9]+' |
grep -v '/engines/.*.py.* - warning: "logger" is not defined' |
grep -v '/plugins/.*.py.* - error: "logger" is not defined' |
grep -v '/engines/.*.py.* - warning: "supported_languages" is not defined' |
grep -v '/engines/.*.py.* - warning: "language_aliases" is not defined' |
grep -v '/engines/.*.py.* - warning: "categories" is not defined'
# ignore exit value from pyright
# dump_return ${PIPESTATUS[0]}
return 0
@ -93,7 +94,8 @@ test.unit() {
test.coverage() {
build_msg TEST 'unit test coverage'
( set -e
(
set -e
pyenv.activate
# shellcheck disable=SC2086
python -m nose2 ${TEST_NOSE2_VERBOSE} -C --log-capture --with-coverage --coverage searx -s tests/unit
@ -114,7 +116,7 @@ test.rst() {
build_msg TEST "[reST markup] ${RST_FILES[*]}"
for rst in "${RST_FILES[@]}"; do
pyenv.cmd rst2html --halt error "$rst" > /dev/null || die 42 "fix issue in $rst"
pyenv.cmd rst2html --halt error "$rst" >/dev/null || die 42 "fix issue in $rst"
done
}
@ -132,7 +134,7 @@ test.pybabel() {
}
test.clean() {
build_msg CLEAN "test stuff"
build_msg CLEAN "test stuff"
rm -rf geckodriver.log .coverage coverage/
dump_return $?
}

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
themes.help(){
themes.help() {
cat <<EOF
themes.:
all : test & build all themes
@ -13,14 +13,16 @@ EOF
}
themes.all() {
( set -e
(
set -e
vite.simple.build
)
dump_return $?
}
themes.simple() {
( set -e
(
set -e
build_msg SIMPLE "theme: run build (simple)"
vite.simple.build
)
@ -28,7 +30,8 @@ themes.simple() {
}
themes.fix() {
( set -e
(
set -e
build_msg SIMPLE "theme: fix (all themes)"
vite.simple.fix
)
@ -36,7 +39,8 @@ themes.fix() {
}
themes.lint() {
( set -e
(
set -e
build_msg SIMPLE "theme: lint (all themes)"
vite.simple.lint
)
@ -44,7 +48,8 @@ themes.lint() {
}
themes.test() {
( set -e
(
set -e
# we run a build to test (in CI)
build_msg SIMPLE "theme: run build (to test)"
vite.simple.build

View file

@ -4,7 +4,7 @@
declare _Blue
declare _creset
vite.help(){
vite.help() {
cat <<EOF
vite.: .. to be done ..
simple.:
@ -30,7 +30,8 @@ VITE_SIMPLE_THEME="${REPO_ROOT}/client/simple"
# }
vite.simple.build() {
( set -e
(
set -e
templates.simple.pygments
node.env
@ -39,19 +40,21 @@ vite.simple.build() {
pushd "${VITE_SIMPLE_THEME}"
npm install
npm run build
popd &> /dev/null
popd &>/dev/null
)
}
vite.simple.fix() {
( set -e
(
set -e
node.env
npm --prefix client/simple run fix
)
}
vite.simple.lint() {
( set -e
(
set -e
node.env
npm --prefix client/simple run lint
)
@ -59,8 +62,8 @@ vite.simple.lint() {
templates.simple.pygments() {
build_msg PYGMENTS "searxng_extra/update/update_pygments.py"
pyenv.cmd python searxng_extra/update/update_pygments.py \
| prefix_stdout "${_Blue}PYGMENTS ${_creset} "
pyenv.cmd python searxng_extra/update/update_pygments.py |
prefix_stdout "${_Blue}PYGMENTS ${_creset} "
if [ "${PIPESTATUS[0]}" -ne "0" ]; then
build_msg PYGMENTS "building LESS files for pygments failed"
return 1

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: AGPL-3.0-or-later
weblate.help(){
weblate.help() {
cat <<EOF
weblate.:
push.translations: push translation changes from SearXNG to Weblate's counterpart
@ -19,8 +19,9 @@ weblate.translations.worktree() {
#
# remote weblate https://translate.codeberg.org/git/searxng/searxng/
( set -e
if ! git remote get-url weblate 2> /dev/null; then
(
set -e
if ! git remote get-url weblate 2>/dev/null; then
git remote add weblate https://translate.codeberg.org/git/searxng/searxng/
fi
if [ -d "${TRANSLATIONS_WORKTREE}" ]; then
@ -49,7 +50,8 @@ weblate.to.translations() {
# 4. In translations worktree, merge changes of branch 'translations' from
# remote 'weblate' and push it on branch 'translations' of 'origin'
( set -e
(
set -e
pyenv.activate
if [ "$(wlc lock-status)" != "locked: True" ]; then
die 1 "weblate must be locked, currently: $(wlc lock-status)"
@ -77,14 +79,18 @@ weblate.translations.commit() {
# create a commit in the local branch (master)
local existing_commit_hash commit_body commit_message exitcode
( set -e
(
set -e
pyenv.activate
# lock change on weblate
wlc lock
# get translations branch in git worktree (TRANSLATIONS_WORKTREE)
weblate.translations.worktree
existing_commit_hash=$(cd "${TRANSLATIONS_WORKTREE}"; git log -n1 --pretty=format:'%h')
existing_commit_hash=$(
cd "${TRANSLATIONS_WORKTREE}"
git log -n1 --pretty=format:'%h'
)
# pull weblate commits
weblate.to.translations
@ -95,20 +101,23 @@ weblate.translations.commit() {
# compile translations
build_msg BABEL 'compile translation catalogs into binary MO files'
pybabel compile --statistics \
-d "searx/translations"
-d "searx/translations"
# update searx/data/translation_labels.json
data.locales
# git add/commit (no push)
commit_body=$(cd "${TRANSLATIONS_WORKTREE}"; git log --pretty=format:'%h - %as - %aN <%ae>' "${existing_commit_hash}..HEAD")
commit_body=$(
cd "${TRANSLATIONS_WORKTREE}"
git log --pretty=format:'%h - %as - %aN <%ae>' "${existing_commit_hash}..HEAD"
)
commit_message=$(echo -e "[l10n] update translations from Weblate\n\n${commit_body}")
git add searx/translations
git add searx/data/locales.json
git commit -m "${commit_message}"
)
exitcode=$?
( # make sure to always unlock weblate
( # make sure to always unlock weblate
set -e
pyenv.cmd wlc unlock
)
@ -133,9 +142,10 @@ weblate.push.translations() {
# 5. Notify Weblate to pull updated 'master' & 'translations' branch.
local messages_pot diff_messages_pot last_commit_hash last_commit_detail \
exitcode
exitcode
messages_pot="${TRANSLATIONS_WORKTREE}/searx/translations/messages.pot"
( set -e
(
set -e
pyenv.activate
# get translations branch in git worktree (TRANSLATIONS_WORKTREE)
weblate.translations.worktree
@ -143,12 +153,14 @@ weblate.push.translations() {
# update messages.pot in the master branch
build_msg BABEL 'extract messages from source files and generate POT file'
pybabel extract -F babel.cfg --project="SearXNG" --version="-" \
-o "${messages_pot}" \
"searx/"
-o "${messages_pot}" \
"searx/"
# stop if there is no meaningful change in the master branch
diff_messages_pot=$(cd "${TRANSLATIONS_WORKTREE}";\
git diff -- "searx/translations/messages.pot")
diff_messages_pot=$(
cd "${TRANSLATIONS_WORKTREE}"
git diff -- "searx/translations/messages.pot"
)
if ! echo "$diff_messages_pot" | grep -qE "[\+\-](msgid|msgstr)"; then
build_msg BABEL 'no changes detected, exiting'
return 42
@ -160,7 +172,7 @@ weblate.push.translations() {
return 0
fi
if [ "$exitcode" -gt 0 ]; then
return $exitcode
return $exitcode
fi
(
set -e
@ -192,7 +204,7 @@ weblate.push.translations() {
-d "${TRANSLATIONS_WORKTREE}/searx/translations"
# git add/commit/push
last_commit_hash=$(git log -n1 --pretty=format:'%h')
last_commit_hash=$(git log -n1 --pretty=format:'%h')
last_commit_detail=$(git log -n1 --pretty=format:'%h - %as - %aN <%ae>' "${last_commit_hash}")
pushd "${TRANSLATIONS_WORKTREE}"
@ -207,7 +219,7 @@ weblate.push.translations() {
wlc pull
)
exitcode=$?
( # make sure to always unlock weblate
( # make sure to always unlock weblate
set -e
pyenv.activate
wlc unlock

View file

@ -5,10 +5,10 @@ valkey.distro.setup() {
# shellcheck disable=SC2034
case $DIST_ID in
ubuntu|debian)
ubuntu | debian)
VALKEY_PACKAGES="valkey-server"
;;
arch|fedora|centos)
arch | fedora | centos)
VALKEY_PACKAGES="valkey"
;;
*)
@ -36,13 +36,13 @@ valkey.backports() {
esac
}
valkey.install(){
valkey.install() {
info_msg "installing valkey ..."
valkey.distro.setup
case $DIST_ID in
debian|ubuntu)
apt-cache show "${VALKEY_PACKAGES}" &> /dev/null || valkey.backports
debian | ubuntu)
apt-cache show "${VALKEY_PACKAGES}" &>/dev/null || valkey.backports
pkg_install "${VALKEY_PACKAGES}"
# do some fix ...
@ -54,7 +54,7 @@ valkey.install(){
systemd_activate_service valkey-server
;;
arch|fedora|centos)
arch | fedora | centos)
pkg_install "${VALKEY_PACKAGES}"
systemd_activate_service valkey
;;

View file

@ -94,7 +94,7 @@ case $DIST_ID-$DIST_VERS in
SEARXNG_BUILD_PACKAGES="${SEARXNG_BUILD_PACKAGES_debian}"
APACHE_PACKAGES="$APACHE_PACKAGES libapache2-mod-proxy-uwsgi"
;;
ubuntu-*|debian-*)
ubuntu-* | debian-*)
SEARXNG_PACKAGES="${SEARXNG_PACKAGES_debian} python-is-python3"
SEARXNG_BUILD_PACKAGES="${SEARXNG_BUILD_PACKAGES_debian}"
;;
@ -142,7 +142,7 @@ instance:
cmd : run command in SearXNG instance's environment (e.g. bash)
EOF
searxng.instance.env
[[ -n ${1} ]] && err_msg "$1"
[[ -n ${1} ]] && err_msg "$1"
}
searxng.instance.env() {
@ -164,52 +164,68 @@ EOF
main() {
case $1 in
install|remove|instance)
install | remove | instance)
nginx_distro_setup
apache_distro_setup
uWSGI_distro_setup
required_commands \
sudo systemctl install git wget curl \
|| exit
sudo systemctl install git wget curl ||
exit
;;
esac
local _usage="unknown or missing $1 command $2"
case $1 in
--getenv) var="$2"; echo "${!var}"; exit 0;;
--cmd) shift; "$@";;
-h|--help) usage; exit 0;;
--getenv)
var="$2"
echo "${!var}"
exit 0
;;
--cmd)
shift
"$@"
;;
-h | --help)
usage
exit 0
;;
install)
sudo_or_exit
case $2 in
all) searxng.install.all;;
user) searxng.install.user;;
pyenv) searxng.install.pyenv;;
searxng-src) searxng.install.clone;;
settings) searxng.install.settings;;
uwsgi) searxng.install.uwsgi;;
packages) searxng.install.packages;;
buildhost) searxng.install.buildhost;;
nginx) searxng.nginx.install;;
apache) searxng.apache.install;;
valkey) searxng.install.valkey;;
*) usage "$_usage"; exit 42;;
all) searxng.install.all ;;
user) searxng.install.user ;;
pyenv) searxng.install.pyenv ;;
searxng-src) searxng.install.clone ;;
settings) searxng.install.settings ;;
uwsgi) searxng.install.uwsgi ;;
packages) searxng.install.packages ;;
buildhost) searxng.install.buildhost ;;
nginx) searxng.nginx.install ;;
apache) searxng.apache.install ;;
valkey) searxng.install.valkey ;;
*)
usage "$_usage"
exit 42
;;
esac
;;
remove)
sudo_or_exit
case $2 in
all) searxng.remove.all;;
user) drop_service_account "${SERVICE_USER}";;
pyenv) searxng.remove.pyenv;;
settings) searxng.remove.settings;;
uwsgi) searxng.remove.uwsgi;;
apache) searxng.apache.remove;;
remove) searxng.nginx.remove;;
valkey) searxng.remove.valkey;;
redis) searxng.remove.redis;;
*) usage "$_usage"; exit 42;;
all) searxng.remove.all ;;
user) drop_service_account "${SERVICE_USER}" ;;
pyenv) searxng.remove.pyenv ;;
settings) searxng.remove.settings ;;
uwsgi) searxng.remove.uwsgi ;;
apache) searxng.apache.remove ;;
remove) searxng.nginx.remove ;;
valkey) searxng.remove.valkey ;;
redis) searxng.remove.redis ;;
*)
usage "$_usage"
exit 42
;;
esac
;;
instance)
@ -228,19 +244,30 @@ main() {
;;
cmd)
sudo_or_exit
shift; shift; searxng.instance.exec "$@"
shift
shift
searxng.instance.exec "$@"
;;
get_setting)
shift; shift; searxng.instance.get_setting "$@"
shift
shift
searxng.instance.get_setting "$@"
;;
call)
# call a function in instance's environment
shift; shift; searxng.instance.self.call "$@"
shift
shift
searxng.instance.self.call "$@"
;;
_call)
shift; shift; "$@"
shift
shift
"$@"
;;
*)
usage "$_usage"
exit 42
;;
*) usage "$_usage"; exit 42;;
esac
;;
*)
@ -363,9 +390,9 @@ searxng.remove.all() {
searxng.install.user() {
rst_title "SearXNG -- install user" section
echo
if getent passwd "${SERVICE_USER}" > /dev/null; then
echo "user already exists"
return 0
if getent passwd "${SERVICE_USER}" >/dev/null; then
echo "user already exists"
return 0
fi
tee_stderr 1 <<EOF | bash | prefix_stdout
@ -384,7 +411,7 @@ searxng.install.packages() {
searxng.install.buildhost() {
TITLE="SearXNG -- install buildhost packages" pkg_install \
"${SEARXNG_PACKAGES} ${SEARXNG_BUILD_PACKAGES}"
"${SEARXNG_PACKAGES} ${SEARXNG_BUILD_PACKAGES}"
}
searxng.install.clone() {
@ -393,7 +420,7 @@ searxng.install.clone() {
die 42 "To clone SearXNG, first install user ${SERVICE_USER}."
fi
echo
if ! sudo -i -u "${SERVICE_USER}" ls -d "$REPO_ROOT" > /dev/null; then
if ! sudo -i -u "${SERVICE_USER}" ls -d "$REPO_ROOT" >/dev/null; then
die 42 "user '${SERVICE_USER}' missed read permission: $REPO_ROOT"
fi
# SERVICE_HOME="$(sudo -i -u "${SERVICE_USER}" echo \$HOME 2>/dev/null)"
@ -415,10 +442,10 @@ searxng.install.clone() {
# https://github.com/searxng/searxng/issues/1251
git config --system --add safe.directory "${REPO_ROOT}/.git"
git_clone "$REPO_ROOT" "${SEARXNG_SRC}" \
"$GIT_BRANCH" "${SERVICE_USER}"
"$GIT_BRANCH" "${SERVICE_USER}"
git config --system --add safe.directory "${SEARXNG_SRC}"
pushd "${SEARXNG_SRC}" > /dev/null
pushd "${SEARXNG_SRC}" >/dev/null
tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
cd "${SEARXNG_SRC}"
git remote set-url origin ${GIT_URL}
@ -426,7 +453,7 @@ git config user.email "${ADMIN_EMAIL}"
git config user.name "${ADMIN_NAME}"
git config --list
EOF
popd > /dev/null
popd >/dev/null
}
searxng.install.link_src() {
@ -476,7 +503,7 @@ searxng.remove.pyenv() {
return
fi
info_msg "remove pyenv activation from ~/.profile"
tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
grep -v 'source ${SEARXNG_PYENV}/bin/activate' ~/.profile > ~/.profile.##
mv ~/.profile.## ~/.profile
EOF
@ -493,9 +520,9 @@ searxng.install.settings() {
mkdir -p "$(dirname "${SEARXNG_SETTINGS_PATH}")"
DEFAULT_SELECT=1 \
install_template --no-eval \
"${SEARXNG_SETTINGS_PATH}" \
"${SERVICE_USER}" "${SERVICE_GROUP}"
install_template --no-eval \
"${SEARXNG_SETTINGS_PATH}" \
"${SERVICE_USER}" "${SERVICE_GROUP}"
tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "root"
sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" "${SEARXNG_SETTINGS_PATH}"
@ -529,9 +556,9 @@ pip install -U --use-pep517 --no-build-isolation -e .
EOF
rst_para "update instance's settings.yml from ${SEARXNG_SETTINGS_PATH}"
DEFAULT_SELECT=2 \
install_template --no-eval \
"${SEARXNG_SETTINGS_PATH}" \
"${SERVICE_USER}" "${SERVICE_GROUP}"
install_template --no-eval \
"${SEARXNG_SETTINGS_PATH}" \
"${SERVICE_USER}" "${SERVICE_GROUP}"
sudo -H -i <<EOF
sed -i -e "s/ultrasecretkey/$(openssl rand -hex 16)/g" "${SEARXNG_SETTINGS_PATH}"
@ -568,10 +595,10 @@ searxng.install.uwsgi.socket() {
# Emperor will run the vassal using the UID/GID of the vassal
# configuration file [1] (user and group of the app .ini file).
# [1] https://uwsgi-docs.readthedocs.io/en/latest/Emperor.html#tyrant-mode-secure-multi-user-hosting
uWSGI_install_app --variant=socket "${SEARXNG_UWSGI_APP}" "${SERVICE_USER}" "${SERVICE_GROUP}"
uWSGI_install_app --variant=socket "${SEARXNG_UWSGI_APP}" "${SERVICE_USER}" "${SERVICE_GROUP}"
;;
*)
uWSGI_install_app --variant=socket "${SEARXNG_UWSGI_APP}"
uWSGI_install_app --variant=socket "${SEARXNG_UWSGI_APP}"
;;
esac
sleep 5
@ -611,11 +638,10 @@ searxng.install.valkey() {
valkey.install
}
searxng.instance.localtest() {
rst_title "Test SearXNG instance locally" section
rst_para "Activate debug mode, start a minimal SearXNG "\
"service and debug a HTTP request/response cycle."
rst_para "Activate debug mode, start a minimal SearXNG " \
"service and debug a HTTP request/response cycle."
if service_is_available "http://${SEARXNG_INTERNAL_HTTP}" &>/dev/null; then
err_msg "URL/port http://${SEARXNG_INTERNAL_HTTP} is already in use, you"
@ -626,7 +652,7 @@ searxng.instance.localtest() {
fi
echo
searxng.instance.debug.on
tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
tee_stderr 0.1 <<EOF | sudo -H -u "${SERVICE_USER}" -i 2>&1 | prefix_stdout "$_service_prefix"
export SEARXNG_SETTINGS_PATH="${SEARXNG_SETTINGS_PATH}"
cd ${SEARXNG_SRC}
timeout 10 python searx/webapp.py &
@ -708,7 +734,7 @@ This installs SearXNG's uWSGI app as Nginx site. The Nginx site is located at:
${NGINX_APPS_AVAILABLE}/${NGINX_SEARXNG_SITE} and requires a uWSGI."
searxng.install.http.pre
if ! nginx_is_installed ; then
if ! nginx_is_installed; then
err_msg "Nginx packages are not installed"
if ! ask_yn "Do you really want to continue and install Nginx packages?" Yn; then
return
@ -749,8 +775,8 @@ searxng.instance.exec() {
die 42 "can't execute: instance does not exist (missed account ${SERVICE_USER})"
fi
sudo -H -i -u "${SERVICE_USER}" \
SEARXNG_UWSGI_USE_SOCKET="${SEARXNG_UWSGI_USE_SOCKET}" \
"$@"
SEARXNG_UWSGI_USE_SOCKET="${SEARXNG_UWSGI_USE_SOCKET}" \
"$@"
}
searxng.instance.self.call() {
@ -769,7 +795,7 @@ EOF
searxng.instance.debug.on() {
warn_msg "Do not enable debug in a production environment!"
info_msg "try to enable debug mode ..."
tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
cd ${SEARXNG_SRC}
sed -i -e "s/debug: false/debug: true/g" "$SEARXNG_SETTINGS_PATH"
EOF
@ -778,7 +804,7 @@ EOF
searxng.instance.debug.off() {
info_msg "try to disable debug mode ..."
tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
tee_stderr 0.1 <<EOF | sudo -H -i 2>&1 | prefix_stdout "$_service_prefix"
cd ${SEARXNG_SRC}
sed -i -e "s/debug: true/debug: false/g" "$SEARXNG_SETTINGS_PATH"
EOF
@ -799,7 +825,7 @@ searxng.instance.inspect() {
echo
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*)
ubuntu-* | debian-*)
# For uWSGI debian uses the LSB init process; for each configuration
# file new uWSGI daemon instance is started with additional option.
service uwsgi status "${SERVICE_NAME}"
@ -812,16 +838,16 @@ searxng.instance.inspect() {
;;
esac
echo -e "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
echo -e "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
read -r -s -n1 -t 5
echo
while true; do
while true; do
trap break 2
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*) tail -f "/var/log/uwsgi/app/${SERVICE_NAME%.*}.log" ;;
arch-*) journalctl -f -u "uwsgi@${SERVICE_NAME%.*}" ;;
fedora-*) journalctl -f -u uwsgi ;;
ubuntu-* | debian-*) tail -f "/var/log/uwsgi/app/${SERVICE_NAME%.*}.log" ;;
arch-*) journalctl -f -u "uwsgi@${SERVICE_NAME%.*}" ;;
fedora-*) journalctl -f -u uwsgi ;;
esac
done
@ -858,10 +884,10 @@ searxng.doc.rst() {
local arch_build="${SEARXNG_BUILD_PACKAGES_arch}"
local fedora_build="${SEARXNG_BUILD_PACKAGES_fedora}"
debian="$(echo "${debian}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
arch="$(echo "${arch}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
arch="$(echo "${arch}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
fedora="$(echo "${fedora}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
debian_build="$(echo "${debian_build}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
arch_build="$(echo "${arch_build}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
arch_build="$(echo "${arch_build}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
fedora_build="$(echo "${fedora_build}" | sed 's/.*/ & \\/' | sed '$ s/.$//')"
if [[ ${SEARXNG_UWSGI_USE_SOCKET} == true ]]; then
@ -870,7 +896,7 @@ searxng.doc.rst() {
uwsgi_variant=':socket'
fi
eval "echo \"$(< "${REPO_ROOT}/docs/build-templates/searxng.rst")\""
eval "echo \"$(<"${REPO_ROOT}/docs/build-templates/searxng.rst")\""
# I use ubuntu-20.04 here to demonstrate that versions are also supported,
# normally debian-* and ubuntu-* are most the same.
@ -885,7 +911,8 @@ searxng.doc.rst() {
echo -e "\n.. START searxng uwsgi-description $DIST_NAME"
case $DIST_ID-$DIST_VERS in
ubuntu-*|debian-*) cat <<EOF
ubuntu-* | debian-*)
cat <<EOF
.. code:: bash
@ -901,8 +928,9 @@ searxng.doc.rst() {
disable: sudo -H rm ${uWSGI_APPS_ENABLED}/${SEARXNG_UWSGI_APP}
EOF
;;
arch-*) cat <<EOF
;;
arch-*)
cat <<EOF
.. code:: bash
@ -919,8 +947,9 @@ EOF
disable: sudo -H systemctl disable uwsgi@${SEARXNG_UWSGI_APP%.*}
EOF
;;
fedora-*|centos-7) cat <<EOF
;;
fedora-* | centos-7)
cat <<EOF
.. code:: bash
@ -933,40 +962,40 @@ EOF
disable: sudo -H rm ${uWSGI_APPS_ENABLED}/${SEARXNG_UWSGI_APP}
EOF
;;
;;
esac
echo -e ".. END searxng uwsgi-description $DIST_NAME"
local _show_cursor="" # prevent from prefix_stdout's trailing show-cursor
local _show_cursor="" # prevent from prefix_stdout's trailing show-cursor
echo -e "\n.. START searxng uwsgi-appini $DIST_NAME"
echo ".. code:: bash"
echo
eval "echo \"$(< "${TEMPLATES}/${uWSGI_APPS_AVAILABLE}/${SEARXNG_UWSGI_APP}${uwsgi_variant}")\"" | prefix_stdout " "
eval "echo \"$(<"${TEMPLATES}/${uWSGI_APPS_AVAILABLE}/${SEARXNG_UWSGI_APP}${uwsgi_variant}")\"" | prefix_stdout " "
echo -e "\n.. END searxng uwsgi-appini $DIST_NAME"
echo -e "\n.. START nginx socket"
echo ".. code:: nginx"
echo
eval "echo \"$(< "${TEMPLATES}/${NGINX_APPS_AVAILABLE}/${NGINX_SEARXNG_SITE}:socket")\"" | prefix_stdout " "
eval "echo \"$(<"${TEMPLATES}/${NGINX_APPS_AVAILABLE}/${NGINX_SEARXNG_SITE}:socket")\"" | prefix_stdout " "
echo -e "\n.. END nginx socket"
echo -e "\n.. START nginx http"
echo ".. code:: nginx"
echo
eval "echo \"$(< "${TEMPLATES}/${NGINX_APPS_AVAILABLE}/${NGINX_SEARXNG_SITE}")\"" | prefix_stdout " "
eval "echo \"$(<"${TEMPLATES}/${NGINX_APPS_AVAILABLE}/${NGINX_SEARXNG_SITE}")\"" | prefix_stdout " "
echo -e "\n.. END nginx http"
echo -e "\n.. START apache socket"
echo ".. code:: apache"
echo
eval "echo \"$(< "${TEMPLATES}/${APACHE_SITES_AVAILABLE}/${APACHE_SEARXNG_SITE}:socket")\"" | prefix_stdout " "
eval "echo \"$(<"${TEMPLATES}/${APACHE_SITES_AVAILABLE}/${APACHE_SEARXNG_SITE}:socket")\"" | prefix_stdout " "
echo -e "\n.. END apache socket"
echo -e "\n.. START apache http"
echo ".. code:: apache"
echo
eval "echo \"$(< "${TEMPLATES}/${APACHE_SITES_AVAILABLE}/${APACHE_SEARXNG_SITE}")\"" | prefix_stdout " "
eval "echo \"$(<"${TEMPLATES}/${APACHE_SITES_AVAILABLE}/${APACHE_SEARXNG_SITE}")\"" | prefix_stdout " "
echo -e "\n.. END apache http"
)
done