Rather than having to 'pb-plugin run' multiple times, we want users to
be able to execute multiple plugin binaries with more accessible
command-line statements.
This change reverts to the previous 'install' (rather than 'run')
behaviour, and creates wrapper scripts to call into the chroot.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
plugin_meta=pb-plugin.conf
plugin_meta_dir=etc/preboot-plugins/
plugin_meta_path=$plugin_meta_dir$plugin_meta
plugin_meta=pb-plugin.conf
plugin_meta_dir=etc/preboot-plugins/
plugin_meta_path=$plugin_meta_dir$plugin_meta
+plugin_wrapper_dir=/usr/bin
Usage: $0 <command>
Where <command> is one of:
Usage: $0 <command>
Where <command> is one of:
- run <FILE|URL> - run plugin from FILE/URL
- scan - look for available plugins on attached devices
- create <DIR> - create a new plugin archive from DIR
+ install <FILE|URL> - install plugin from FILE/URL
+ scan - look for available plugins on attached devices
+ create <DIR> - create a new plugin archive from DIR
echo " (version $PLUGIN_VERSION)"
}
echo " (version $PLUGIN_VERSION)"
}
- for dir in etc dev sys proc
+ for dir in etc dev sys proc var
+ [ -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
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
+ local base binary wrapper
+ binary=$2
+ wrapper=$plugin_wrapper_dir/$(basename $binary)
- [ -e $base/dev/null ] && umount $base/dev
- [ -e $base/sys/kernel ] && umount $base/sys
- [ -e $base/proc/stat ] && umount $base/proc
- rm -rf $base
+ cat <<EOF > $wrapper
+#!/bin/sh
+
+exec $(realpath $0) __wrap '$base' '$binary' "\$@"
+EOF
+
+ chmod a+x $wrapper
+ local url name file __dest
echo
sha256sum "$file" | cut -f1 -d' '
echo
echo
sha256sum "$file" | cut -f1 -d' '
echo
- echo "Do you want to run this plugin? (y/N)"
+ echo "Do you want to install this plugin? (y/N)"
. $__dest/$plugin_meta_path
. $__dest/$plugin_meta_path
- (
- executable=${PLUGIN_EXECUTABLE:-$executable}
-
- __run_init $__dest
-
- printf "Entering plugin\n"
- plugin_info
-
- chroot $__dest $executable
-
- printf "\nExiting plugin & cleaning up\n"
- __run_cleanup $__dest
- )
+ for binary in ${PLUGIN_EXECUTABLES}
+ do
+ __create_wrapper "$__dest" "$binary"
+ done
+ echo "Plugin installed"
+ plugin_info
-Enter the full path (within the plugin root) to the plugin executable file.
-This will be the default action when the plugin is run. (eg /usr/bin/my-util)
+Enter the full path (within the plugin root) to the plugin executable file(s).
+These will be exposed as wrapper scripts, to be run from the standard petitboot
+shell environment (eg, /usr/bin/my-raid-config).
+
+If multiple executables are provided, separate with a space.
PLUGIN_NAME='$pluginname'
PLUGIN_VERSION='$version'
PLUGIN_DATE='$date'
PLUGIN_NAME='$pluginname'
PLUGIN_VERSION='$version'
PLUGIN_DATE='$date'
-PLUGIN_EXECUTABLE='$executable'
+PLUGIN_EXECUTABLES='$executables'
echo "error: no PLUGIN_DATE defined in metadata" &>2
exit 1
fi
echo "error: no PLUGIN_DATE defined in metadata" &>2
exit 1
fi
- if [ ! -n "$PLUGIN_EXECUTABLE" ]
+ if [ ! -n "$PLUGIN_EXECUTABLES" ]
- echo "error: no PLUGIN_EXECUTABLE defined in metadata" \
- &>2
+ echo "error: no PLUGIN_EXECUTABLES defined in metadata"\ &>2
(
echo "PLUGIN_NAME=test"
echo "PLUGIN_VERSION=1"
(
echo "PLUGIN_NAME=test"
echo "PLUGIN_VERSION=1"
- echo "PLUGIN_EXECUTABLE=/bin/sh"
+ echo "PLUGIN_EXECUTABLES=/bin/sh"
) > $mnt_dir/$plugin_meta_path
(
cd $mnt_dir;
) > $mnt_dir/$plugin_meta_path
(
cd $mnt_dir;
+__wrap)
+ shift
+ do_wrap $@
+ ;;
__test)
shift
do_tests $@
__test)
shift
do_tests $@