From aa6c00b0835847fea53b299b3302e8d470c79297 Mon Sep 17 00:00:00 2001 From: Felipe Conti Date: Sun, 10 Jun 2018 14:02:42 -0300 Subject: [PATCH 1/3] Treatment to use root --- install.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 884e1a6..a377972 100755 --- a/install.sh +++ b/install.sh @@ -28,6 +28,18 @@ case $KERNEL in ;; esac +sh_c='sh -c' +if [ "$CURRENT_USER" != 'root' ]; then + if command_exists sudo; then + sh_c='sudo -E sh -c' + elif command_exists su; then + sh_c='su -c' + else + output "Error: this installer needs the ability to run commands as root. We are unable to find either "sudo" or "su" available to make this happen." + exit 1 + fi +fi + TMP=$(mktemp -d "${TMPDIR:-/tmp}/ctop.XXXXX") cd ${TMP} @@ -54,7 +66,7 @@ wget -q --show-progress $url (sha256sum -c --quiet --ignore-missing sha256sums.txt) || exit 1 output "installing to /usr/local/bin" -chmod +x ctop-* -sudo mv ctop-* /usr/local/bin/ctop +$sh_c "chmod +x ctop-*" +$sh_c "mv ctop-* /usr/local/bin/ctop" output "done!" From c786b697bf71066b54fa58c1626317ff18515ff0 Mon Sep 17 00:00:00 2001 From: Felipe Conti Date: Sun, 10 Jun 2018 14:04:34 -0300 Subject: [PATCH 2/3] Add function command_exists --- install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/install.sh b/install.sh index a377972..31e83aa 100755 --- a/install.sh +++ b/install.sh @@ -5,6 +5,10 @@ KERNEL=$(uname -s) function output() { echo -e "\033[32mctop-install\033[0m $@"; } +function command_exists() { + command -v "$@" > /dev/null 2>&1 +} + # extract github download url matching pattern function extract_url() { match=$1; shift From 541fe70b78fb77dffaba4cca3ce5af5e79ca5424 Mon Sep 17 00:00:00 2001 From: "Felipe B. Conti" Date: Sun, 10 Jun 2018 14:12:07 -0300 Subject: [PATCH 3/3] Remove unnecessary treatment --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 31e83aa..e77bbda 100755 --- a/install.sh +++ b/install.sh @@ -70,7 +70,7 @@ wget -q --show-progress $url (sha256sum -c --quiet --ignore-missing sha256sums.txt) || exit 1 output "installing to /usr/local/bin" -$sh_c "chmod +x ctop-*" +chmod +x ctop-* $sh_c "mv ctop-* /usr/local/bin/ctop" output "done!"