summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2016-07-16 19:00:47 +0200
committertv <tv@krebsco.de>2016-07-16 21:39:42 +0200
commit8fde09584a8ca1f52e6af53a04adfe4338ea4a1b (patch)
tree8b8924de6366c87defd85bbb7a182c6183073844 /bin
initv1.0.0
Diffstat (limited to 'bin')
-rwxr-xr-xbin/populate64
1 files changed, 64 insertions, 0 deletions
diff --git a/bin/populate b/bin/populate
new file mode 100755
index 0000000..17a8107
--- /dev/null
+++ b/bin/populate
@@ -0,0 +1,64 @@
+#! /bin/sh
+set -efu
+
+self=$(readlink -f "$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 "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 1
+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 "$debug" = true; then
+ echo "$script"
+else
+ eval "$script"
+fi