#!/usr/bin/env bash playbook_add() { notice "$BASHTARD_PLAYBOOK" "Creating user 'tyil'" useradd \ --no-create-home \ tyil notice "$BASHTARD_PLAYBOOK" "Cloning dotfiles" git clone "$(config "users.tyil.git.url")" "$(config "users.tyil.home")" chown -R tyil:tyil "$(config "users.tyil.home")" playbook_sync } playbook_sync() { local packages=( bash git sudo zsh ) local sharedir="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share" notice "$BASHTARD_PLAYBOOK" "Installing all desired utilities" for package in "${packages[@]}" do pkg install "$package" done if [[ $BASHTARD_COMMAND != "add" ]] then notice "$BASHTARD_PLAYBOOK" "Updating dotfiles" sudo -u tyil \ git -C "$(config "users.tyil.home")" stash sudo -u tyil \ git -C "$(config "users.tyil.home")" pull origin "$(config "users.tyil.git.branch")" sudo -u tyil \ git -C "$(config "users.tyil.home")" stash pop fi notice "$BASHTARD_PLAYBOOK" "Updating all 3rd party git repositories" grep -v '^#' "$sharedir/gittab" | while read -r tab dir do dir="$(config "users.tyil.home")/$dir" grep -v '^#' "$sharedir/gittab.d/$tab" | while read -r name repo branch do notice "$BASHTARD_PLAYBOOK" "Updating $dir/$name" if [[ ! -d "$dir/$name" ]] then sudo -u tyil git clone \ --single-branch \ --branch "$branch" \ --depth 1 \ "$repo" \ "$dir/$name" fi sudo -u tyil git -C "$dir/$name" checkout "$branch" sudo -u tyil git -C "$dir/$name" pull "$repo" "$branch" done done } playbook_del() { userdel tyil rm -fr --one-file-system -- "$(config "users.tyil.home")" }