From 5fb6d4f508d9744a8d82160ca184729514bc18c8 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 23 Feb 2020 12:10:45 +0100 Subject: [PATCH] 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 --- utils/filtron.sh | 10 +++++---- utils/lib.sh | 57 ++++++++++++++++++++++++++++++++++++++++-------- utils/lxc.sh | 11 +++++++--- utils/morty.sh | 10 +++++---- utils/searx.sh | 42 +++++++++++++++++++++++------------ 5 files changed, 96 insertions(+), 34 deletions(-) diff --git a/utils/filtron.sh b/utils/filtron.sh index 2d227081..ba284787 100755 --- a/utils/filtron.sh +++ b/utils/filtron.sh @@ -106,7 +106,7 @@ main() { rst_title "$SERVICE_NAME" part required_commands \ - dpkg apt-get install git wget curl \ + sudo install git wget curl \ || exit local _usage="unknown or missing $1 command $2" @@ -231,9 +231,11 @@ assert_user() { rst_title "user $SERVICE_USER" section echo tee_stderr 1 < /dev/null - return $? + case $DIST_ID in + ubuntu|debian) + dpkg -l "$1" &> /dev/null + return $? + ;; + arch) + pacman -Qsq "$1" &> /dev/null + return $? + ;; + fedora) + dnf list -q --installed "$1" &> /dev/null + return $? + ;; + esac } # git tooling diff --git a/utils/lxc.sh b/utils/lxc.sh index 08205d37..8020b134 100755 --- a/utils/lxc.sh +++ b/utils/lxc.sh @@ -39,12 +39,15 @@ ubu1904_boilerplate="$ubu1804_boilerplate" # shellcheck disable=SC2034 archlinux_boilerplate=" pacman -Syu --noconfirm -pacman -S --noconfirm git curl wget +pacman -S --noconfirm git curl wget sudo +echo 'Set disable_coredump false' >> /etc/sudo.conf " +# shellcheck disable=SC2034 fedora31_boilerplate=" dnf update -y -dnf install -y git curl wget +dnf install -y git curl wget hostname +echo 'Set disable_coredump false' >> /etc/sudo.conf " REMOTE_IMAGES=() @@ -162,7 +165,9 @@ main() { lxc exec "${i}" -- "$@" exit_val=$? if [[ $exit_val -ne 0 ]]; then - err_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}" + warn_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}" + else + info_msg "[${_BBlue}${i}${_creset}] exit code (${_BRed}${exit_val}${_creset}) from ${_BGreen}${*}${_creset}" fi done ;; diff --git a/utils/morty.sh b/utils/morty.sh index bd4ad590..37ee87ed 100755 --- a/utils/morty.sh +++ b/utils/morty.sh @@ -105,7 +105,7 @@ main() { rst_title "$SERVICE_NAME" part required_commands \ - dpkg apt-get install git wget curl \ + sudo install git wget curl \ || exit local _usage="ERROR: unknown or missing $1 command $2" @@ -224,9 +224,11 @@ assert_user() { rst_title "user $SERVICE_USER" section echo tee_stderr 1 <