From 8dc0a4b96408a341f221847e82a72c2eb2238252 Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Wed, 11 May 2022 08:02:53 -0700 Subject: [PATCH] Add option to install without prompting --- install.sh | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/install.sh b/install.sh index c473c98..a1a1a2a 100755 --- a/install.sh +++ b/install.sh @@ -1,7 +1,7 @@ #!/bin/bash ################################################################################ -#Copyright (C) 2013 Tony Grosinger. All rights reserved. +#Copyright (C) 2022 Tony Grosinger. All rights reserved. # #Description: # This script can be run in two modes depending on the file structure of the @@ -34,14 +34,14 @@ fi # Define functions ################################################################################ -# Remove a file if it exists then create a symlink to the one contained in ${REPO_DIR} +# Remove a file if it exists then create a symlink to the one contained in ${DOTFILES_DIR} function linkFile() { - ln -fns ${REPO_DIR}/$1 $1; + ln -fns ${DOTFILES_DIR}/$1 $1; } -# Remove a file if it exists then create a symlink from the file in $HOME/bin to the one contained in ${REPO_DIR} +# Remove a file if it exists then create a symlink from the file in $HOME/bin to the one contained in ${DOTFILES_DIR} function linkBin() { - ln -fns ${REPO_DIR}/$1 $HOME/bin/$2; + ln -fns ${DOTFILES_DIR}/$1 $HOME/bin/$2; } # Create a directory named by first parameter. Delete directory first if it already exists. @@ -69,7 +69,6 @@ function performSetup() { echo "Linking shell configs..." linkFile ".bashrc" - ln -fns ${REPO_DIR}/.bashrc .zshrc echo "Linking vim..." linkFile ".vim" @@ -111,22 +110,26 @@ function performSetup() { # Initialize (Determine mode) ################################################################################ -# Determine which mode we are running in. (Is the file in the current directory?) -if [ -f install.sh ]; then +# Determine which mode we are running in. (Does the install script exist in the dotfiles directory?) +if [ -f ${DOTFILES_DIR}/install.sh ]; then echo "Running in Mode 1: Already cloned repository" - REPO_DIR="$( cd "$( dirname "$0" )" && pwd )" - echo "This will create symlinks and destroy any conflicting configs already in place."; - read -p "Continue? [y/N] " choice + if [ "${1}" != "-y" ]; then + echo "This will create symlinks and destroy any conflicting configs already in place."; + read -p "Continue? [y/N] " choice - # Perform the logic - case "$choice" in - Y|y|yes ) - performSetup ${HOME} - echo "Done! Restart your shell to see changes" - ;; - * ) echo "Aborted!";; - esac + # Perform the logic + case "$choice" in + Y|y|yes ) + performSetup ${HOME} + echo "Done! Restart your shell to see changes" + ;; + * ) echo "Aborted!";; + esac + else + performSetup ${HOME} + echo "Done! Restart your shell to see changes" + fi else echo "Running in Mode 2: Direct from Curl" @@ -163,7 +166,6 @@ else curl -L ${REPO_TAR} | tar zx --strip 1 --directory ${DOTFILES_DIR} fi - REPO_DIR="${DOTFILES_DIR}" performSetup ${HOME} echo "Done! Restart your shell to see changes" fi