mirror of
1
0
Fork 0

Got setup script working

This commit is contained in:
The Aviator 2015-05-31 02:06:00 -04:00
parent 0918b8af1f
commit 8c9a4ecd9e
1 changed files with 87 additions and 38 deletions

View File

@ -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