From e774d6cbedd15d34d84e1a390d959cc55809de74 Mon Sep 17 00:00:00 2001 From: Tristan Williams Date: Sun, 13 Oct 2024 12:43:03 -0400 Subject: Make messages from installer consistent and pleasing --- new-user-setup.sh | 62 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 20 deletions(-) (limited to 'new-user-setup.sh') diff --git a/new-user-setup.sh b/new-user-setup.sh index 2f4ded8..7b8dbe1 100755 --- a/new-user-setup.sh +++ b/new-user-setup.sh @@ -12,6 +12,21 @@ # should be cloned and run this way for every new user. +# Messages passed to the user by this script are in 8-char columns. +#Created: +#Removed: +#Moved : +#Skipped: +# +#ERROR : +#WARNING: +#INFO : +# +#File : +#Dir : +#Symlink: + + ######################################################################## ## Setup ######################################################################## @@ -26,51 +41,58 @@ ENDCOLOR="\e[0m" # Startup message -echo "" echo "### Starting dotfiles.core installation... ###" ######################################################################## ## Put files into place ######################################################################## + # File placement function place_file () { file=$1 target=$2 if [[ -e $target ]]; then - echo -e "\n${WARN}WARNING: ${target} already exists!${ENDCOLOR}" + echo -e \ + "${WARN}WARNING: File : ${target} already exists!" \ + "[A]bort, [D]elete, [R]eplace, [S]kip: ${ENDCOLOR}" invalid_selection=0 while - read -p "[A]bort, [D]elete, [R]eplace, [S]kip: " -n1 selection - echo "" + # The following echo fixes read's annoying newline that + # messes up my nice script formatting. It sends cursor back + # to the "target already exists" line. + # \033[1A moves up to previous line. + # \033[1000C moves to the last column in the line up to 1000. + echo -en "\033[1A\033[1000C" + read -n1 selection case $selection in "a"|"A") - echo "Abort!" + echo "INFO : Abort!" exit 0;; "d"|"D") rm -fv $target - echo -e "${YELLOW}Removed ${target}${ENDCOLOR}" + echo -e "${YELLOW}Removed: File : ${target}${ENDCOLOR}" ln -s $file $target - echo -e "${GREEN}Created: ${target} -> ${file}${ENDCOLOR}" + echo -e "${GREEN}Created: Symlink: ${target} -> ${file}${ENDCOLOR}" return 0;; "r"|"R") - mv -f $target $target.bak & \ - echo -e "${YELLOW}Moved: ${target} to ${target}.bak${ENDCOLOR}" - ln -s $file $target & \ - echo -e "${GREEN}Created: ${target} -> ${file}${ENDCOLOR}" + mv -f $target $target.bak + echo -e "${YELLOW}Moved : File : ${target} to ${target}.bak${ENDCOLOR}" + ln -s $file $target + echo -e "${GREEN}Created: Symlink: ${target} -> ${file}${ENDCOLOR}" return 0;; "s"|"S") - echo -e "${YELLOW}Skipping ${target}${ENDCOLOR}" + echo -e "${YELLOW}Skipped: File : ${target}${ENDCOLOR}" return 0;; *) - echo -e "${WARN}Invalid selection, try again...${ENDCOLOR}" + echo -e "${WARN}ERROR : Invalid selection, try again...${ENDCOLOR}" invalid_selection=1;; esac [[ $invalid_selection==1 ]] do true; done else ln -s $file $target - echo -e "\n${GREEN}Created: ${target} -> ${file}${ENDCOLOR}" + echo -e "${GREEN}Created: File : ${target} -> ${file}${ENDCOLOR}" fi } @@ -78,10 +100,10 @@ place_file () { place_directory () { directory=$1 if [[ -d $directory ]]; then - echo -e "${YELLOW}${directory} already exists.${ENDCOLOR}" + echo -e "${YELLOW}Skipped: Dir : ${directory}${ENDCOLOR}" else - mkdir -p $directory & \ - echo -e "${GREEN}Created: ${directory}${ENDCOLOR}" + mkdir -p $directory + echo -e "${GREEN}Created: Dir : ${directory}${ENDCOLOR}" fi } @@ -91,11 +113,11 @@ place_file $HOME/dotfiles.core/home/.bashrc $HOME/.bashrc place_file $HOME/dotfiles.core/home/.bash_aliases $HOME/.bash_aliases # GPG Configuration -place_directory $HOME/.gnupg & \ - place_file $HOME/dotfiles.core/home/.gnupg/gpg-agent.conf $HOME/.gnupg/gpg-agent.conf +place_directory $HOME/.gnupg/ +place_file $HOME/dotfiles.core/home/.gnupg/gpg-agent.conf $HOME/.gnupg/gpg-agent.conf ######################################################################## ## END OF SCRIPT ######################################################################## -echo -e "\nInstallation completed: dotfiles.core\n" +echo -e "INFO : Installation completed: dotfiles.core" -- cgit v1.2.3