Clean up sudo usage a bit

This commit is contained in:
Alex Malinovich 2016-11-20 02:31:14 -08:00
commit 1d9e15d7a4

View file

@ -22,8 +22,6 @@ install() {
fi fi
if [ $EUID != 0 ]; then if [ $EUID != 0 ]; then
echo "You don't have permissions to continue, trying sudo instead..."
sleep 1
sudo $DISTRO_INSTALL sudo $DISTRO_INSTALL
else else
$DISTRO_INSTALL $DISTRO_INSTALL
@ -171,6 +169,12 @@ save_config() {
echo "done" echo "done"
} }
if [ $EUID -ne 0 ]; then
echo
echo "This script needs to be run with root/sudo, but you are running as '$(whoami)'. Enabling sudo."
sudo -v
fi
if [ -f /etc/redhat-release ]; then if [ -f /etc/redhat-release ]; then
REDHAT=true REDHAT=true
else else
@ -189,13 +193,12 @@ read -e -p "Directory to install into: " -i "/opt/plexupdate" FULL_PATH
if [ ! -d "$FULL_PATH" ]; then if [ ! -d "$FULL_PATH" ]; then
echo -n "'$FULL_PATH' doesn't exist, attempting to create... " echo -n "'$FULL_PATH' doesn't exist, attempting to create... "
if ! mkdir -p "$FULL_PATH" 2>/dev/null; then if ! mkdir -p "$FULL_PATH" 2>/dev/null; then
echo "trying with sudo... "
sudo mkdir -p "$FULL_PATH" || abort "failed, cannot continue" sudo mkdir -p "$FULL_PATH" || abort "failed, cannot continue"
sudo chown $(whoami) "$FULL_PATH" || abort "failed, cannot continue" sudo chown $(whoami) "$FULL_PATH" || abort "failed, cannot continue"
fi fi
echo "done" echo "done"
elif [ ! -w "$FULL_PATH" ]; then elif [ ! -w "$FULL_PATH" ]; then
echo -n "'$FULL_PATH' exists, but you don't have permission to write to it. Changing owner with sudo... " echo -n "'$FULL_PATH' exists, but you don't have permission to write to it. Changing owner... "
sudo chown $(whoami) "$FULL_PATH" || abort "failed, cannot continue" sudo chown $(whoami) "$FULL_PATH" || abort "failed, cannot continue"
echo "done" echo "done"
fi fi