+# How the ABI versioning works:
+#
+# - This script has an ABI defined ($plugin_abi)
+#
+# - Plugins have a current ABI number ($PLUGIN_ABI), and a minimum supported
+# ABI number ($PLUGIN_ABI_MIN).
+#
+# - A plugin is OK to run if:
+# - the plugin's ABI matches the script ABI, or
+# - the plugin's minimum ABI is lower than or equal to the script ABI
+plugin_abi_check()
+{
+ [ -n "$PLUGIN_ABI" ] &&
+ ( [ $PLUGIN_ABI -eq $plugin_abi ] ||
+ [ $PLUGIN_ABI_MIN -le $plugin_abi ] )
+}
+
+do_wrap()
+{
+ local base binary dir
+
+ base=$1
+ binary=$2
+ shift 2
+
+ for dir in etc dev sys proc var
+ do
+ [ -e "$base/$dir" ] || mkdir -p "$base/$dir"
+ done
+
+ cp /etc/resolv.conf $base/etc
+ mount -o bind /dev $base/dev
+ mount -o bind /sys $base/sys
+ mount -o bind /proc $base/proc
+ mount -o bind /var $base/var
+
+ chroot "$base" "$binary" "$@"
+
+ umount $base/dev
+ umount $base/sys
+ umount $base/proc
+ umount $base/var
+}
+
+__create_wrapper()
+{
+ local base binary wrapper
+
+ base=$1
+ binary=$2
+ wrapper=$plugin_wrapper_dir/$(basename $binary)
+
+ mkdir -p $plugin_wrapper_dir
+
+ cat <<EOF > $wrapper
+#!/bin/sh
+
+exec $(realpath $0) __wrap '$base' '$binary' "\$@"
+EOF
+
+ chmod a+x $wrapper
+}
+