From b96e08bf53b11b325ab86adbabf14a1de1274d65 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Thu, 14 May 2015 19:25:38 -0400 Subject: [PATCH 1/8] Basic start to an easy setup system --- easy_setup.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 easy_setup.sh diff --git a/easy_setup.sh b/easy_setup.sh new file mode 100755 index 0000000..0ceb988 --- /dev/null +++ b/easy_setup.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +paths=('~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2') + +echo "Welcome to the configuration generator for DotBot" +echo "Please be aware that if you have a complicated setup, you may need more customization than this script offers." + + +for item in ${paths[*]} +do + fullname="${item/\~/$HOME}" + if [ -f $fullname ] || [ -d $fullname ]; then + moveon=0; + until [ $moveon -eq 1 ]; do + read -p "I found ${item}, do you want to dotbot it? (Y/n) " answer + if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then + echo "Dotbotted!" + moveon=1 + elif echo "$answer" | grep -iq "^n"; then + echo "Not!" + moveon=1 + else + echo "Answer not understood: ${answer}" + fi + done + fi +done + From 0918b8af1f8b6e07715ede907ae6e829593c3594 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Fri, 15 May 2015 17:21:40 -0400 Subject: [PATCH 2/8] Added more final structure, follows official guide --- easy_setup.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/easy_setup.sh b/easy_setup.sh index 0ceb988..f98869e 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -2,9 +2,79 @@ paths=('~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2') +setupshell='echo "Setting up DotBot. Please do not ^C."' +dotclean='' +dotlink='' +dotshell='' + echo "Welcome to the configuration generator for DotBot" echo "Please be aware that if you have a complicated setup, you may need more customization than this script offers." +echo; +echo "At any time, press ^C to quit. No changes will be made until you confirm." +echo; +prefix="~/.dotfiles" +prefixfull="${prefix/\~/${HOME}}" + +if ! [ -d $prefixfull ]; then + echo "${prefix} is not in use." +else + echo "${prefix} exists and may be in use." +fi + + +moveon=0; +until [ $moveon -eq 1 ]; do + read -p "Where do you want your dotfiles repository to be? (~/.dotfiles) " answer + if echo "$answer" | grep -q "^$" ; then + moveon=1 + else + echo "FEATURE NOT YET SUPPORTED." + echo "Sorry for misleading you." + echo; +# prefix=$answer +# read -p "Press enter to confirm selection, anything else and then enter to try again. " answer +# moveon=(test "${answer}" == "") + fi +done + +setupshell="${setupshell}; mkdir -p ${prefix}; cd ${prefix}" + +moveon=0; +until [ $moveon -eq 1 ]; do + read -p "Shall we add DotBot as a submodule (a good idea)? (Y/n) " answer + if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then + echo "Will do." + setupshell="${setupshell}; git submodule add https://github.com/anishathalye/dotbot; cp dotbot/tools/git-submodule/install ." + moveon=1 + elif echo "$answer" | grep -iq "^n"; then + echo "Okay, I shall not. You will need to manually set up your install script." + moveon=1 + else + echo "Answer not understood: ${answer}" + fi +done + + + +moveon=0; +until [ $moveon -eq 1 ]; do + read -p "Do you want DotBot to clean ~/ of broken links added by DotBot? (recommended) (Y/n) " answer + if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then + echo "I will ask DotBot to clean." + dotclean="- clean: ['~']" + moveon=1 + elif echo "$answer" | grep -iq "^n"; then + echo "Not asking DotBot to clean." + moveon=1 + else + echo "Answer not understood: ${answer}" + fi +done + + +i=0; +declare -a linksection for item in ${paths[*]} do @@ -14,10 +84,12 @@ do until [ $moveon -eq 1 ]; do read -p "I found ${item}, do you want to dotbot it? (Y/n) " answer if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echo "Dotbotted!" + linksection[$i]="${item}"; + i=$i+1 + echo "DotBotted!" moveon=1 elif echo "$answer" | grep -iq "^n"; then - echo "Not!" + echo "Not added to DotBot." moveon=1 else echo "Answer not understood: ${answer}" @@ -26,3 +98,11 @@ do fi done +dotlink="- link:" + +for item in ${linksection[*]} +do + dotlink="${dotlink}"$'\f\r'$item +done + +echo $dotlink From 8c9a4ecd9e45fd9125c4ce8224ddd52cda99679b Mon Sep 17 00:00:00 2001 From: The Aviator Date: Sun, 31 May 2015 02:06:00 -0400 Subject: [PATCH 3/8] Got setup script working --- easy_setup.sh | 125 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 87 insertions(+), 38 deletions(-) diff --git a/easy_setup.sh b/easy_setup.sh index f98869e..b119971 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -1,108 +1,157 @@ #!/usr/bin/env bash +echoerr() { echo "$@" >&2; } paths=('~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2') -setupshell='echo "Setting up DotBot. Please do not ^C."' +setupshell='echo "Setting up DotBot. Please do not ^C." >&2' dotclean='' dotlink='' dotshell='' -echo "Welcome to the configuration generator for DotBot" -echo "Please be aware that if you have a complicated setup, you may need more customization than this script offers." -echo; -echo "At any time, press ^C to quit. No changes will be made until you confirm." -echo; +echoerr "Welcome to the configuration generator for DotBot" +echoerr "Please be aware that if you have a complicated setup, you may need more customization than this script offers." +echoerr; +echoerr "At any time, press ^C to quit. No changes will be made until you confirm." +echoerr; prefix="~/.dotfiles" prefixfull="${prefix/\~/${HOME}}" if ! [ -d $prefixfull ]; then - echo "${prefix} is not in use." + echoerr "${prefix} is not in use." else - echo "${prefix} exists and may be in use." + echoerr "${prefix} exists and may have another purpose than ours." fi moveon=0; -until [ $moveon -eq 1 ]; do - read -p "Where do you want your dotfiles repository to be? (~/.dotfiles) " answer +until (( $moveon )); do + read -p "Where do you want your dotfiles repository to be? ($prefix) " answer if echo "$answer" | grep -q "^$" ; then moveon=1 else - echo "FEATURE NOT YET SUPPORTED." - echo "Sorry for misleading you." - echo; -# prefix=$answer -# read -p "Press enter to confirm selection, anything else and then enter to try again. " answer -# moveon=(test "${answer}" == "") + echoerr "FEATURE NOT YET SUPPORTED." + echoerr "Sorry for misleading you." + echoerr; fi done -setupshell="${setupshell}; mkdir -p ${prefix}; cd ${prefix}" +setupshell=$setupshell'; mkdir -p '$prefix'; cd '$prefix'; git init' moveon=0; -until [ $moveon -eq 1 ]; do +until (( $moveon )); do read -p "Shall we add DotBot as a submodule (a good idea)? (Y/n) " answer if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echo "Will do." - setupshell="${setupshell}; git submodule add https://github.com/anishathalye/dotbot; cp dotbot/tools/git-submodule/install ." + echoerr "Will do." + setupshell=$setupshell'; git submodule add https://github.com/anishathalye/dotbot; cp dotbot/tools/git-submodule/install .' moveon=1 elif echo "$answer" | grep -iq "^n"; then - echo "Okay, I shall not. You will need to manually set up your install script." + echoerr "Okay, I shall not. You will need to manually set up your install script." moveon=1 else - echo "Answer not understood: ${answer}" + echoerr "Answer not understood: ${answer}" fi done - - moveon=0; -until [ $moveon -eq 1 ]; do +until (( $moveon )); do read -p "Do you want DotBot to clean ~/ of broken links added by DotBot? (recommended) (Y/n) " answer if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echo "I will ask DotBot to clean." + echoerr "I will ask DotBot to clean." dotclean="- clean: ['~']" moveon=1 elif echo "$answer" | grep -iq "^n"; then - echo "Not asking DotBot to clean." + echoerr "Not asking DotBot to clean." moveon=1 else - echo "Answer not understood: ${answer}" + echoerr "Answer not understood: ${answer}" fi done -i=0; -declare -a linksection +declare -a linksection; +declare -i i; +echoerr "Going to iterate items" for item in ${paths[*]} do fullname="${item/\~/$HOME}" if [ -f $fullname ] || [ -d $fullname ]; then + echoerr "Found one!" moveon=0; - until [ $moveon -eq 1 ]; do - read -p "I found ${item}, do you want to dotbot it? (Y/n) " answer + until (( $moveon )); do + read -p "I found ${item}, do you want to DotBot it? (Y/n) " answer if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - linksection[$i]="${item}"; + linksection[$i]=$item; i=$i+1 - echo "DotBotted!" + echoerr "DotBotted!" moveon=1 elif echo "$answer" | grep -iq "^n"; then - echo "Not added to DotBot." + echoerr "Not added to DotBot." moveon=1 else - echo "Answer not understood: ${answer}" + echoerr "Answer not understood: ${answer}" fi done fi done -dotlink="- link:" +dotlink='- link:' +newline='\n' +hspace='\x20\x20\x20\x20' for item in ${linksection[*]} do - dotlink="${dotlink}"$'\f\r'$item + fullname="${item/\~/$HOME}" + firstdot=`expr index "$item" .` + firstslash=`expr index "$item" /` + if [ -d $fullname ]; then + itempath=$item'/' + else + itempath=$item + fi + if [[ $firstdot -gt $firstslash ]] ; then + itempath=${itempath:$firstdot}; + else + itempath=${itempath:$firstslash}; + fi + new_entry=$newline$hspace$item':' + new_entry=$new_entry$newline$hspace$hspace'path: '$itempath + new_entry=$new_entry$newline$hspace$hspace'create: true' + new_entry=$new_entry$newline$hspace$hspace'relink: false' + new_entry=$new_entry$newline$hspace$hspace'force: false' + + setupshell=$setupshell'; mkdir -p '$itempath'; rmdir '$itempath'; mv '$item' '$itempath + dotlink="$dotlink$new_entry" done +export installconfyaml="$dotclean$newline$newline$dotlink$newline$newline$dotshell" + +setupshell=$setupshell'; echo -e "'$installconfyaml'" > install.conf.yaml' + + +moveon=0; +until (( $moveon )); do + read -p "Shall I make the initial commit? (Y/n) " answer + if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then + echoerr "Will do." + setupshell=$setupshell'; git add -A; git commit -m "Initial commit"' + moveon=1 + elif echo "$answer" | grep -iq "^n"; then + echoerr "Okay, I shall not. You will need to take care of that yourself." + moveon=1 + else + echoerr "Answer not understood: ${answer}" + fi +done + +echo; echo $dotlink +echo +echo "The below are the actions that will be taken to setup DotBot." + +echoerr $setupshell + +read -p "If you do not see a problem with the above commands, press enter. This is your last chance to press ^C before actions are taken that should not be interrupted. " + +eval $setupshell From ec2c6016ae067cd766e79dac7317172dd9bcc770 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Sun, 31 May 2015 02:16:06 -0400 Subject: [PATCH 4/8] Ensure only yaml config file written to stdout --- easy_setup.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/easy_setup.sh b/easy_setup.sh index b119971..6998312 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -145,10 +145,10 @@ until (( $moveon )); do fi done -echo; +echoerr; echo $dotlink -echo -echo "The below are the actions that will be taken to setup DotBot." +echoerr +echoerr "The below are the actions that will be taken to setup DotBot." echoerr $setupshell From 643e1b955f90ba9c8cf92389469b7fe49ed562c5 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Sun, 31 May 2015 02:22:14 -0400 Subject: [PATCH 5/8] Removed stray debug message --- easy_setup.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/easy_setup.sh b/easy_setup.sh index 6998312..6a3e90f 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -77,7 +77,6 @@ for item in ${paths[*]} do fullname="${item/\~/$HOME}" if [ -f $fullname ] || [ -d $fullname ]; then - echoerr "Found one!" moveon=0; until (( $moveon )); do read -p "I found ${item}, do you want to DotBot it? (Y/n) " answer From e66e2dff8e558bf1dd5472d7cae1e76f6f7cef02 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Sun, 31 May 2015 16:07:49 -0400 Subject: [PATCH 6/8] Added testing mode --- easy_setup.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/easy_setup.sh b/easy_setup.sh index 6a3e90f..2f12337 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -1,6 +1,14 @@ #!/usr/bin/env bash echoerr() { echo "$@" >&2; } +testmode=0; + +case "$1" in + test) + testmode=1; + echoerr "Test mode enabled." +esac + paths=('~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2') setupshell='echo "Setting up DotBot. Please do not ^C." >&2' @@ -145,12 +153,19 @@ until (( $moveon )); do done echoerr; -echo $dotlink +if ! (( $testmode )); then + echo $dotlink +fi echoerr echoerr "The below are the actions that will be taken to setup DotBot." +if (( $testmode )); then + echoerr "Just kidding. They won't be." +fi echoerr $setupshell read -p "If you do not see a problem with the above commands, press enter. This is your last chance to press ^C before actions are taken that should not be interrupted. " -eval $setupshell +if ! (( $testmode )); then + eval $setupshell +fi From ed1b4f4bab7fa380156007e5dc682110300e5715 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Sun, 31 May 2015 16:08:01 -0400 Subject: [PATCH 7/8] Aggressively fixed commit without gitconfig issue --- easy_setup.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/easy_setup.sh b/easy_setup.sh index 2f12337..cb84dd9 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -15,6 +15,7 @@ setupshell='echo "Setting up DotBot. Please do not ^C." >&2' dotclean='' dotlink='' dotshell='' +installerrun=1; echoerr "Welcome to the configuration generator for DotBot" echoerr "Please be aware that if you have a complicated setup, you may need more customization than this script offers." @@ -56,6 +57,7 @@ until (( $moveon )); do elif echo "$answer" | grep -iq "^n"; then echoerr "Okay, I shall not. You will need to manually set up your install script." moveon=1 + installerrun=0; else echoerr "Answer not understood: ${answer}" fi @@ -138,7 +140,24 @@ setupshell=$setupshell'; echo -e "'$installconfyaml'" > install.conf.yaml' moveon=0; +installerrun=1; until (( $moveon )); do + read -p "Shall I run the installer? (Necessary to git commit) (Y/n) " answer + if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then + echoerr "Will do." + setupshell=$setupshell'; ./install' + moveon=1 + elif echo "$answer" | grep -iq "^n"; then + echoerr "Okay, I shall not. You will need to take care of that yourself." + moveon=1 + installerrun=0; + else + echoerr "Answer not understood: ${answer}" + fi +done + +moveon=0; +until (( $moveon )) || ! (( $installerrun )); do read -p "Shall I make the initial commit? (Y/n) " answer if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then echoerr "Will do." From 8faa2b8e218368a6e8c911701ab52c018b9e5e18 Mon Sep 17 00:00:00 2001 From: The Aviator Date: Mon, 1 Jun 2015 03:02:25 -0400 Subject: [PATCH 8/8] General restructuring and created flags --- easy_setup.sh | 288 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 206 insertions(+), 82 deletions(-) diff --git a/easy_setup.sh b/easy_setup.sh index cb84dd9..4bd0329 100755 --- a/easy_setup.sh +++ b/easy_setup.sh @@ -1,17 +1,90 @@ #!/usr/bin/env bash echoerr() { echo "$@" >&2; } +appendshell() { + case "$1" in + start) + add='echo "Setting up DotBot. Please do not ^C." >&2;' + ;; + mkprefix) + add="mkdir -p $2; cd $2;" + ;; + gitinit) + add='git init;' + ;; + gitaddsub) + add='git submodule add https://github.com/anishathalye/dotbot;' + ;; + gitinstallinstall) + add='cp dotbot/tools/git-submodule/install .;' + ;; + ensureparentdirs) + add="mkdir -p $2; rmdir $2;" + ;; + mv) + add="mv $2 $3;" + ;; + echoconfig) + add='echo -e "'$2'" > '$3';' + ;; + runinstaller) + add='./install;' + ;; + gitinitialcommit) + add='git add -A; git commit -m "Initial commit";' + ;; + + esac + setupshell=$setupshell' '$add +} testmode=0; +verboseconf=0; +dumpconf=0; +preview=1; -case "$1" in - test) - testmode=1; - echoerr "Test mode enabled." -esac +while [ $# -ne 0 ]; do + case "$1" in + test) + testmode=1; + echoerr "Test mode enabled." + ;; + no-test) + testmode=0; + echoerr "Test mode disabled." + ;; + verbose-config) + verboseconf=1; + echoerr "Verbose configuration file active." + ;; + no-verbose-config) + verboseconf=0; + echoerr "Concise configuration file active." + ;; + dump-config) + dumpconf=1; + echoerr "Will dump config to stdout." + ;; + no-dump-config) + dumpconf=0; + echoerr "Will not dump config to stdout." + ;; + preview) + preview=1; + echoerr "Will show commands to be executed." + ;; + no-preview) + preview=0; + echoerr "Will not show commands to be executed." + ;; + *) + echoerr "Unfamiliar configuration option" + esac + shift +done paths=('~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2') -setupshell='echo "Setting up DotBot. Please do not ^C." >&2' +setupshell='' dotclean='' dotlink='' dotshell='' @@ -23,6 +96,8 @@ echoerr; echoerr "At any time, press ^C to quit. No changes will be made until you confirm." echoerr; +appendshell start + prefix="~/.dotfiles" prefixfull="${prefix/\~/${HOME}}" @@ -33,11 +108,10 @@ else fi -moveon=0; -until (( $moveon )); do +while true; do read -p "Where do you want your dotfiles repository to be? ($prefix) " answer - if echo "$answer" | grep -q "^$" ; then - moveon=1 + if [ -z $answer ]; then + break else echoerr "FEATURE NOT YET SUPPORTED." echoerr "Sorry for misleading you." @@ -45,37 +119,51 @@ until (( $moveon )); do fi done -setupshell=$setupshell'; mkdir -p '$prefix'; cd '$prefix'; git init' +appendshell mkprefix $prefix +appendshell gitinit -moveon=0; -until (( $moveon )); do +while true; do read -p "Shall we add DotBot as a submodule (a good idea)? (Y/n) " answer - if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echoerr "Will do." - setupshell=$setupshell'; git submodule add https://github.com/anishathalye/dotbot; cp dotbot/tools/git-submodule/install .' - moveon=1 - elif echo "$answer" | grep -iq "^n"; then - echoerr "Okay, I shall not. You will need to manually set up your install script." - moveon=1 - installerrun=0; - else - echoerr "Answer not understood: ${answer}" + if [ -z $answer ]; then + answer='y' fi + case "$answer" in + Y*|y*) + echoerr "Will do." + appendshell gitaddsub + appendshell gitinstallinstall + break + ;; + N*|n*) + echoerr "Okay, I shall not. You will need to manually set up your install script." + installerrun=0; + break + ;; + *) + echoerr "Answer not understood: ${answer}" + ;; + esac done -moveon=0; -until (( $moveon )); do +while true; do read -p "Do you want DotBot to clean ~/ of broken links added by DotBot? (recommended) (Y/n) " answer - if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echoerr "I will ask DotBot to clean." - dotclean="- clean: ['~']" - moveon=1 - elif echo "$answer" | grep -iq "^n"; then - echoerr "Not asking DotBot to clean." - moveon=1 - else - echoerr "Answer not understood: ${answer}" + if [ -z $answer ]; then + answer='y' fi + case "$answer" in + Y*|y*) + echoerr "I will ask DotBot to clean." + dotclean="- clean: ['~']" + break + ;; + N*|n*) + echoerr "Not asking DotBot to clean." + break + ;; + *) + echoerr "Answer not understood: ${answer}" + ;; + esac done @@ -87,20 +175,25 @@ for item in ${paths[*]} do fullname="${item/\~/$HOME}" if [ -f $fullname ] || [ -d $fullname ]; then - moveon=0; - until (( $moveon )); do + while true; do read -p "I found ${item}, do you want to DotBot it? (Y/n) " answer - if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - linksection[$i]=$item; - i=$i+1 - echoerr "DotBotted!" - moveon=1 - elif echo "$answer" | grep -iq "^n"; then - echoerr "Not added to DotBot." - moveon=1 - else - echoerr "Answer not understood: ${answer}" + if [ -z $answer ]; then + answer='y' fi + case "$answer" in + Y*|y*) + linksection[$i]=$item; + i=$i+1 + echoerr "DotBotted!" + break + ;; + N*|n*) + echoerr "Not added to DotBot." + break + ;; + *) + echoerr "Answer not understood: ${answer}" + esac done fi done @@ -124,66 +217,97 @@ do else itempath=${itempath:$firstslash}; fi - new_entry=$newline$hspace$item':' - new_entry=$new_entry$newline$hspace$hspace'path: '$itempath - new_entry=$new_entry$newline$hspace$hspace'create: true' - new_entry=$new_entry$newline$hspace$hspace'relink: false' - new_entry=$new_entry$newline$hspace$hspace'force: false' + nextslash=`expr index "$itempath" /` + if [[ $nextslash -gt 0 ]]; then + entryisdir='true'; + else + entryisdir='false'; + fi + if (( $verboseconf )); then + new_entry=$newline$hspace$item':' + new_entry=$new_entry$newline$hspace$hspace'path: '$itempath + new_entry=$new_entry$newline$hspace$hspace'create: '$entryisdir + new_entry=$new_entry$newline$hspace$hspace'relink: false' + new_entry=$new_entry$newline$hspace$hspace'force: false' + elif [[ $entryisdir = 'false' ]]; then + new_entry=$newline$hspace$item': '$itempath + else + new_entry=$newline$hspace$item':' + new_entry=$new_entry$newline$hspace$hspace'path: '$itempath + new_entry=$new_entry$newline$hspace$hspace'create: '$entryisdir + fi - setupshell=$setupshell'; mkdir -p '$itempath'; rmdir '$itempath'; mv '$item' '$itempath + appendshell ensureparentdirs $itempath; + appendshell mv $item $itempath dotlink="$dotlink$new_entry" done export installconfyaml="$dotclean$newline$newline$dotlink$newline$newline$dotshell" -setupshell=$setupshell'; echo -e "'$installconfyaml'" > install.conf.yaml' +appendshell echoconfig "$installconfyaml" 'install.conf.yaml' -moveon=0; -installerrun=1; -until (( $moveon )); do +while (( $installerrun )); do read -p "Shall I run the installer? (Necessary to git commit) (Y/n) " answer - if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echoerr "Will do." - setupshell=$setupshell'; ./install' - moveon=1 - elif echo "$answer" | grep -iq "^n"; then - echoerr "Okay, I shall not. You will need to take care of that yourself." - moveon=1 - installerrun=0; - else - echoerr "Answer not understood: ${answer}" + if [ -z $answer ]; then + answer='y' fi + case "$answer" in + Y*|y*) + echoerr "Will do." + appendshell runinstaller + break + ;; + N*|n*) + echoerr "Okay, I shall not. You will need to take care of that yourself." + installerrun=0; + break + ;; + *) + echoerr "Answer not understood: ${answer}" + ;; + esac done -moveon=0; -until (( $moveon )) || ! (( $installerrun )); do +while (( $installerrun )); do read -p "Shall I make the initial commit? (Y/n) " answer - if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then - echoerr "Will do." - setupshell=$setupshell'; git add -A; git commit -m "Initial commit"' - moveon=1 - elif echo "$answer" | grep -iq "^n"; then - echoerr "Okay, I shall not. You will need to take care of that yourself." - moveon=1 - else - echoerr "Answer not understood: ${answer}" + if [ -z $answer ]; then + answer='y' fi + case "$answer" in + Y*|y*) + echoerr "Will do." + appendshell gitinitialcommit + break + ;; + N*|n*) + echoerr "Okay, I shall not. You will need to take care of that yourself." + break + ;; + *) + echoerr "Answer not understood: ${answer}" + ;; + esac done echoerr; -if ! (( $testmode )); then - echo $dotlink +if (( $dumpconf )); then + echo -e "$dotlink" + echoerr fi -echoerr echoerr "The below are the actions that will be taken to setup DotBot." if (( $testmode )); then echoerr "Just kidding. They won't be." fi -echoerr $setupshell +if (( $preview )); then + echoerr $setupshell + warningmessage='If you do not see a problem with the above commands, press enter. ' +else + warningmessage='' +fi -read -p "If you do not see a problem with the above commands, press enter. This is your last chance to press ^C before actions are taken that should not be interrupted. " +read -p "${warningmessage}This is your last chance to press ^C before actions are taken that should not be interrupted. " if ! (( $testmode )); then eval $setupshell