add --no-modify-config flag to install.sh

pull/810/head
Shingo Kitagawa 2016-11-04 17:42:40 +09:00
parent 7ffb9e2579
commit 00d17ff16a
1 changed files with 40 additions and 37 deletions

View File

@ -9,6 +9,7 @@ function show_usage() {
echo "--help (-h): Display this help message" echo "--help (-h): Display this help message"
echo "--silent (-s): Install default settings without prompting for input"; echo "--silent (-s): Install default settings without prompting for input";
echo "--interactive (-i): Interactively choose plugins" echo "--interactive (-i): Interactively choose plugins"
echo "--no-modify-config (-n): Do not modify existing config file"
exit 0; exit 0;
} }
@ -64,20 +65,22 @@ function backup_new() {
for param in "$@"; do for param in "$@"; do
shift shift
case "$param" in case "$param" in
"--help") set -- "$@" "-h" ;; "--help") set -- "$@" "-h" ;;
"--silent") set -- "$@" "-s" ;; "--silent") set -- "$@" "-s" ;;
"--interactive") set -- "$@" "-i" ;; "--interactive") set -- "$@" "-i" ;;
*) set -- "$@" "$param" "--no-modify-config") set -- "$@" "-n" ;;
*) set -- "$@" "$param"
esac esac
done done
OPTIND=1 OPTIND=1
while getopts "hsi" opt while getopts "hsin" opt
do do
case "$opt" in case "$opt" in
"h") show_usage; exit 0 ;; "h") show_usage; exit 0 ;;
"s") silent=true ;; "s") silent=true ;;
"i") interactive=true ;; "i") interactive=true ;;
"n") no_modify_config=true ;;
"?") show_usage >&2; exit 1 ;; "?") show_usage >&2; exit 1 ;;
esac esac
done done
@ -101,48 +104,48 @@ esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it" echo "Installing bash-it"
if [ -e "$HOME/$BACKUP_FILE" ]; then if ! [[ $silent ]] && ! [[ $no_modify_config ]]; then
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 if [ -e "$HOME/$BACKUP_FILE" ]; then
while ! [ $silent ]; do echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP while ! [ $silent ]; do
case $RESP in read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in
[yY])
break
;;
[nN]|"")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 1
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
while ! [ $silent ]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in
[yY]) [yY])
test -w "$HOME/$CONFIG_FILE" &&
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
break break
;; ;;
[nN]|"") [nN]|"")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" backup_new
exit 1 break
;; ;;
*) *)
echo -e "\033[91mPlease choose y or n.\033[m" echo -e "\033[91mPlease choose y or n.\033[m"
;; ;;
esac esac
done done
fi elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
while ! [ $silent ]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in
[yY])
test -w "$HOME/$CONFIG_FILE" &&
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
break
;;
[nN]|"")
backup_new
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
if [ $silent ]; then
# backup/new by default # backup/new by default
backup_new backup_new
fi fi