on master help sign in
LXC: normalize package installation & user creation.

utils/lib.sh: - get DIST_ID & DIST_VERSION from /etc/os-release - pkg_[install|remove|...] supports ubuntu, debian, archlinux & fedora utils/lxc.sh - Workaround for the "setrlimit(RLIMIT_CORE): Operation not permitted" error:: 'Set disable_coredump false' >> /etc/sudo.conf utils/[searx.sh|filtron.sh|morty.sh] - switched user creation from 'adduser' perl script to 'useradd' built-in command utils/searx.sh - install packages for ubuntu, debian, archlinux & fedora Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit5fb6d4f508d9744a8d82160ca184729514bc18c8 authorMarkus Heiser <markus.heiser@darmarit.de> dateSun 23 Feb 2020, 12:10 (7 years ago) parente36e0f8
5 files changed+96−34
utils/filtron.sh+6−4 utils/lib.sh+48−9 utils/lxc.sh+8−3 utils/morty.sh+6−4 utils/searx.sh+28−14
utils/filtron.sh+6−4
@@ -106,7 +106,7 @@ main() {
106106 rst_title "$SERVICE_NAME" part
107107
108108 required_commands \
109− dpkg apt-get install git wget curl \
109+ sudo install git wget curl \
110110 || exit
111111
112112 local _usage="unknown or missing $1 command $2"
@@ -231,9 +231,11 @@ assert_user() {
231231 rst_title "user $SERVICE_USER" section
232232 echo
233233 tee_stderr 1 <<EOF | bash | prefix_stdout
234−sudo -H adduser --shell /bin/bash --system --home $SERVICE_HOME \
235− --disabled-password --group --gecos 'Filtron' $SERVICE_USER
236−sudo -H usermod -a -G shadow $SERVICE_USER
234+useradd --shell /bin/bash --system \
235+ --home-dir "$SERVICE_HOME" \
236+ --comment 'Reverse HTTP proxy to filter requests' $SERVICE_USER
237+mkdir "$SERVICE_HOME"
238+chown -R "$SERVICE_GROUP:$SERVICE_GROUP" "$SERVICE_HOME"
237239groups $SERVICE_USER
238240EOF
239241 SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME)"
utils/lib.sh+48−9
@@ -3,6 +3,11 @@
33# SPDX-License-Identifier: AGPL-3.0-or-later
44# shellcheck disable=SC2059,SC1117
55
6+# ubuntu, debian, arch, fedora ...
7+DIST_ID=$(source /etc/os-release; echo $ID);
8+# shellcheck disable=SC2034
9+DIST_VERS=$(source /etc/os-release; echo $VERSION_ID);
10+
611ADMIN_NAME="${ADMIN_NAME:-$(git config user.name)}"
712ADMIN_NAME="${ADMIN_NAME:-$USER}"
813
@@ -54,7 +59,7 @@ sudo_or_exit() {
5459
5560required_commands() {
5661
57− # usage: requires_commands [cmd1 ...]
62+ # usage: required_commands [cmd1 ...]
5863
5964 local exit_val=0
6065 while [ -n "$1" ]; do
@@ -787,9 +792,6 @@ uWSGI_disable_app() {
787792
788793# distro's package manager
789794# ------------------------
790−#
791−# FIXME: Arch Linux & RHEL should be added
792−#
793795
794796pkg_install() {
795797
@@ -801,8 +803,20 @@ pkg_install() {
801803 if ! ask_yn "Should packages be installed?" Yn 30; then
802804 return 42
803805 fi
804− # shellcheck disable=SC2068
805− apt-get install -m -y $@
806+ case $DIST_ID in
807+ ubuntu|debian)
808+ # shellcheck disable=SC2068
809+ apt-get install -m -y $@
810+ ;;
811+ arch)
812+ # shellcheck disable=SC2068
813+ pacman -S --noconfirm $@
814+ ;;
815+ fedora)
816+ # shellcheck disable=SC2068
817+ dnf install -y $@
818+ ;;
819+ esac
806820}
807821
808822pkg_remove() {
@@ -815,15 +829,40 @@ pkg_remove() {
815829 if ! ask_yn "Should packages be removed (purge)?" Yn 30; then
816830 return 42
817831 fi
818− apt-get purge --autoremove --ignore-missing -y "$@"
832+ case $DIST_ID in
833+ ubuntu|debian)
834+ # shellcheck disable=SC2068
835+ apt-get purge --autoremove --ignore-missing -y $@
836+ ;;
837+ arch)
838+ # shellcheck disable=SC2068
839+ pacman -R --noconfirm $@
840+ ;;
841+ fedora)
842+ # shellcheck disable=SC2068
843+ dnf remove -y $@
844+ ;;
845+ esac
819846}
820847
821848pkg_is_installed() {
822849
823850 # usage: pkg_is_install foopkg || pkg_install foopkg
824851
825− dpkg -l "$1" &> /dev/null
826− return $?
852+ case $DIST_ID in
853+ ubuntu|debian)
854+ dpkg -l "$1" &> /dev/null
855+ return $?
856+ ;;
857+ arch)
858+ pacman -Qsq "$1" &> /dev/null
859+ return $?
860+ ;;
861+ fedora)
862+ dnf list -q --installed "$1" &> /dev/null
863+ return $?
864+ ;;
865+ esac
827866}
828867
829868# git tooling
utils/lxc.sh+8−3
@@ -39,12 +39,15 @@ ubu1904_boilerplate="$ubu1804_boilerplate"
3939# shellcheck disable=SC2034
4040archlinux_boilerplate="
4141pacman -Syu --noconfirm
42−pacman -S --noconfirm git curl wget
42+pacman -S --noconfirm git curl wget sudo
43+echo 'Set disable_coredump false' >> /etc/sudo.conf
4344"
4445
46+# shellcheck disable=SC2034
4547fedora31_boilerplate="
4648dnf update -y
47−dnf install -y git curl wget
49+dnf install -y git curl wget hostname
50+echo 'Set disable_coredump false' >> /etc/sudo.conf
4851"
4952
5053REMOTE_IMAGES=()
@@ -162,7 +165,9 @@ main() {
162165 lxc exec "${i}" -- "$@"
163166 exit_val=$?
164167 if [[ $exit_val -ne 0 ]]; then
165− err_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
168+ warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
169+ else
170+ info_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}"
166171 fi
167172 done
168173 ;;
utils/morty.sh+6−4
@@ -105,7 +105,7 @@ main() {
105105 rst_title "$SERVICE_NAME" part
106106
107107 required_commands \
108− dpkg apt-get install git wget curl \
108+ sudo install git wget curl \
109109 || exit
110110
111111 local _usage="ERROR: unknown or missing $1 command $2"
@@ -224,9 +224,11 @@ assert_user() {
224224 rst_title "user $SERVICE_USER" section
225225 echo
226226 tee_stderr 1 <<EOF | bash | prefix_stdout
227−sudo -H adduser --shell /bin/bash --system --home $SERVICE_HOME \
228− --disabled-password --group --gecos 'Morty' $SERVICE_USER
229−sudo -H usermod -a -G shadow $SERVICE_USER
227+useradd --shell /bin/bash --system \
228+ --home-dir "$SERVICE_HOME" \
229+ --comment 'Web content sanitizer proxy' $SERVICE_USER
230+mkdir "$SERVICE_HOME"
231+chown -R "$SERVICE_GROUP:$SERVICE_GROUP" "$SERVICE_HOME"
230232groups $SERVICE_USER
231233EOF
232234 SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME)"
utils/searx.sh+28−14
@@ -35,14 +35,26 @@ SEARX_UWSGI_APP="searx.ini"
3535# shellcheck disable=SC2034
3636SEARX_UWSGI_SOCKET="/run/uwsgi/app/searx/socket"
3737
38−# FIXME: Arch Linux & RHEL should be added
39−
40−SEARX_APT_PACKAGES="\
41− uwsgi uwsgi-plugin-python3 \
42− git build-essential \
43− libxslt-dev python3-dev python3-babel python3-venv \
44− zlib1g-dev libffi-dev libssl-dev \
45−"
38+case $DIST_ID in
39+ ubuntu|debian) # apt packages
40+ SEARX_PACKAGES="\
41+ python3-dev python3-babel python3-venv \
42+ uwsgi uwsgi-plugin-python3 \
43+ git build-essential libxslt-dev zlib1g-dev libffi-dev libssl-dev "
44+ ;;
45+ arch) # pacman packages
46+ SEARX_PACKAGES="\
47+ python python-pip python-lxml python-babel \
48+ uwsgi uwsgi-plugin-python \
49+ git base-devel libxml2 "
50+ ;;
51+ fedora) # dnf packages
52+ SEARX_PACKAGES="\
53+ python python-pip python-lxml python-babel \
54+ uwsgi uwsgi-plugin-python3 \
55+ git @development-tools libxml2 "
56+ ;;
57+esac
4658
4759# Apache Settings
4860
@@ -72,7 +84,7 @@ usage() {
7284usage::
7385
7486 $(basename "$0") shell
75− $(basename "$0") install [all|user|pyenv|searx-src|apache]
87+ $(basename "$0") install [all|user|searx-src|pyenv|apache]
7688 $(basename "$0") update [searx]
7789 $(basename "$0") remove [all|user|pyenv|searx-src]
7890 $(basename "$0") activate [service]
@@ -120,7 +132,7 @@ main() {
120132 rst_title "$SEARX_INSTANCE_NAME" part
121133
122134 required_commands \
123− dpkg systemctl apt-get install git wget curl \
135+ sudo systemctl install git wget curl \
124136 || exit
125137
126138 local _usage="unknown or missing $1 command $2"
@@ -202,7 +214,7 @@ _service_prefix=" |$SERVICE_USER| "
202214
203215install_all() {
204216 rst_title "Install $SEARX_INSTANCE_NAME (service)"
205− pkg_install "$SEARX_APT_PACKAGES"
217+ pkg_install "$SEARX_PACKAGES"
206218 wait_key
207219 assert_user
208220 wait_key
@@ -260,9 +272,11 @@ assert_user() {
260272 rst_title "user $SERVICE_USER" section
261273 echo
262274 tee_stderr 1 <<EOF | bash | prefix_stdout
263−sudo -H adduser --shell /bin/bash --system --home "$SERVICE_HOME" \
264− --disabled-password --group --gecos 'searx' $SERVICE_USER
265−sudo -H usermod -a -G shadow $SERVICE_USER
275+useradd --shell /bin/bash --system \
276+ --home-dir "$SERVICE_HOME" \
277+ --comment 'Privacy-respecting metasearch engine' $SERVICE_USER
278+mkdir "$SERVICE_HOME"
279+chown -R "$SERVICE_GROUP:$SERVICE_GROUP" "$SERVICE_HOME"
266280groups $SERVICE_USER
267281EOF
268282 #SERVICE_HOME="$(sudo -i -u "$SERVICE_USER" echo \$HOME)"