Skip to content

Instantly share code, notes, and snippets.

@banister
Created January 12, 2018 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banister/51b7bd1a663b91910e7fdb87a3611fc8 to your computer and use it in GitHub Desktop.
Save banister/51b7bd1a663b91910e7fdb87a3611fc8 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
DROPBOX_TOKEN=
DIR=${1:-~}
RUBY_VERSION=2.5.0
# setup logfile (set to append to log)
exec 4>>"$DIR"/basis.log
setup_git() {
download_file /configfiles/git/dot-gitconfig "$DIR"/.gitconfig
}
wrap_with_messages() {
echo "setting up $1"
setup_$2
echo "finished setting up ${1}!"
}
setup_ssh() {
echo "setting up ssh"
ssh_dir="$DIR"/.ssh
mkdir -p $ssh_dir
download_file /configfiles/ssh-files/id_rsa.pub "${DIR}/.ssh/id_rsa.pub"
download_file /configfiles/ssh-files/id_rsa "${DIR}/.ssh/id_rsa"
chmod 600 ${DIR}/.ssh/id_rsa
echo "finished setting up ssh!"
}
setup_nano() {
echo "setting up nano"
nano_dir="$DIR"/nanorc
git clone https://github.com/nanorc/nanorc.git "$nano_dir" --depth 1
(cd "$nano_dir"; make install >&4 2>&4)
# can't use $DIR as we can't stop make install installing to ~/.nano
backup_file ~/.nanorc
cat "include ~/.nano/syntax/ALL.nanorc" > ~/.nanorc
echo "finished setting up nano"
}
setup_ruby() {
os_name=$(uname -s)
updated_path="PATH=~/.rbenv/bin:$PATH"
case $os_name in
Darwin)
wrap_with_messages homebrew
brew install openssl libyaml libffi
brew install rbenv
create_or_append "$updated_path" ~/.profile
create_or_append "$updated_path" ~/.zshrc
source ~/.zshrc
source ~/.profile
rbenv install 2.4.1
;;
Linux)
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
create_or_append "$updated_path" ~/.profile
create_or_append "$updated_path" ~/.zshrc
create_or_append 'eval "$(rbenv init -)"' ~/.profile
create_or_append 'eval "$(rbenv init -)"' ~/.zshrc
source ~/.zshrc
source ~/.profile
mkdir -p ~/.rbenv/plugins
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
sudo apt-get install gcc-6 autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
rbenv install $RUBY_VERSION
;;
*)
echo "UNSUPPORTED OS VERSION!!! $(uname -s)"
;;
esac
}
download_file() {
# if the destination file already exists, back it up
backup_file "$2"
curl -X -sSL POST https://content.dropboxapi.com/2/files/download \
--header "Authorization: Bearer ${DROPBOX_TOKEN}" \
--header "Dropbox-API-Arg: {\"path\": \"${1}\"}" -o "$2"
}
backup_file() {
if [ -f "$1" ]; then
cp "$1" "$1".bak
fi
}
setup_homebrew() {
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
}
setup_spacemacs() {
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
download_file /configfiles/emacs/dot-spacemacs ~/.spacemacs
}
create_or_append() {
if [ -f "$2" ]; then
echo "$1" >> "$2"
else
echo "$1" > "$2"
fi
}
wrap_with_messages git
wrap_with_messages ssh
wrap_with_messages nano
wrap_with_messages ruby
wrap_with_messages spacemacs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment