4 __pb_mount_dir=/var/petitboot/mnt/dev/
6 plugin_file=pb-plugin.cpio.gz
7 plugin_meta=pb-plugin.conf
8 plugin_meta_dir=etc/preboot-plugins/
9 plugin_meta_path=$plugin_meta_dir$plugin_meta
10 plugin_wrapper_dir=/usr/bin
17 Where <command> is one of:
18 install <FILE|URL> - install plugin from FILE/URL
19 scan - look for available plugins on attached devices
20 create <DIR> - create a new plugin archive from DIR
41 wget -O - "$url" > $file
44 ncftpget -c "$url" > $file
47 echo "error: Unsuported protocol $proto" >&2
55 if [ "$PLUGIN_VENDOR" ]
57 title="$PLUGIN_VENDOR: $PLUGIN_NAME"
63 echo " (version $PLUGIN_VERSION)"
74 for dir in etc dev sys proc var
76 [ -e "$base/$dir" ] || mkdir -p "$base/$dir"
79 cp /etc/resolv.conf $base/etc
80 mount -o bind /dev $base/dev
81 mount -o bind /sys $base/sys
82 mount -o bind /proc $base/proc
83 mount -o bind /var $base/var
85 chroot "$base" "$binary" "$@"
95 local base binary wrapper
99 wrapper=$plugin_wrapper_dir/$(basename $binary)
104 exec $(realpath $0) __wrap '$base' '$binary' "\$@"
112 local url name file __dest
118 echo "error: install requires a file/URL argument." >&2
127 trap "rm '$file'" EXIT
128 download "$url" "$file"
131 echo "error: failed to download $url" >&2
138 echo "error: $file doesn't exist or is not readable" >&2
143 echo "File '$name' has the following sha256 checksum:"
145 sha256sum "$file" | cut -f1 -d' '
147 echo "Do you want to install this plugin? (y/N)"
160 gunzip -c "$file" | ( cd $__dest && cpio -i -d)
164 echo "error: Failed to extract archive $url, exiting"
169 . $__dest/$plugin_meta_path
171 for binary in ${PLUGIN_EXECUTABLES}
173 __create_wrapper "$__dest" "$binary"
176 echo "Plugin installed"
182 local found dev plugin_path __meta_tmp
184 for mnt in $__pb_mount_dir/*
187 plugin_path="$mnt/$plugin_file"
189 [ -e "$plugin_path" ] || continue
191 # extract plugin metadata to a temporary directory
192 __meta_tmp=$(mktemp -d)
193 [ -d $__meta_tmp ] || continue
194 gunzip -c "$plugin_path" |
196 cpio -i -d $plugin_meta_path 2>/dev/null)
197 if ! [ $? = 0 -a -e "$plugin_path" ]
204 . $__meta_tmp/$plugin_meta_path
206 printf "Plugin found on %s:\n" $dev
209 printf "To run this plugin:\n"
210 printf " $0 run $plugin_path\n"
219 echo "No plugins found"
225 local vendorname vendorshortname
226 local pluginname pluginnhortname
227 local version date executable
234 Enter the vendor company / author name. This can contain spaces.
235 (eg. 'Example Corporation')
240 Enter the vendor shortname. This should be a single-word abbreviation, in all
241 lower-case. This is only used in internal filenames.
243 Typically, a stock-ticker name is used for this (eg 'exco')
249 Enter the descriptive plugin name. This can contain spaces, but should only be
250 a few words in length (eg 'RAID configuration utility')
256 Enter the plugin shortname. This should not contain spaces, but hyphens are
257 fine (eg 'raid-config'). This is only used in internal filnames.
264 Enter the plugin version. This should not contain spaces (eg 1.2):
270 Enter the full path (within the plugin root) to the plugin executable file(s).
271 These will be exposed as wrapper scripts, to be run from the standard petitboot
272 shell environment (eg, /usr/bin/my-raid-config).
274 If multiple executables are provided, separate with a space.
278 date=$(date +%Y-%m-%d)
280 mkdir -p $(dirname $file)
283 PLUGIN_VENDOR='$vendorname'
284 PLUGIN_NAME='$pluginname'
285 PLUGIN_VERSION='$version'
287 PLUGIN_EXECUTABLES='$executables'
294 local src meta_dir_abs meta_file
299 echo "error: missing source directory" >&2
306 echo "error: source directory missing" >&2
310 meta_file=$src/$plugin_meta_path
312 if [ ! -e $meta_file ]
314 echo "No plugin metadata file found. " \
315 "Would you like to create one? (Y/n)"
319 echo "Cancelled, exiting"
323 guided_meta $meta_file || exit
326 # Sanity check metadata file
329 if [ ! -n "$PLUGIN_VENDOR" ]
331 echo "error: no PLUGIN_VENDOR defined in metadata" &>2
334 if [ ! -n "$PLUGIN_NAME" ]
336 echo "error: no PLUGIN_NAME defined in metadata" &>2
339 if [ ! -n "$PLUGIN_VERSION" ]
341 echo "error: no PLUGIN_VERSION defined in metadata" &>2
344 if [ ! -n "$PLUGIN_DATE" ]
346 echo "error: no PLUGIN_DATE defined in metadata" &>2
349 if [ ! -n "$PLUGIN_EXECUTABLES" ]
351 echo "error: no PLUGIN_EXECUTABLES defined in metadata"\ &>2
361 find -mindepth 1 | cpio -o -Hnewc -v
362 ) | gzip -c > $outfile
365 echo "Plugin metadata:"
366 sed -e 's/^/ /' $meta_file
369 echo "User-visible metadata:"
373 plugin_info | sed -e 's/^/ /'
383 Ship this file in the top-level-directory of a USB device or CD to have it
384 automatically discoverable by 'pb-plugin scan'.
392 tmp=$(mktemp -p $test_tmpdir)
393 ref=$(mktemp -p $test_tmpdir)
402 download http://example.com/test $tmp
410 tmp=$(mktemp -p $test_tmpdir)
411 ref=$(mktemp -p $test_tmpdir)
420 download ftp://example.com/test $tmp
426 __pb_mount_dir="$test_tmpdir/mnt"
427 mnt_dir="$__pb_mount_dir/sda"
428 mkdir -p $mnt_dir/$plugin_meta_dir
430 echo "PLUGIN_NAME=test"
431 echo "PLUGIN_VERSION=1"
432 echo "PLUGIN_EXECUTABLES=/bin/sh"
433 ) > $mnt_dir/$plugin_meta_path
436 find -mindepth 1 | cpio -o -Hnewc 2>/dev/null
437 ) | gzip -c > $mnt_dir/$plugin_file
439 do_scan | grep -q 'test 1'
445 __pb_mount_dir="$test_tmpdir/mnt"
446 mkdir -p $__pb_mount_dir
447 do_scan | grep -q "No plugins"
454 test_tmpdir="$tests_tmpdir/$n"
496 tests_tmpdir=$(mktemp -d)
499 do_test ! is_url "/test"
500 do_test ! is_url "./test"
501 do_test ! is_url "../test"
502 do_test ! is_url "test"
503 do_test is_url "http://example.com/path"
504 do_test is_url "git+ssh://example.com/path"
505 do_test test_http_download
506 do_test test_ftp_download
508 do_test test_empty_scan
510 if [ $test_failed = 0 ]
512 echo "$n tests passed"
517 rm -rf "$tests_tmpdir"
542 echo "error: Missing command" >&2
547 echo "Invalid command: $s" >&2