2015-03-05 16:54:46 +00:00
#!/bin/bash -e
2015-03-05 17:27:05 +00:00
set -o pipefail
2015-03-05 16:54:46 +00:00
2015-03-05 18:29:14 +00:00
[ " $NAME " ] || NAME =
[ " $EMAIL " ] || EMAIL =
[ " $IRCSET " ] || IRCSET =
[ " $IRCSERVER " ] || IRCSERVER = irc.freenode.net
[ " $IRCPORT " ] || IRCPORT = 6667
[ " $IRCNICK " ] || IRCNICK = coward
[ " $IRCPASS " ] || IRCPASS =
[ " $DOTFILES " ] || DOTFILES = " $HOME " /.dotfiles
2015-03-05 16:54:46 +00:00
2015-03-05 20:02:38 +00:00
if [ [ -f " $DOTFILES " /dotfilesrc ] ] ; then
source " $DOTFILES " /dotfilesrc
fi
2015-03-05 16:54:46 +00:00
die( ) { echo " $1 " 1>& 2 && show_help && [ " $2 " ] && [ " $2 " -ge 0 ] && exit " $2 " || exit 1; }
# Show help function to be used below
show_help( ) {
2015-03-05 17:27:05 +00:00
echo "USAGE: setup.sh [arguments]"
2015-03-05 16:54:46 +00:00
echo "ARGS:"
2015-03-05 17:27:05 +00:00
cat <<HELP
-h, --help # This help message
-n, --name # Name for git
-e, --email # Email for git
2015-03-05 18:29:14 +00:00
-i, --irssi # Do not prompt for irssi options
2015-03-05 17:27:05 +00:00
-s, --server # Server for irssi
2015-03-05 17:42:54 +00:00
-p, --port # Port for irssi
2015-03-05 17:27:05 +00:00
-N, --nick # Nick for irssi
2015-03-05 17:42:54 +00:00
-P, --password # Password for irssi
2015-03-05 17:27:05 +00:00
HELP
2015-03-05 16:54:46 +00:00
}
# Parse command line options (odd formatting to simplify show_help() above)
NARGS = -1; while [ " $# " -ne " $NARGS " ] ; do NARGS = $# ; case $1 in
# SWITCHES
-h| --help) # This help message
show_help; exit 1; ; ;
-n| --name) # Name for git
shift && NAME = " $1 " && shift; ; ;
-e| --email) # Email for git
shift && EMAIL = " $1 " && shift; ; ;
2015-03-05 18:29:14 +00:00
-i| --irssi)
shift && IRCSET = 1 && shift; ; ;
2015-03-05 16:54:46 +00:00
-s| --server) # server for irssi
2015-03-05 18:29:14 +00:00
shift && IRCSERVER = " $1 " && IRCSET = 1 && shift; ; ;
2015-03-05 17:42:54 +00:00
-p| --port) # port for irssi
2015-03-05 18:29:14 +00:00
shift && IRCPORT = " $1 " && IRCSET = 1 && shift; ; ;
2015-03-05 16:54:46 +00:00
-N| --nick) # nick for irssi
2015-03-05 18:29:14 +00:00
shift && IRCNICK = " $1 " && IRCSET = 1 && shift; ; ;
2015-03-05 17:42:54 +00:00
-P| --password) # password for irssi
2015-03-05 18:29:14 +00:00
shift && IRCPASS = " $1 " && IRCSET = 1 && shift; ; ;
2015-03-05 16:54:46 +00:00
esac ; done
2015-03-05 20:02:38 +00:00
if [ [ ! " $NAME " ] ] ; then
read -e -p " Git author name [ $USER ]: " NAME
2015-03-05 18:29:14 +00:00
fi
2015-03-05 20:02:38 +00:00
[ " $NAME " ] || NAME = " $USER "
if [ [ ! " $EMAIL " ] ] ; then
read -e -p " Git author email [ $USER @ $( hostname) ]: " EMAIL
2015-03-05 18:29:14 +00:00
fi
2015-03-05 20:02:38 +00:00
[ " $EMAIL " ] || EMAIL = " $USER @ $( hostname) "
if [ [ ! " $IRCSET " ] ] ; then
read -e -p "Would you like to set up irssi [y/N]? " yn
2015-03-05 18:29:14 +00:00
case $yn in
[ Yy] * )
2015-03-05 20:02:38 +00:00
read -e -p " irssi server [ $IRCSERVER ]: " IRCSERVER
read -e -p " irssi port [ $IRCPORT ]: " IRCPORT
read -e -p " irssi nick [ $IRCNICK ]: " IRCNICK
read -e -p "irssi psasword []: " IRCPASS
2015-03-05 18:29:14 +00:00
; ;
esac
fi
2015-03-05 16:54:46 +00:00
fn_distro( ) {
2015-03-05 20:02:38 +00:00
if [ [ -f /etc/lsb-release ] ] ; then
2015-03-05 16:54:46 +00:00
os = $( lsb_release -s -d)
2015-03-05 20:02:38 +00:00
elif [ [ -f /etc/debian_version ] ] ; then
2015-03-05 16:54:46 +00:00
os = " Debian $( cat /etc/debian_version) "
2015-03-05 20:02:38 +00:00
elif [ [ -f /etc/redhat-release ] ] ; then
2015-03-05 16:54:46 +00:00
os = $( cat /etc/redhat-release)
else
os = " $( uname -s) $( uname -r) "
fi
}
UNAMESTR = $( uname)
if [ [ " $UNAMESTR " = = 'Linux' ] ] ; then
fn_distro
if [ [ " $os " = = Ubuntu* ] ] ; then
sudo apt-get install -y build-essential git irssi vim-nox zsh tmux
2015-03-10 15:58:50 +00:00
[ -d " $HOME " /go ] || curl -L https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | tar -xzC " $HOME "
elif [ [ " $os " = = CentOS* ] ] ; then
sudo yum install -y vim-enhanced zsh git
2015-03-05 16:54:46 +00:00
fi
elif [ [ " $UNAMESTR " = = 'Darwin' ] ] ; then
# Probably need to set up brew and brew install some stuff here...
2015-03-10 15:58:50 +00:00
[ -d " $HOME " /go ] || curl -L https://storage.googleapis.com/golang/go1.4.2.darwin-amd64-osx10.8.tar.gz | tar -xzC " $HOME "
2015-03-05 16:54:46 +00:00
fi
2015-03-10 15:58:50 +00:00
export GOROOT = " $HOME " /go
export GOPATH = $HOME
2015-03-05 20:02:38 +00:00
if [ [ ! -d " $DOTFILES " ] ] ; then
2015-03-10 15:58:50 +00:00
git clone http://git.chrissexton.org/cws/dotfiles.git " $DOTFILES "
2015-03-05 20:02:38 +00:00
elif [ [ ! -d " $DOTFILES " /files ] ] ; then
2015-03-05 17:27:05 +00:00
die "You must have a destination for the dotfiles repository!"
fi
2015-03-05 16:54:46 +00:00
2015-03-05 20:02:38 +00:00
cat >" $DOTFILES " /dotfilesrc <<DOTFILESRC
NAME = " $NAME "
EMAIL = " $EMAIL "
IRCSET = 1
IRCSERVER = " $IRCSERVER "
IRCPORT = " $IRCPORT "
IRCNICK = " $IRCNICK "
IRCPASS = " $IRCPASS "
DOTFILES = " $DOTFILES "
DOTFILESRC
2015-03-05 17:26:59 +00:00
cat " $DOTFILES " /files/gitignore_global > " $HOME " /.gitignore_global
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
<" $DOTFILES " /files/gitconfig sed -e " s/%NAME%/ $NAME / " | sed -e " s/%EMAIL%/ $EMAIL / " > " $HOME " /.gitconfig
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
cat " $DOTFILES " /files/tmux.conf > " $HOME " /.tmux.conf
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
cat " $DOTFILES " /files/vimrc > " $HOME " /.vimrc
2015-03-10 15:58:50 +00:00
if [ [ " $os " = = CentOS* ] ] ; then
sudo ln -s /usr/bin/vim /usr/local/bin/vi
fi
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
if [ [ ! -d " $HOME " /.oh-my-zsh ] ] ; then
2015-03-05 16:54:46 +00:00
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
fi
if [ [ ! " $SHELL " = ~ .*zsh ] ] ; then
2015-03-10 15:58:50 +00:00
if [ [ " $os " = = CentOS* ] ] ; then
chsh -s /bin/zsh
else
chsh -s " $( which zsh) "
fi
2015-03-05 16:54:46 +00:00
fi
2015-03-05 17:26:59 +00:00
cat " $DOTFILES " /files/zshrc > " $HOME " /.zshrc
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
mkdir -p " $HOME " /bin
cat " $DOTFILES " /files/tmux.sh > " $HOME " /bin/tmux.sh
2015-03-05 16:54:46 +00:00
2015-03-05 17:26:59 +00:00
mkdir -p " $HOME " /.irssi
<" $DOTFILES " /files/irssiconfig sed -e " s/%PASSWORD%/ $IRCPASS / " | sed -e " s/%NICK%/ $IRCNICK / " | sed -e " s/%SERVER%/ $IRCSERVER / " | sed -e " s/%PORT%/ $IRCPORT / " > " $HOME " /.irssi/config
2015-03-05 20:02:38 +00:00
if [ [ ! -L " $HOME " /bin/setup.sh ] ] ; then
ln -s " $DOTFILES " /setup.sh " $HOME " /bin
fi