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
################################################################################
#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,11 +110,11 @@ 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 )"
if [ "${1}" != "-y" ]; then
echo "This will create symlinks and destroy any conflicting configs already in place.";
read -p "Continue? [y/N] " choice
@ -127,6 +126,10 @@ if [ -f install.sh ]; then
;;
* ) 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