diff --git a/Tips-and-Tricks.md b/Tips-and-Tricks.md index 2407853..3f53cce 100644 --- a/Tips-and-Tricks.md +++ b/Tips-and-Tricks.md @@ -1,7 +1,119 @@ ## How can I have different groups of tasks for different hosts with different configurations? +### Simple setup + See [here](https://github.com/anishathalye/dotbot/pull/11#issuecomment-73082152) for information on using machine-specific configs. +### More advanced setup + +If you want to install programs independently from a general configuration file, the following setup might be for you. + +#### Configurations +Write a configuration file for each program and put them together in a directory: +``` +meta/configs/ +├── bash.yaml +├── git.yaml +├── i3.yaml +└── ... +``` +Then add a basic configuration file (i.e. for cleaning up) at `meta/base.yaml`. + +#### Profiles +Then summarize these configurations in profiles: +``` +meta/profiles/ +├── server +├── workstation +└── ... +``` +In a profile you specify the configurations you want to install (one per line, without `.yaml`). + +#### New `install` scripts +Then replace the `install` script with the following ones: + +##### `install-profile` +```bash +#!/usr/bin/env bash + +set -e + +BASE_CONFIG="base" +CONFIG_SUFFIX=".yaml" + +META_DIR="meta" +CONFIG_DIR="configs" +PROFILES_DIR="profiles" + +DOTBOT_DIR="dotbot" +DOTBOT_BIN="bin/dotbot" + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + +cd "${BASE_DIR}" +git submodule update --init --recursive "${DOTBOT_DIR}" + + +while IFS= read -r config; do + CONFIGS+=" ${config}" +done < "${META_DIR}/${PROFILES_DIR}/$1" + +shift + + +"${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}" + +for config in ${CONFIGS} ${@}; do + echo -e "\nConfigure $config" + "${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "${META_DIR}/${CONFIG_DIR}/${config}${CONFIG_SUFFIX}" +done +``` + +##### `install-standalone` +```bash +#!/usr/bin/env bash + +set -e + +BASE_CONFIG="base" +CONFIG_SUFFIX=".yaml" + +META_DIR="meta" +CONFIG_DIR="configs" +PROFILES_DIR="profiles" + +DOTBOT_DIR="dotbot" +DOTBOT_BIN="bin/dotbot" + +BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + + +cd "${BASE_DIR}" +git submodule update --init --recursive "${DOTBOT_DIR}" + + +"${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "${META_DIR}/${BASE_CONFIG}${CONFIG_SUFFIX}" + +for config in ${@}; do + "${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "${META_DIR}/${CONFIG_DIR}/${config}${CONFIG_SUFFIX}" +done +``` + +Now you should be able to install a profile with +``` +./install-profile [] +``` +and single configurations with +``` +./install-standalone +``` + +If you have any open questions or something is unclear, you can try to take a look at a dotfile repository that uses this setup: +* [vbrandl/dotfiles](https://github.com/vbrandl/dotfiles) +* [vsund/dotfiles](https://github.com/vsund/dotfiles) + + ## Automatically install or update dotfiles when ssh'ing into a remote machine (or: let my dotfiles follow me) Original inspiration: http://klaig.blogspot.co.at/2013/04/make-your-dotfiles-follow-you.html