Add provisioning scripts

This commit is contained in:
Correl Roush 2018-02-21 23:15:49 -05:00
parent 6750387219
commit d699950ad3
11 changed files with 176 additions and 0 deletions

14
Dockerfile Normal file
View file

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

29
provision.sh Executable file
View file

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

15
recipes/apt Normal file
View file

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

6
recipes/base Normal file
View file

@ -0,0 +1,6 @@
#!/bin/bash
set +e
_recipe brew
_recipe git
_recipe zsh

35
recipes/brew Normal file
View file

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

5
recipes/elm Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
_recipe nvm
_npm elm-oracle
_npm elm-format

13
recipes/emacs Normal file
View file

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

5
recipes/git Normal file
View file

@ -0,0 +1,5 @@
#!/bin/bash
set +e
_recipe brew
_brew git

3
recipes/haskell Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
_brew haskell-stack

22
recipes/nvm Normal file
View file

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

29
recipes/zsh Normal file
View file

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