summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
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