Skip to content

Commit

Permalink
Merge pull request #23 from MattSurabian/sudoless-install
Browse files Browse the repository at this point in the history
Sudoless install
  • Loading branch information
MattSurabian committed Nov 14, 2015
2 parents 0dae9be + 9d5da07 commit 88a1acd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ systemInstallPath="/usr/local/bin";
executableSystemInstallPath="$systemInstallPath/$executableFileName";
CREDS_FILE="login.conf";
systemCredsFilePath="$CONF_BASE_PATH/$CREDS_FILE";
configOnly="false"

# Source: https://gist.github.com/hoylen/6607180
PROG="$(basename "$0")";
Expand All @@ -22,16 +23,20 @@ VERSION="0.2";

HELP_TEXT="Usage: $PROG [options]
Options:
-f | --force Allow overwriting existing files on system if they already exist. Useful for at least updating login info, and for also restoring program defaults.
-s | --symlink Install the main program executable as a link to the original contained within this project, rather than copying it over into the system directory. This may allow for simply updating the main project via source control, but be aware that changing its location may break the symlink, and would require re-installation.
-h | --help show this help message";
-f | --force Allow overwriting existing files on system if they already exist. Useful for at least updating login info, and for also restoring program defaults.
-s | --symlink Install the main program executable as a link to the original contained within this project, rather than copying it over into the system directory. This may allow for simply updating the main project via source control, but be aware that changing its location may break the symlink, and would require re-installation.
-c | --configuration Skip adding the script to the user's PATH and just create proxpn configuration files.
-h | --help show this help message";

while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
echo "$HELP_TEXT";
exit 0;
;;
-c | --configuration)
configOnly="true"
;;
-s | --symlink)
symlinkToMainExecutable="true";
;;
Expand All @@ -46,6 +51,13 @@ while [ $# -gt 0 ]; do
shift
done

if [ $EUID != 0 -a $configOnly != true ]; then
echo "This script must be run as root in order to copy the script to $systemInstallPath."
echo "Falling back to configuration only mode. You must re-run this script with sudo or manually copy the proxpn script into your PATH before using the proxpn command."
echo
configOnly="true"
fi

[[ -z "$overwriteFiles" ]] && overwriteFiles="false";
[[ -z "$symlinkToMainExecutable" ]] && symlinkToMainExecutable="false";

Expand Down Expand Up @@ -74,6 +86,8 @@ fi
## Install system-wide program link, if not already installed.
if [[ -f "$executableSystemInstallPath" && ! "$overwriteFiles" == "true" ]]; then
echo "System-wide program link already exists; continuing installation...";
elif [ $configOnly == "true" ]; then
echo "Operating in configuration only mode. Skipping system-wide progam linking..."
elif [[ -f "$executableFilePath" ]]; then
if [[ -f "$executableSystemInstallPath" ]]; then
rm "$executableSystemInstallPath";
Expand Down

0 comments on commit 88a1acd

Please sign in to comment.