Add option to install without prompting

This commit is contained in:
Tony Grosinger 2022-05-11 08:02:53 -07:00
parent 3a538461f0
commit 8dc0a4b964

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
################################################################################ ################################################################################
#Copyright (C) 2013 Tony Grosinger. All rights reserved. #Copyright (C) 2022 Tony Grosinger. All rights reserved.
# #
#Description: #Description:
# This script can be run in two modes depending on the file structure of the # This script can be run in two modes depending on the file structure of the
@ -34,14 +34,14 @@ fi
# Define functions # 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() { 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() { 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. # Create a directory named by first parameter. Delete directory first if it already exists.
@ -69,7 +69,6 @@ function performSetup() {
echo "Linking shell configs..." echo "Linking shell configs..."
linkFile ".bashrc" linkFile ".bashrc"
ln -fns ${REPO_DIR}/.bashrc .zshrc
echo "Linking vim..." echo "Linking vim..."
linkFile ".vim" linkFile ".vim"
@ -111,11 +110,11 @@ function performSetup() {
# Initialize (Determine mode) # Initialize (Determine mode)
################################################################################ ################################################################################
# Determine which mode we are running in. (Is the file in the current directory?) # Determine which mode we are running in. (Does the install script exist in the dotfiles directory?)
if [ -f install.sh ]; then if [ -f ${DOTFILES_DIR}/install.sh ]; then
echo "Running in Mode 1: Already cloned repository" echo "Running in Mode 1: Already cloned repository"
REPO_DIR="$( cd "$( dirname "$0" )" && pwd )"
if [ "${1}" != "-y" ]; then
echo "This will create symlinks and destroy any conflicting configs already in place."; echo "This will create symlinks and destroy any conflicting configs already in place.";
read -p "Continue? [y/N] " choice read -p "Continue? [y/N] " choice
@ -127,6 +126,10 @@ if [ -f install.sh ]; then
;; ;;
* ) echo "Aborted!";; * ) echo "Aborted!";;
esac esac
else
performSetup ${HOME}
echo "Done! Restart your shell to see changes"
fi
else else
echo "Running in Mode 2: Direct from Curl" echo "Running in Mode 2: Direct from Curl"
@ -163,7 +166,6 @@ else
curl -L ${REPO_TAR} | tar zx --strip 1 --directory ${DOTFILES_DIR} curl -L ${REPO_TAR} | tar zx --strip 1 --directory ${DOTFILES_DIR}
fi fi
REPO_DIR="${DOTFILES_DIR}"
performSetup ${HOME} performSetup ${HOME}
echo "Done! Restart your shell to see changes" echo "Done! Restart your shell to see changes"
fi fi