1
0
Fork 0
mirror of synced 2024-06-15 21:51:10 -04:00

General restructuring and created flags

This commit is contained in:
The Aviator 2015-06-01 03:02:25 -04:00
parent ed1b4f4bab
commit 8faa2b8e21

View file

@ -1,17 +1,90 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echoerr() { echo "$@" >&2; } 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; testmode=0;
verboseconf=0;
dumpconf=0;
preview=1;
case "$1" in while [ $# -ne 0 ]; do
test) case "$1" in
testmode=1; test)
echoerr "Test mode enabled." testmode=1;
esac 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') 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='' dotclean=''
dotlink='' dotlink=''
dotshell='' dotshell=''
@ -23,6 +96,8 @@ echoerr;
echoerr "At any time, press ^C to quit. No changes will be made until you confirm." echoerr "At any time, press ^C to quit. No changes will be made until you confirm."
echoerr; echoerr;
appendshell start
prefix="~/.dotfiles" prefix="~/.dotfiles"
prefixfull="${prefix/\~/${HOME}}" prefixfull="${prefix/\~/${HOME}}"
@ -33,11 +108,10 @@ else
fi fi
moveon=0; while true; do
until (( $moveon )); do
read -p "Where do you want your dotfiles repository to be? ($prefix) " answer read -p "Where do you want your dotfiles repository to be? ($prefix) " answer
if echo "$answer" | grep -q "^$" ; then if [ -z $answer ]; then
moveon=1 break
else else
echoerr "FEATURE NOT YET SUPPORTED." echoerr "FEATURE NOT YET SUPPORTED."
echoerr "Sorry for misleading you." echoerr "Sorry for misleading you."
@ -45,37 +119,51 @@ until (( $moveon )); do
fi fi
done done
setupshell=$setupshell'; mkdir -p '$prefix'; cd '$prefix'; git init' appendshell mkprefix $prefix
appendshell gitinit
moveon=0; while true; do
until (( $moveon )); do
read -p "Shall we add DotBot as a submodule (a good idea)? (Y/n) " answer 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 if [ -z $answer ]; then
echoerr "Will do." answer='y'
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}"
fi 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 done
moveon=0; while true; do
until (( $moveon )); do
read -p "Do you want DotBot to clean ~/ of broken links added by DotBot? (recommended) (Y/n) " answer 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 if [ -z $answer ]; then
echoerr "I will ask DotBot to clean." answer='y'
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}"
fi 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 done
@ -87,20 +175,25 @@ for item in ${paths[*]}
do do
fullname="${item/\~/$HOME}" fullname="${item/\~/$HOME}"
if [ -f $fullname ] || [ -d $fullname ]; then if [ -f $fullname ] || [ -d $fullname ]; then
moveon=0; while true; do
until (( $moveon )); do
read -p "I found ${item}, do you want to DotBot it? (Y/n) " answer 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 if [ -z $answer ]; then
linksection[$i]=$item; answer='y'
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}"
fi 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 done
fi fi
done done
@ -124,66 +217,97 @@ do
else else
itempath=${itempath:$firstslash}; itempath=${itempath:$firstslash};
fi fi
new_entry=$newline$hspace$item':' nextslash=`expr index "$itempath" /`
new_entry=$new_entry$newline$hspace$hspace'path: '$itempath if [[ $nextslash -gt 0 ]]; then
new_entry=$new_entry$newline$hspace$hspace'create: true' entryisdir='true';
new_entry=$new_entry$newline$hspace$hspace'relink: false' else
new_entry=$new_entry$newline$hspace$hspace'force: false' 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" dotlink="$dotlink$new_entry"
done done
export installconfyaml="$dotclean$newline$newline$dotlink$newline$newline$dotshell" 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; while (( $installerrun )); do
installerrun=1;
until (( $moveon )); do
read -p "Shall I run the installer? (Necessary to git commit) (Y/n) " answer 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 if [ -z $answer ]; then
echoerr "Will do." answer='y'
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 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 done
moveon=0; while (( $installerrun )); do
until (( $moveon )) || ! (( $installerrun )); do
read -p "Shall I make the initial commit? (Y/n) " answer read -p "Shall I make the initial commit? (Y/n) " answer
if echo "$answer" | grep -iq "^y" || echo "$answer" | grep -q "^$" ; then if [ -z $answer ]; then
echoerr "Will do." answer='y'
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 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 done
echoerr; echoerr;
if ! (( $testmode )); then if (( $dumpconf )); then
echo $dotlink echo -e "$dotlink"
echoerr
fi fi
echoerr
echoerr "The below are the actions that will be taken to setup DotBot." echoerr "The below are the actions that will be taken to setup DotBot."
if (( $testmode )); then if (( $testmode )); then
echoerr "Just kidding. They won't be." echoerr "Just kidding. They won't be."
fi 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 if ! (( $testmode )); then
eval $setupshell eval $setupshell