From fe98b44168e7fbc05adcdd6a0c4ef896085f8058 Mon Sep 17 00:00:00 2001 From: Svenum <43136984+Svenum@users.noreply.github.com> Date: Sat, 24 Aug 2024 13:56:35 +0200 Subject: [PATCH] add --no-sudo option (#76) --- install.sh | 24 ++++++++++++++---------- post-install.sh | 20 ++++++++++++-------- pre-uninstall.sh | 19 +++++++++++-------- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/install.sh b/install.sh index 3280d96..4a63e78 100755 --- a/install.sh +++ b/install.sh @@ -1,14 +1,9 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] - then echo "This program requires root permissions" - exit 1 -fi - # Argument parsing SHORT=r,d:,p:,s:,h -LONG=remove,dest-dir:,prefix-dir:,sysconf-dir:,no-ectool,no-pre-uninstall,no-post-install,no-battery-sensors,help +LONG=remove,dest-dir:,prefix-dir:,sysconf-dir:,no-ectool,no-pre-uninstall,no-post-install,no-battery-sensors,no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; @@ -25,6 +20,7 @@ SHOULD_PRE_UNINSTALL=true SHOULD_POST_INSTALL=true SHOULD_REMOVE=false NO_BATTERY_SENSOR=false +NO_SUDO=false eval set -- "$VALID_ARGS" while true; do @@ -56,8 +52,11 @@ while true; do '--no-battery-sensors') NO_BATTERY_SENSOR=true ;; + '--no-sudo') + NO_SUDO=true + ;; '--help' | '-h') - echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install] [--no-pre-uninstall]" 1>&2 + echo "Usage: $0 [--remove,-r] [--dest-dir,-d ] [--prefix-dir,-p ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-ectool] [--no-post-install] [--no-pre-uninstall] [--no-sudo]" 1>&2 exit 0 ;; --) @@ -66,7 +65,12 @@ while true; do esac shift done -# + +# Root check +if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ] + then echo "This program requires root permissions ore use the '--no-sudo' option" + exit 1 +fi SERVICES_DIR="./services" SERVICE_EXTENSION=".service" @@ -93,7 +97,7 @@ function uninstall_legacy() { function uninstall() { if [ "$SHOULD_PRE_UNINSTALL" = true ]; then - ./pre-uninstall.sh + ./pre-uninstall.sh "$([ "$NO_SUDO" = true ] && echo "--no-sudo")" fi # remove program services based on the services present in the './services' folder echo "removing services" @@ -185,7 +189,7 @@ function install() { done done if [ "$SHOULD_POST_INSTALL" = true ]; then - ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" + ./post-install.sh --dest-dir "$DEST_DIR" --sysconf-dir "$SYSCONF_DIR" "$([ "$NO_SUDO" = true ] && echo "--no-sudo")" fi } diff --git a/post-install.sh b/post-install.sh index c92e74a..0a2f252 100755 --- a/post-install.sh +++ b/post-install.sh @@ -1,16 +1,12 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] - then echo "This program requires root permissions" - exit 1 -fi - HOME_DIR="$(eval echo "~$(logname)")" # Argument parsing +NO_SUDO=false SHORT=d:,s:,h -LONG=dest-dir:,sysconf-dir:,help +LONG=dest-dir:,sysconf-dir:,no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; @@ -30,8 +26,11 @@ while true; do SYSCONF_DIR=$2 shift ;; + '--no-sudo') + NO_SUDO=true + ;; '--help' | '-h') - echo "Usage: $0 [--dest-dir,-d ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)]" 1>&2 + echo "Usage: $0 [--dest-dir,-d ] [--sysconf-dir,-s system configuration destination directory (defaults to $SYSCONF_DIR)] [--no-sudo]" 1>&2 exit 0 ;; --) @@ -40,7 +39,12 @@ while true; do esac shift done -# + +# Root check +if [ "$EUID" -ne 0 ] && [ "$NO_SUDO" = false ] + then echo "This program requires root permissions ore use the '--no-sudo' option" + exit 1 +fi SERVICES_DIR="./services" SERVICE_EXTENSION=".service" diff --git a/pre-uninstall.sh b/pre-uninstall.sh index 9ca3953..cc08cc9 100755 --- a/pre-uninstall.sh +++ b/pre-uninstall.sh @@ -1,16 +1,12 @@ #!/bin/bash set -e -if [ "$EUID" -ne 0 ] - then echo "This program requires root permissions" - exit 1 -fi - HOME_DIR="$(eval echo "~$(logname)")" # Argument parsing +NO_SUDO=false SHORT=h -LONG=help +LONG=no-sudo,help VALID_ARGS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@") if [[ $? -ne 0 ]]; then exit 1; @@ -19,8 +15,11 @@ fi eval set -- "$VALID_ARGS" while true; do case "$1" in + '--no-sudo') + NO_SUDO=true + ;; '--help' | '-h') - echo "Usage: $0" 1>&2 + echo "Usage: $0 [--no-sudo]" 1>&2 exit 0 ;; --) @@ -29,7 +28,11 @@ while true; do esac shift done -# + +if [ "$EUID" -ne 0 ] + then echo "This program requires root permissions ore use the '--no-sudo' option" + exit 1 +fi SERVICES_DIR="./services" SERVICE_EXTENSION=".service"