Manage your machine configuration in a simple bash script.
Quickly bootstrap your personal development machines with box.
The source for this demonstration is here.
You can bootstrap box right into your configuration script.
Place this at the top of the file:
function bootstrap-box () {
local BOX_PATH="/usr/local/share/box/box.sh"
if [ ! -f "$BOX_PATH" ]; then
sudo mkdir -p `dirname "$BOX_PATH"`
sudo wget -O "$BOX_PATH" https://raw.githubusercontent.com/AndrewVos/box/master/box.sh
sudo chmod +x "$BOX_PATH"
fi
source "$BOX_PATH"
}
bootstrap-box
Box allows you to configure a machine by "satisfying" dependencies.
To satisfy an apt dependency, for example, do satisfy apt "package-name"
. This will ensure that the package is installed and is the
latest version.
To execute some code before or after installing a package, use Tasks.
For file and executable tasks, box will execute a
custom function which must do the install.
You must write this function and it must be named install-NAME
.
Whenever box executes an install- function it will cd into a directory inside /tmp, so feel free to have at it with the file system.
satisfy apt "git"
satisfy apt "vim"
satisfy apt-ppa "ppa:peek-developers/stable"
satisfy apt "peek"
satisfy pacman "i3"
satisfy pacman "postgresql"
Install yaourt
:
function install-yaourt () {
git clone https://aur.archlinux.org/package-query.git
cd package-query
makepkg -si
cd ..
git clone https://aur.archlinux.org/yaourt.git
cd yaourt
makepkg -si
cd ..
}
satisfy executable "yaourt"
satisfy yaourt "google-chrome"
satisfy yaourt "spotify"
satisfy deb "slack-desktop" "https://downloads.slack-edge.com/linux_releases/slack-desktop-2.7.1-amd64.deb"
satisfy golang "go1.9"
satisfy go-package "github.com/AndrewVos/pwompt"
satisfy github "https://github.com/AndrewVos/vimfiles" "$HOME/vimfiles"
if did-install; then
cd $HOME/vimfiles
./install.sh
fi
function install-my-file () {
cp file /my/file
}
satisfy file "my-file" "/my/file"
function install-thing () {
sudo wget -O /usr/bin/thing https://example.org/thing
}
satisfy executable "thing"
satisfy symlink "$HOME/dotfiles/bash/.bashrc" "$HOME/.bashrc"
satisfy symlink "$HOME/dotfiles/vim/.vimrc" "$HOME/.vimrc"
satisfy dconf "CMD+SHIFT+s to take an area screenshot" "org.gnome.settings-daemon.plugins.media-keys.area-screenshot-clip" "<Shift><Super>s"
satisfy file-line "Source my aliases" ~/.bashrc "source ~/.my-aliases"
if will-install apt "enpass"; then
sudo echo "deb http://repo.sinew.in/ stable main" > /etc/apt/sources.list.d/enpass.list
wget -O - https://dl.sinew.in/keys/enpass-linux.key | sudo apt-key add -
sudo apt update
fi
if will-upgrade apt "enpass"; then
echo "Upgrading enpass, no further action required"
fi
satisfy apt "enpass"
satisfy apt "vim"
if did-install; then
echo "vim was installed"
fi
if did-upgrade; then
echo "vim was upgraded"
fi
For the obsessive among us, you can wrap sections of your config in section
for some nesting and
a nice label:
section "VIM"
satisfy apt "vim"
satisfy symlink "$HOME/dotfiles/vim/.vimrc" "$HOME/.vimrc"
end-section
This will output something like:
[VIM]
apt vim -> latest
symlink /home/andrewvos/vimfiles/.vimrc -> latest
You can add as many levels of nesting as you see fit. Go wild.