diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..82d6d3d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu + +RUN apt-get update \ + && apt-get install -y sudo locales + +RUN localedef -i en_US -f UTF-8 en_US.UTF-8 \ + && useradd -m -s /bin/bash correl \ + && echo 'correl ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers + +USER correl +WORKDIR /home/correl +COPY . /home/correl/dotfiles +RUN DEBUG=1 /home/correl/dotfiles/provision.sh +CMD ["/bin/bash", "/home/correl/dotfiles/provision.sh"] diff --git a/provision.sh b/provision.sh new file mode 100755 index 0000000..080dd54 --- /dev/null +++ b/provision.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set +e + +function _run { + local msg=$1 + shift + if [ -z "$DEBUG" ]; then + echo -n "$msg..." + $@ 2>&1 >/dev/null + else + echo "$msg..." + $@ + fi + echo "done." +} + +function _recipe { + source ${HOME}/dotfiles/recipes/$1 +} + +USER=${USER:-$(whoami)} +_PLATFORM=$(uname -s | awk '{print tolower($1)}') + +for recipe in base $@; do + _recipe $recipe +done + +echo "Finished, restarting shell." +exec $SHELL diff --git a/recipes/apt b/recipes/apt new file mode 100644 index 0000000..3c4a85e --- /dev/null +++ b/recipes/apt @@ -0,0 +1,15 @@ +#!/bin/bash + +if [ -z "$__apt_updated" ]; then + _run "Update APT cache" sudo apt-get update + __apt_updated=yes +fi + +function _apt { + local pkg=$1 + if ! dpkg -s $pkg >/dev/null 2>&1; then + _run "[apt] Install $pkg" sudo apt-get install -y $1 + else + echo "[apt] $pkg is already installed, skipping." + fi +} diff --git a/recipes/base b/recipes/base new file mode 100644 index 0000000..2981cc4 --- /dev/null +++ b/recipes/base @@ -0,0 +1,6 @@ +#!/bin/bash +set +e + +_recipe brew +_recipe git +_recipe zsh diff --git a/recipes/brew b/recipes/brew new file mode 100644 index 0000000..66d4eae --- /dev/null +++ b/recipes/brew @@ -0,0 +1,35 @@ +#!/bin/bash +set +e + +function __install_brew { + case "$(uname -s)" in + Darwin) + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + ;; + *) + _recipe apt + + for pkg in build-essential curl file git python-setuptools; do + _apt $pkg + done + [ -d ~/.linuxbrew ] || git clone -q https://github.com/Linuxbrew/brew.git ~/.linuxbrew + PATH="$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH" + test -r ~/.bash_profile && echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.bash_profile + echo "export PATH='$(brew --prefix)/bin:$(brew --prefix)/sbin'":'"$PATH"' >>~/.profile + ;; + esac +} + +function _brew { + local pkg=$1 + if ! brew ls $pkg >/dev/null 2>&1; then + _run "[brew] Install $pkg" brew install $@ + else + echo "[brew] $pkg is already installed, skipping." + fi +} + + +if ! which brew >/dev/null; then + _run "Install brew" __install_brew +fi diff --git a/recipes/elm b/recipes/elm new file mode 100644 index 0000000..aedc71e --- /dev/null +++ b/recipes/elm @@ -0,0 +1,5 @@ +#!/bin/bash + +_recipe nvm +_npm elm-oracle +_npm elm-format diff --git a/recipes/emacs b/recipes/emacs new file mode 100644 index 0000000..deb89ab --- /dev/null +++ b/recipes/emacs @@ -0,0 +1,13 @@ +#!/bin/bash +set +e + +_recipe brew + +case $_PLATFORM in + darwin) + _brew emacs --with-cocoa --with-librsvg --with-imagemagick@6 + ;; + linux) + _brew emacs --with-librsvg --with-imagemagick@6 + ;; +esac diff --git a/recipes/git b/recipes/git new file mode 100644 index 0000000..6796ef1 --- /dev/null +++ b/recipes/git @@ -0,0 +1,5 @@ +#!/bin/bash +set +e + +_recipe brew +_brew git diff --git a/recipes/haskell b/recipes/haskell new file mode 100644 index 0000000..1c94d0a --- /dev/null +++ b/recipes/haskell @@ -0,0 +1,3 @@ +#!/bin/bash + +_brew haskell-stack diff --git a/recipes/nvm b/recipes/nvm new file mode 100644 index 0000000..c473054 --- /dev/null +++ b/recipes/nvm @@ -0,0 +1,22 @@ +#!/bin/bash +set +e + +function __install_nvm { + curl -s -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh >/dev/null | bash + source ~/.nvm/nvm.sh + nvm install node 2>/dev/null + nvm alias default node +} + +function _npm { + local pkg=$1 + if ! npm list -g $pkg >/dev/null; then + _run "[npm] Install $pkg" npm install --no-progress -g $@ + else + echo "[npm] $pkg is already installed, skipping." + fi +} + +if ! [ -f ~/.nvm/nvm.sh ]; then + _run "Install nvm" __install_nvm +fi diff --git a/recipes/zsh b/recipes/zsh new file mode 100644 index 0000000..7d677aa --- /dev/null +++ b/recipes/zsh @@ -0,0 +1,29 @@ +#!/bin/bash +set +e + +_recipe brew +_brew zsh + +__zsh_bin="$(which zsh)" +__zsh_files=(.zshrc) + +if ! grep "^$__zsh_bin\$" /etc/shells >/dev/null; then + sudo sh -c "echo $__zsh_bin >> /etc/shells" +fi +case "$(uname -s)" in + Darwin) + __shell=$(dscl . -read /Users/${USER} UserShell | awk '{print $2}') + ;; + *) + __shell=$(getent passwd $USER | cut -d: -f7) + ;; +esac +if [ "$__shell" != "$__zsh_bin" ]; then + echo "Install $__zsh_bin as default shell (currently $__shell)" + sudo chsh -s $__zsh_bin ${USER} +fi +export SHELL=$__zsh_bin + +if ! [ -f ${HOME}/.zshrc ]; then + _run "Install .zshrc" ln -s ${HOME}/dotfiles/.zshrc ${HOME}/.zshrc +fi