always request permissions with sudo if needed in install script
This commit is contained in:
parent
9db1deb169
commit
f879aaca4a
1 changed files with 14 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
install_dir="${PREFIX:-/usr/local}/bin"
|
install_dir="${PREFIX:-/usr/local}/bin"
|
||||||
|
@ -17,7 +17,6 @@ usage() {
|
||||||
echo " -d <path>, --dest <path> Set install destination (default /usr/local/bin)"
|
echo " -d <path>, --dest <path> Set install destination (default /usr/local/bin)"
|
||||||
echo " -V, --verify Verify gpg signature"
|
echo " -V, --verify Verify gpg signature"
|
||||||
echo " -l, --local Verify gpg signature with local keychain"
|
echo " -l, --local Verify gpg signature with local keychain"
|
||||||
echo " -s, --sudo Use sudo to request write permission if needed"
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +42,6 @@ while true; do
|
||||||
local=1
|
local=1
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-s | --sudo)
|
|
||||||
use_sudo=1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-h | --help)
|
-h | --help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
@ -65,6 +60,11 @@ while true; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
have_term=0
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
have_term=1
|
||||||
|
fi
|
||||||
|
|
||||||
need_sudo=""
|
need_sudo=""
|
||||||
if [ ! -w "$install_dir" ]; then
|
if [ ! -w "$install_dir" ]; then
|
||||||
need_sudo="$install_dir"
|
need_sudo="$install_dir"
|
||||||
|
@ -82,28 +82,23 @@ if [ -z "$need_sudo" ] && [ -e "$install_dir/f" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$use_sudo" -eq 0 ] && [ -t 0 ] && [ -n "$need_sudo" ]; then
|
if [ "$use_sudo" -eq 0 ] && [ -n "$need_sudo" ]; then
|
||||||
printf "'%s' is not writable. Do you want to install with sudo? [y/N]: " "$need_sudo"
|
printf "%s is not writable. Permissions will be requested with sudo.\n" "$need_sudo"
|
||||||
read -r answer_use_sudo
|
|
||||||
if [ "$answer_use_sudo" = "y" ] || [ "$answer_use_sudo" = "Y" ]; then
|
|
||||||
use_sudo=1
|
use_sudo=1
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
SUDOCMD=""
|
SUDOCMD=""
|
||||||
if [ -n "$need_sudo" ]; then
|
if [ -n "$need_sudo" ]; then
|
||||||
if [ "$use_sudo" -eq 1 ]; then
|
if [ "$use_sudo" -eq 1 ]; then
|
||||||
SUDOCMD=sudo
|
SUDOCMD=sudo
|
||||||
else
|
else
|
||||||
echo "$need_sudo is not writable. Install with the --sudo argument or use a user"
|
echo "error: '$need_sudo' is not writable."
|
||||||
echo "with write permissions."
|
exit 1
|
||||||
echo
|
|
||||||
usage
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# prompt for nightly build option if interactive
|
# prompt for nightly build option if interactive
|
||||||
if [ "$nightly" -eq 0 ] && [ -t 0 ]; then
|
if [ "$nightly" -eq 0 ] && [ "$have_term" -eq 1 ]; then
|
||||||
printf "do you want to install a Nightly build? [y/N]: "
|
printf "do you want to install a Nightly build? [y/N]: "
|
||||||
read -r answer_nightly
|
read -r answer_nightly
|
||||||
if [ "$answer_nightly" = "y" ] || [ "$answer_nightly" = "Y" ]; then
|
if [ "$answer_nightly" = "y" ] || [ "$answer_nightly" = "Y" ]; then
|
||||||
|
@ -111,7 +106,7 @@ if [ "$nightly" -eq 0 ] && [ -t 0 ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$verify" -eq 0 ] && [ -t 0 ]; then
|
if [ "$verify" -eq 0 ] && [ "$have_term" -eq 1 ]; then
|
||||||
printf "do you want to download and verify the gpg signature? [y/N]: "
|
printf "do you want to download and verify the gpg signature? [y/N]: "
|
||||||
read -r answer_verify
|
read -r answer_verify
|
||||||
if [ "$answer_verify" = "y" ] || [ "$answer_verify" = "Y" ]; then
|
if [ "$answer_verify" = "y" ] || [ "$answer_verify" = "Y" ]; then
|
||||||
|
@ -120,7 +115,7 @@ if [ "$verify" -eq 0 ] && [ -t 0 ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! "$(readlink "$install_dir/f")" = "$install_dir/flow" ]; then
|
if [ ! "$(readlink "$install_dir/f")" = "$install_dir/flow" ]; then
|
||||||
if [ -t 0 ] && [ "$add_alias" -eq 0 ]; then
|
if [ "$have_term" -eq 1 ] && [ "$add_alias" -eq 0 ]; then
|
||||||
printf "do you want to create an alias 'f' for 'flow'? [y/N]: "
|
printf "do you want to create an alias 'f' for 'flow'? [y/N]: "
|
||||||
read -r answer_alias
|
read -r answer_alias
|
||||||
if [ "$answer_alias" = "y" ] || [ "$answer_alias" = "Y" ]; then
|
if [ "$answer_alias" = "y" ] || [ "$answer_alias" = "Y" ]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue