4 __pb_mount_dir=/var/petitboot/mnt/dev/
5 plugin_dev_meta=pb-plugin.conf
6 plugin_installed_meta_dir=/etc/preboot-plugins/
13 Where <command> is one of:
14 install <FILE|URL> - install plugin from FILE/URL
15 scan - look for available plugins on attached devices
16 list - list currently-installed plugins
17 create <DIR> - create a new plugin archive from DIR
38 wget -O - "$url" > $file
41 ncftpget -c "$url" > $file
44 echo "error: Unsuported protocol $proto" >&2
52 if [ "$PLUGIN_VENDOR" ]
54 title="$PLUGIN_VENDOR: $PLUGIN_NAME"
60 echo " (version $PLUGIN_VERSION)"
71 echo "error: install requires a file/URL argument." >&2
77 echo "error: destination directory '$__dest' doesn't exist" >&2
83 echo "error: destination directory isn't writeable" >&2
92 trap "rm '$file'" EXIT
93 download "$url" "$file"
96 echo "error: failed to download $url" >&2
103 echo "error: $file doesn't exist or is not readable" >&2
108 echo "File '$name' has the following sha256 checksum:"
110 sha256sum "$file" | cut -f1 -d' '
112 echo "Do you want to install into the pre-boot environment? (y/N)"
124 gunzip -c "$file" | ( cd $__dest && cpio -i -d)
128 echo "error: Failed to extract archive $url, exiting"
137 for mnt in $__pb_mount_dir/*
140 metafile="$mnt/$plugin_dev_meta"
141 [ -e "$metafile" ] || continue
144 printf "Plugin found on %s:\n" $dev
147 printf "To install this plugin, run:\n"
148 printf " $0 install $mnt/$PLUGIN_FILE\n"
156 echo "No plugins found"
164 for meta in $plugin_installed_meta_dir/*
166 [ -e "$meta" ] || continue
167 [ $found = 0 ] && printf "Installed plugins:\n"
178 echo "No plugins installed"
184 local vendorname vendorshortname
185 local pluginname pluginnhortname
193 Enter the vendor company / author name. This can contain spaces.
194 (eg. 'Example Corporation')
199 Enter the vendor shortname. This should be a single-word abbreviation, in all
200 lower-case. This is only used in internal filenames.
202 Typically, a stock-ticker name is used for this (eg 'exco')
208 Enter the descriptive plugin name. This can contain spaces, but should only be
209 a few words in length (eg 'RAID configuration utility')
215 Enter the plugin shortname. This should not contain spaces, but hyphens are
216 fine (eg 'raid-config'). This is only used in internal filnames.
223 Enter the plugin version. This should not contain spaces (eg 1.2):
227 date=$(date +%Y-%m-%d)
231 cat <<EOF > $dir/$vendorshortname-$pluginshortname
232 PLUGIN_VENDOR='$vendorname'
233 PLUGIN_NAME='$pluginname'
234 PLUGIN_VERSION='$version'
242 local src found meta_dir_abs meta_file
247 echo "error: missing source directory" >&2
254 echo "error: source directory missing" >&2
258 meta_dir_abs="$src/$plugin_installed_meta_dir"
260 for meta in $meta_dir_abs/*
262 [ -e "$meta" ] || continue
269 echo "No plugin metadata file found. " \
270 "Would you like to create one? (Y/n)"
274 echo "Cancelled, exiting"
278 guided_meta $meta_dir_abs || exit
279 meta_file=$meta_dir_abs/*
284 echo "error: Multiple metadata files found in $meta_dir_abs" >&2
288 # Sanity check metadata file
291 if [ ! -n "$PLUGIN_VENDOR" ]
293 echo "error: no PLUGIN_VENDOR defined in metadata" &>2
296 if [ ! -n "$PLUGIN_NAME" ]
298 echo "error: no PLUGIN_NAME defined in metadata" &>2
301 if [ ! -n "$PLUGIN_VERSION" ]
303 echo "error: no PLUGIN_VERSION defined in metadata" &>2
306 if [ ! -n "$PLUGIN_DATE" ]
308 echo "error: no PLUGIN_DATE defined in metadata" &>2
314 outfile=pb-plugin.cpio.gz
318 find -mindepth 1 | cpio -o -Hnewc -v
319 ) | gzip -c > pb-plugin.cpio.gz
321 cp $meta_file $plugin_dev_meta
322 echo "PLUGIN_FILE='$outfile'" >> $plugin_dev_meta
325 echo "Plugin metadata:"
326 sed -e 's/^/ /' $meta_file
329 echo "User-visible metadata:"
333 plugin_info | sed -e 's/^/ /'
346 If you rename $outfile (or distribute it in a non-root directory), then
347 also update the PLUGIN_FILE variable in $plugin_dev_meta.
355 tmp=$(mktemp -p $test_tmpdir)
356 ref=$(mktemp -p $test_tmpdir)
365 download http://example.com/test $tmp
373 tmp=$(mktemp -p $test_tmpdir)
374 ref=$(mktemp -p $test_tmpdir)
383 download ftp://example.com/test $tmp
389 __pb_mount_dir="$test_tmpdir/mnt"
390 mnt_dir="$__pb_mount_dir/sda"
393 echo "PLUGIN_NAME=test"
394 echo "PLUGIN_VERSION=1"
395 echo "PLUGIN_FILE=data/pb-plugin.cpio.gz"
396 ) > $mnt_dir/$plugin_dev_meta
398 do_scan | grep -q 'test 1'
404 do_scan | grep -q "No plugins"
411 test_tmpdir="$tests_tmpdir/$n"
413 __test_dest="$test_tmpdir/base"
415 [ -d "$__test_dest" ] || exit 1
457 tests_tmpdir=$(mktemp -d)
460 do_test ! is_url "/test"
461 do_test ! is_url "./test"
462 do_test ! is_url "../test"
463 do_test ! is_url "test"
464 do_test is_url "http://example.com/path"
465 do_test is_url "git+ssh://example.com/path"
466 do_test test_http_download
467 do_test test_ftp_download
469 do_test test_empty_scan
471 if [ $test_failed = 0 ]
473 echo "$n tests passed"
478 rm -rf "$tests_tmpdir"
503 echo "error: Missing command" >&2
508 echo "Invalid command: $s" >&2