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
16 Where <command> is one of:
17 run <FILE|URL> - run plugin from FILE/URL
18 scan - look for available plugins on attached devices
19 create <DIR> - create a new plugin archive from DIR
40 wget -O - "$url" > $file
43 ncftpget -c "$url" > $file
46 echo "error: Unsuported protocol $proto" >&2
54 if [ "$PLUGIN_VENDOR" ]
56 title="$PLUGIN_VENDOR: $PLUGIN_NAME"
62 echo " (version $PLUGIN_VERSION)"
71 for dir in etc dev sys proc
76 cp /etc/resolv.conf $base/etc
77 mount -o bind /dev $base/dev
78 mount -o bind /sys $base/sys
79 mount -o bind /proc $base/proc
88 [ -e $base/dev/null ] && umount $base/dev
89 [ -e $base/sys/kernel ] && umount $base/sys
90 [ -e $base/proc/stat ] && umount $base/proc
103 echo "error: install requires a file/URL argument." >&2
112 trap "rm '$file'" EXIT
113 download "$url" "$file"
116 echo "error: failed to download $url" >&2
123 echo "error: $file doesn't exist or is not readable" >&2
128 echo "File '$name' has the following sha256 checksum:"
130 sha256sum "$file" | cut -f1 -d' '
132 echo "Do you want to run this plugin? (y/N)"
145 gunzip -c "$file" | ( cd $__dest && cpio -i -d)
149 echo "error: Failed to extract archive $url, exiting"
154 . $__dest/$plugin_meta_path
157 executable=${PLUGIN_EXECUTABLE:-$executable}
161 printf "Entering plugin\n"
164 chroot $__dest $executable
166 printf "\nExiting plugin & cleaning up\n"
167 __run_cleanup $__dest
174 local found dev plugin_path __meta_tmp
176 for mnt in $__pb_mount_dir/*
179 plugin_path="$mnt/$plugin_file"
181 [ -e "$plugin_path" ] || continue
183 # extract plugin metadata to a temporary directory
184 __meta_tmp=$(mktemp -d)
185 [ -d $__meta_tmp ] || continue
186 gunzip -c "$plugin_path" |
188 cpio -i -d $plugin_meta_path 2>/dev/null)
189 if ! [ $? = 0 -a -e "$plugin_path" ]
196 . $__meta_tmp/$plugin_meta_path
198 printf "Plugin found on %s:\n" $dev
201 printf "To run this plugin:\n"
202 printf " $0 run $plugin_path\n"
211 echo "No plugins found"
217 local vendorname vendorshortname
218 local pluginname pluginnhortname
219 local version date executable
226 Enter the vendor company / author name. This can contain spaces.
227 (eg. 'Example Corporation')
232 Enter the vendor shortname. This should be a single-word abbreviation, in all
233 lower-case. This is only used in internal filenames.
235 Typically, a stock-ticker name is used for this (eg 'exco')
241 Enter the descriptive plugin name. This can contain spaces, but should only be
242 a few words in length (eg 'RAID configuration utility')
248 Enter the plugin shortname. This should not contain spaces, but hyphens are
249 fine (eg 'raid-config'). This is only used in internal filnames.
256 Enter the plugin version. This should not contain spaces (eg 1.2):
262 Enter the full path (within the plugin root) to the plugin executable file.
263 This will be the default action when the plugin is run. (eg /usr/bin/my-util)
267 date=$(date +%Y-%m-%d)
269 mkdir -p $(dirname $file)
272 PLUGIN_VENDOR='$vendorname'
273 PLUGIN_NAME='$pluginname'
274 PLUGIN_VERSION='$version'
276 PLUGIN_EXECUTABLE='$executable'
283 local src meta_dir_abs meta_file
288 echo "error: missing source directory" >&2
295 echo "error: source directory missing" >&2
299 meta_file=$src/$plugin_meta_path
301 if [ ! -e $meta_file ]
303 echo "No plugin metadata file found. " \
304 "Would you like to create one? (Y/n)"
308 echo "Cancelled, exiting"
312 guided_meta $meta_file || exit
315 # Sanity check metadata file
318 if [ ! -n "$PLUGIN_VENDOR" ]
320 echo "error: no PLUGIN_VENDOR defined in metadata" &>2
323 if [ ! -n "$PLUGIN_NAME" ]
325 echo "error: no PLUGIN_NAME defined in metadata" &>2
328 if [ ! -n "$PLUGIN_VERSION" ]
330 echo "error: no PLUGIN_VERSION defined in metadata" &>2
333 if [ ! -n "$PLUGIN_DATE" ]
335 echo "error: no PLUGIN_DATE defined in metadata" &>2
338 if [ ! -n "$PLUGIN_EXECUTABLE" ]
340 echo "error: no PLUGIN_EXECUTABLE defined in metadata" \
351 find -mindepth 1 | cpio -o -Hnewc -v
352 ) | gzip -c > $outfile
355 echo "Plugin metadata:"
356 sed -e 's/^/ /' $meta_file
359 echo "User-visible metadata:"
363 plugin_info | sed -e 's/^/ /'
373 Ship this file in the top-level-directory of a USB device or CD to have it
374 automatically discoverable by 'pb-plugin scan'.
382 tmp=$(mktemp -p $test_tmpdir)
383 ref=$(mktemp -p $test_tmpdir)
392 download http://example.com/test $tmp
400 tmp=$(mktemp -p $test_tmpdir)
401 ref=$(mktemp -p $test_tmpdir)
410 download ftp://example.com/test $tmp
416 __pb_mount_dir="$test_tmpdir/mnt"
417 mnt_dir="$__pb_mount_dir/sda"
418 mkdir -p $mnt_dir/$plugin_meta_dir
420 echo "PLUGIN_NAME=test"
421 echo "PLUGIN_VERSION=1"
422 echo "PLUGIN_EXECUTABLE=/bin/sh"
423 ) > $mnt_dir/$plugin_meta_path
426 find -mindepth 1 | cpio -o -Hnewc 2>/dev/null
427 ) | gzip -c > $mnt_dir/$plugin_file
429 do_scan | grep -q 'test 1'
435 __pb_mount_dir="$test_tmpdir/mnt"
436 mkdir -p $__pb_mount_dir
437 do_scan | grep -q "No plugins"
444 test_tmpdir="$tests_tmpdir/$n"
486 tests_tmpdir=$(mktemp -d)
489 do_test ! is_url "/test"
490 do_test ! is_url "./test"
491 do_test ! is_url "../test"
492 do_test ! is_url "test"
493 do_test is_url "http://example.com/path"
494 do_test is_url "git+ssh://example.com/path"
495 do_test test_http_download
496 do_test test_ftp_download
498 do_test test_empty_scan
500 if [ $test_failed = 0 ]
502 echo "$n tests passed"
507 rm -rf "$tests_tmpdir"
528 echo "error: Missing command" >&2
533 echo "Invalid command: $s" >&2