#! /bin/sh set -efu self=$(readlink -f "$0") basename=${0##*/} prefix=${self%/bin/*} libdir=$prefix/lib debug=false force=false origin_host=${HOSTNAME-cat /proc/sys/kernel/hostname} origin_user=$LOGNAME target_spec= fail=true error() { echo "$basename: error: $1" >&2 fail=false } for arg; do case $arg in --debug) debug=true ;; --force) force=true ;; -*) error "bad argument: $arg" ;; *) if test -n "$target_spec"; then error "bad argument: $arg" else target_spec=$arg fi ;; esac done if test -z "$target_spec"; then error 'no target specified' fi if test "$fail" != true; then exit 11 fi script=$(jq -e -r \ --argjson use_force "$force" \ --arg target_spec "$target_spec" \ --arg origin_host "$origin_host" \ --arg origin_user "$origin_user" \ -f "$libdir/populate.jq") if test -z "$script"; then error 'no script produced' exit 12 fi if test "$debug" = true; then echo "$script" else eval "$script" fi