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=/var/lib/pb-plugins/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)
101 mkdir -p $plugin_wrapper_dir
106 exec $(realpath $0) __wrap '$base' '$binary' "\$@"
114 local url name file __dest
120 echo "error: install requires a file/URL argument." >&2
129 trap "rm '$file'" EXIT
130 download "$url" "$file"
133 echo "error: failed to download $url" >&2
140 echo "error: $file doesn't exist or is not readable" >&2
145 echo "File '$name' has the following sha256 checksum:"
147 sha256sum "$file" | cut -f1 -d' '
149 echo "Do you want to install this plugin? (y/N)"
162 gunzip -c "$file" | ( cd $__dest && cpio -i -d)
166 echo "error: Failed to extract archive $url, exiting"
171 . $__dest/$plugin_meta_path
173 for binary in ${PLUGIN_EXECUTABLES}
175 __create_wrapper "$__dest" "$binary"
178 echo "Plugin installed"
184 local found dev plugin_path __meta_tmp
186 for mnt in $__pb_mount_dir/*
189 plugin_path="$mnt/$plugin_file"
191 [ -e "$plugin_path" ] || continue
193 # extract plugin metadata to a temporary directory
194 __meta_tmp=$(mktemp -d)
195 [ -d $__meta_tmp ] || continue
196 gunzip -c "$plugin_path" |
198 cpio -i -d $plugin_meta_path 2>/dev/null)
199 if ! [ $? = 0 -a -e "$plugin_path" ]
206 . $__meta_tmp/$plugin_meta_path
208 printf "Plugin found on %s:\n" $dev
211 printf "To run this plugin:\n"
212 printf " $0 run $plugin_path\n"
221 echo "No plugins found"
227 local vendorname vendorshortname
228 local pluginname pluginnhortname
229 local version date executable
236 Enter the vendor company / author name. This can contain spaces.
237 (eg. 'Example Corporation')
242 Enter the vendor shortname. This should be a single-word abbreviation, in all
243 lower-case. This is only used in internal filenames.
245 Typically, a stock-ticker name is used for this (eg 'exco')
251 Enter the descriptive plugin name. This can contain spaces, but should only be
252 a few words in length (eg 'RAID configuration utility')
258 Enter the plugin shortname. This should not contain spaces, but hyphens are
259 fine (eg 'raid-config'). This is only used in internal filnames.
266 Enter the plugin version. This should not contain spaces (eg 1.2):
272 Enter the full path (within the plugin root) to the plugin executable file(s).
273 These will be exposed as wrapper scripts, to be run from the standard petitboot
274 shell environment (eg, /usr/bin/my-raid-config).
276 If multiple executables are provided, separate with a space.
280 date=$(date +%Y-%m-%d)
282 mkdir -p $(dirname $file)
285 PLUGIN_VENDOR='$vendorname'
286 PLUGIN_NAME='$pluginname'
287 PLUGIN_VERSION='$version'
289 PLUGIN_EXECUTABLES='$executables'
296 local src meta_dir_abs meta_file
301 echo "error: missing source directory" >&2
308 echo "error: source directory missing" >&2
312 meta_file=$src/$plugin_meta_path
314 if [ ! -e $meta_file ]
316 echo "No plugin metadata file found. " \
317 "Would you like to create one? (Y/n)"
321 echo "Cancelled, exiting"
325 guided_meta $meta_file || exit
328 # Sanity check metadata file
331 if [ ! -n "$PLUGIN_VENDOR" ]
333 echo "error: no PLUGIN_VENDOR defined in metadata" &>2
336 if [ ! -n "$PLUGIN_NAME" ]
338 echo "error: no PLUGIN_NAME defined in metadata" &>2
341 if [ ! -n "$PLUGIN_VERSION" ]
343 echo "error: no PLUGIN_VERSION defined in metadata" &>2
346 if [ ! -n "$PLUGIN_DATE" ]
348 echo "error: no PLUGIN_DATE defined in metadata" &>2
351 if [ ! -n "$PLUGIN_EXECUTABLES" ]
353 echo "error: no PLUGIN_EXECUTABLES defined in metadata"\ &>2
363 find -mindepth 1 | cpio -o -Hnewc -v
364 ) | gzip -c > $outfile
367 echo "Plugin metadata:"
368 sed -e 's/^/ /' $meta_file
371 echo "User-visible metadata:"
375 plugin_info | sed -e 's/^/ /'
385 Ship this file in the top-level-directory of a USB device or CD to have it
386 automatically discoverable by 'pb-plugin scan'.
394 tmp=$(mktemp -p $test_tmpdir)
395 ref=$(mktemp -p $test_tmpdir)
404 download http://example.com/test $tmp
412 tmp=$(mktemp -p $test_tmpdir)
413 ref=$(mktemp -p $test_tmpdir)
422 download ftp://example.com/test $tmp
428 __pb_mount_dir="$test_tmpdir/mnt"
429 mnt_dir="$__pb_mount_dir/sda"
430 mkdir -p $mnt_dir/$plugin_meta_dir
432 echo "PLUGIN_NAME=test"
433 echo "PLUGIN_VERSION=1"
434 echo "PLUGIN_EXECUTABLES=/bin/sh"
435 ) > $mnt_dir/$plugin_meta_path
438 find -mindepth 1 | cpio -o -Hnewc 2>/dev/null
439 ) | gzip -c > $mnt_dir/$plugin_file
441 do_scan | grep -q 'test 1'
447 __pb_mount_dir="$test_tmpdir/mnt"
448 mkdir -p $__pb_mount_dir
449 do_scan | grep -q "No plugins"
456 test_tmpdir="$tests_tmpdir/$n"
498 tests_tmpdir=$(mktemp -d)
501 do_test ! is_url "/test"
502 do_test ! is_url "./test"
503 do_test ! is_url "../test"
504 do_test ! is_url "test"
505 do_test is_url "http://example.com/path"
506 do_test is_url "git+ssh://example.com/path"
507 do_test test_http_download
508 do_test test_ftp_download
510 do_test test_empty_scan
512 if [ $test_failed = 0 ]
514 echo "$n tests passed"
519 rm -rf "$tests_tmpdir"
544 echo "error: Missing command" >&2
549 echo "Invalid command: $s" >&2