diff options
author | Karel Kočí <karel.koci@nic.cz> | 2017-07-21 14:58:13 +0200 |
---|---|---|
committer | Karel Kočí <karel.koci@nic.cz> | 2017-07-21 14:58:13 +0200 |
commit | 65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3 (patch) | |
tree | 31b650900406fd2f8f2b474a0806e35a95190c26 /run.sh | |
download | multiconfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.tar.gz multiconfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.tar.bz2 multiconfig-65f52ead41dc6df73671ddd3a8c6a2edecb6dfb3.zip |
Initial base files ... more to come
Diffstat (limited to 'run.sh')
-rwxr-xr-x | run.sh | 87 |
1 files changed, 87 insertions, 0 deletions
@@ -0,0 +1,87 @@ +#!/bin/sh +set -e + +# Go to root directory +cd "$(dirname $0)" +# Include utilities +. utils/echo + +REQ_OPS= + +while [ $# -gt 0 ]; do + case "$1" in + -h|--help) + # TODO + ;; + --verbose|-v) + echo_verbose + 1 + ;; + --quiet|-q) + echo_verbose - 1 + ;; + --operation|-o) + shift + REQ_OPS="$REQ_OPS $1" + ;; + --key) + KEY_FILE="" + ;; + esac + shift +done + +# Load host configuration +[ -f hosts/"$(hostname)" ] || echo_die "No configuration for host $(hostname) found." +. hosts/"$(hostname)" + +# Run system sanity checks +. utils/syscheck +# Identify some variables from system +. utils/identify + +# Include enabled operations +for OPT in $OPERATIONS; do + if [ -f ops/"$OPT" ]; then + . ops/"$OPT" + else + echo_die "No operation $OPT." + fi +done + +# TODO do we want to have some explicit sorting? + +# Check if operations need some update +if [ -z "$REQ_OPS" ]; then + for OPT in $OPERATIONS; do + if ! "$OPT"_check; then + echo_info "Scheduled: $OPT" + REQ_OPS="$REQ_OPS $OPT" + fi + done +fi +if [ -z "$REQ_OPS" ]; then + echo_info "All operations are in check." + exit +fi + +# Run preparations +for OPT in $REQ_OPS; do + if "$OPT"_prepare; then + PREP_OPS="$PREP_OPS $OPT" + else + echo_error "Preparation failed for $OPT. Skipping." + fi +done + +# Now apply operations +for OPT in $PREP_OPS; do + if ! "$OPT"_apply; then + echo_error "Operation $OPT application failed! Please check what happened." + break + fi +done + +# And at the end run cleanups on all operations we ever executed +for OPT in $REQ_OPS; do + "$OPT"_clean || echo_warn "Cleanup of operation $OPT failed." +done |