aboutsummaryrefslogtreecommitdiff
path: root/boxconf
blob: c1fdf89a0ba8188680ebac04128766e72b4ac411 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
#
# Shell-based configuration management framework for unix-like systems.

set -eu

PROGNAME=boxconf
USAGE="${PROGNAME} [-d] [-s SSH_HOST] [-e VAR=VALUE]... HOSTNAME"
BOXCONF_ROOT=$(dirname "$(readlink -f "$0")")

usage(){
  [ $# -gt 0 ] && printf '%s\n' "$1" 2>&1
  printf 'usage: %s\n' "$USAGE" 2>&1
  exit 2
}

while getopts :hde:s:X _bc_opt; do
  case $_bc_opt in
    h) usage ;;
    d) set -x ;;
    e) eval "$OPTARG" ;;
    s) BOXCONF_SSH_HOST=$OPTARG ;;
    X) _bc_run=1 ;;
    :) usage "missing option value: -${OPTARG}" ;;
    ?) usage "unknown option: -${OPTARG}" ;;
  esac
done

[ $(( OPTIND - $# )) -eq 0 ] || usage
eval "BOXCONF_HOSTNAME=\$$#"

for _bc_lib in "${BOXCONF_ROOT}/lib"/*; do
  . "$_bc_lib"
done

if [ -n "${_bc_run:-}" ]; then
  _boxconf_run
else
  _boxconf_deploy "${BOXCONF_SSH_HOST:-$BOXCONF_HOSTNAME}" "$BOXCONF_HOSTNAME" "$@"
fi