From 7001888437ae1c708874a2d34d69323b15053b33 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 24 Mar 2021 09:47:22 +0100 Subject: [PATCH] [bug] unable to run the setup script if sudoers belong to another group than sudo --- CHANGELOG.md | 1 + setup/setup.sh | 64 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6ab44c1..2a8122c25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Fix a bug: recurring availabilities are not restricted to subscribers - Fix a bug: accounting exports may ignore some invoices for the first and last days - Fix a bug: accounting export caching is not working +- Fix a bug: unable to run the setup script if sudoers belong to another group than sudo - Fix a security issue: updated elliptic to 6.5.4 to fix [CVE-2020-28498](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28498) - [TODO DEPLOY] `\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/scripts/nginx-packs-directive.sh | bash` - [TODO DEPLOY] `rails db:seed` diff --git a/setup/setup.sh b/setup/setup.sh index 17aad2a7c..d8c12fdc9 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -26,12 +26,16 @@ welcome_message() system_requirements() { - if [ "$(whoami)" = "root" ]; then + if is_root; then echo "It is not recommended to run this script as root. As a normal user, elevation will be prompted if needed." read -rp "Continue anyway? (Y/n) " confirm &1) + if [ $? -eq 0 ]; then + echo "has_sudo__pass_set" + elif echo $prompt | grep -q '^sudo:'; then + echo "has_sudo__needs_pass" + else + echo "no_sudo" + fi +} + +elevate_cmd() +{ + local cmd=$@ + + HAS_SUDO=$(has_sudo) + + case "$HAS_SUDO" in + has_sudo__pass_set) + sudo $cmd + ;; + has_sudo__needs_pass) + echo "Please supply sudo password for the following command: sudo $cmd" + sudo $cmd + ;; + *) + echo "Please supply root password for the following command: su -c \"$cmd\"" + su -c "$cmd" + ;; + esac +} + read_email() { local email @@ -113,8 +157,8 @@ prepare_files() read -rp "Continue? (Y/n) " confirm