From 52ef90ea4580ad35bbe07b3720fb01c6fbcf8df3 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 5 Mar 2015 13:29:14 -0500 Subject: [PATCH] Add interactive prompts --- README.md | 6 +++++- setup.sh | 53 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5f242c2..5878292 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,11 @@ This is my repository of files needed for general setup of my machines. It inclu ## Installation -`curl -L http://git.chrissexton.org/cws/dotfiles/raw/master/setup.sh | bash -s -- -n "<>" -e "<>"` +`bash <( curl -L http://git.chrissexton.org/cws/dotfiles/raw/master/setup.sh)` + +Or if you want to customize without an interactive prompt: + +`bash <(curl -L http://git.chrissexton.org/cws/dotfiles/raw/master/setup.sh) -n "<>" -e "<>" -i` You may customize the irssi configuration with the `server`, `port`, `nick`, and `password` options. Any of these options may be specified by environment variables instead of switches. diff --git a/setup.sh b/setup.sh index 45af3b7..9b0fd77 100644 --- a/setup.sh +++ b/setup.sh @@ -2,12 +2,14 @@ set -o pipefail -[ "$NAME" ] || NAME= -[ "$EMAIL" ] || EMAIL= -[ "$IRCSERVER" ] || IRCSERVER=irc.freenode.net -[ "$IRCPORT" ] || IRCPORT=6667 -[ "$IRCNICK" ] || IRCNICK=coward -[ "$IRCPASS" ] || IRCPASS= +[ "$NAME" ] || NAME= +[ "$EMAIL" ] || EMAIL= +[ "$IRCSET" ] || IRCSET= +[ "$IRCSERVER" ] || IRCSERVER=irc.freenode.net +[ "$IRCPORT" ] || IRCPORT=6667 +[ "$IRCNICK" ] || IRCNICK=coward +[ "$IRCPASS" ] || IRCPASS= +[ "$DOTFILES" ] || DOTFILES="$HOME"/.dotfiles die() { echo "$1" 1>&2 && show_help && [ "$2" ] && [ "$2" -ge 0 ] && exit "$2" || exit 1; } @@ -19,6 +21,7 @@ show_help() { -h, --help # This help message -n, --name # Name for git -e, --email # Email for git + -i, --irssi # Do not prompt for irssi options -s, --server # Server for irssi -p, --port # Port for irssi -N, --nick # Nick for irssi @@ -35,18 +38,37 @@ NARGS=-1; while [ "$#" -ne "$NARGS" ]; do NARGS=$#; case $1 in shift && NAME="$1" && shift; ;; -e|--email) # Email for git shift && EMAIL="$1" && shift; ;; + -i|--irssi) + shift && IRCSET=1 && shift; ;; -s|--server) # server for irssi - shift && IRCSERVER="$1" && shift; ;; + shift && IRCSERVER="$1" && IRCSET=1 && shift; ;; -p|--port) # port for irssi - shift && IRCPORT="$1" && shift; ;; + shift && IRCPORT="$1" && IRCSET=1 && shift; ;; -N|--nick) # nick for irssi - shift && IRCNICK="$1" && shift; ;; + shift && IRCNICK="$1" && IRCSET=1 && shift; ;; -P|--password) # password for irssi - shift && IRCPASS="$1" && shift; ;; + shift && IRCPASS="$1" && IRCSET=1 && shift; ;; esac; done -[ "$NAME" ] || die "You must provide a name!" -[ "$EMAIL" ] || die "You must provide an email!" +if [ ! "$NAME" ]; then + read -e -p "Git author name: " NAME +fi +[ "$NAME" ] || die "You must specify a Git author name" +if [ ! "$EMAIL" ]; then + read -e -p "Git author email: " EMAIL +fi +[ "$EMAIL" ] || die "You must specify a Git author email" +if [ ! "$IRCSET" ]; then + read -e -p "Would you like to set up irssi [Y/n]? " -i"n" yn + case $yn in + [Yy]* ) + read -e -p "irssi server: " -i"irc.freenode.net" IRCSERVER + read -e -p "irssi port: " -i"6667" IRCPORT + read -e -p "irssi nick: " -i"coward" IRCNICK + read -e -p "irssi psasword: " IRCPASS + ;; + esac +fi fn_distro(){ if [ -f /etc/lsb-release ]; then @@ -71,12 +93,11 @@ elif [[ "$UNAMESTR" == 'Darwin' ]]; then true fi -if [ ! -d "$HOME"/.dotfiles ]; then - git clone git@git.chrissexton.org:cws/dotfiles.git "$HOME"/.dotfiles -elif [ ! -d "$HOME"/.dotfiles/files ]; then +if [ ! -d "$DOTFILES" ]; then + git clone git@git.chrissexton.org:cws/dotfiles.git "$DOTFILES" +elif [ ! -d "$DOTFILES"/files ]; then die "You must have a destination for the dotfiles repository!" fi -DOTFILES="$HOME"/.dotfiles cat "$DOTFILES"/files/gitignore_global > "$HOME"/.gitignore_global