]> git.ozlabs.org Git - petitboot/blobdiff - utils/pb-plugin
travis: Enable ppc64le Travis builds
[petitboot] / utils / pb-plugin
index a22e8c431d7ea2e18ae9f6cfa3343b3dd98e2d92..a42d0515756f1cb98447b8a84bc3376e904a562f 100755 (executable)
@@ -16,7 +16,7 @@ Usage: $0 <command>
 
 Where <command> is one of:
   install <FILE|URL> - install plugin from FILE/URL
-  scan               - look for available plugins on attached devices
+  scan <DIR>         - look for available plugins on attached devices
   create <DIR>       - create a new plugin archive from DIR
   lint <FILE>        - perform a pre-distribution check on FILE
 EOF
@@ -64,6 +64,27 @@ plugin_info()
        echo "  (version $PLUGIN_VERSION)"
 }
 
+parse_meta()
+{
+       local file name value IFS
+
+       file=$1
+
+       IFS='='
+       while read -r name value
+       do
+               # Ensure we have a sensible variable name
+               echo "$name" | grep -q '^PLUGIN_[A-Z_]*$' || continue
+
+               # we know that $name has no quoting/expansion chars, but we
+               # may need to do some basic surrounding-quote removal for
+               # $value, without evaluating it
+               value=$(echo "$value" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")
+
+               export $name="$value"
+       done < $file
+}
+
 # How the ABI versioning works:
 #
 #  - This script has an ABI defined ($plugin_abi)
@@ -129,7 +150,12 @@ EOF
 
 do_install()
 {
-       local url name file __dest
+       local url name file __dest auto
+
+       if [ "$1" == "auto" ]; then
+               auto=y
+               shift;
+       fi
 
        url=$1
 
@@ -165,17 +191,20 @@ do_install()
        sha256sum "$file" | cut -f1 -d' '
        echo
 
-       echo "Do you want to install this plugin? (y/N)"
-       read resp
+       if [ -z "$auto" ]
+       then
+               echo "Do you want to install this plugin? (y/N)"
+               read resp
 
-       case $resp in
-       [yY]|[yY][eE][sS])
-               ;;
-       *)
-               echo "Cancelled"
-               exit 0
-               ;;
-       esac
+               case $resp in
+               [yY]|[yY][eE][sS])
+                       ;;
+               *)
+                       echo "Cancelled"
+                       exit 0
+                       ;;
+               esac
+       fi
 
        __dest=$(mktemp -d)
        gunzip -c "$file" | ( cd $__dest && cpio -i -d)
@@ -187,7 +216,7 @@ do_install()
                exit 1
        fi
 
-       . $__dest/$plugin_meta_path
+       parse_meta $__dest/$plugin_meta_path
 
        if ! plugin_abi_check
        then
@@ -202,6 +231,12 @@ do_install()
                __create_wrapper "$__dest" "$binary"
        done
 
+       pb-event plugin@local \
+               name=$PLUGIN_NAME id=$PLUGIN_ID version=$PLUGIN_VERSION \
+               vendor=$PLUGIN_VENDOR vendor_id=$PLUGIN_VENDOR_ID \
+               date=$PLUGIN_DATE executables="$PLUGIN_EXECUTABLES" \
+               source_file=$url installed="yes"
+
        echo "Plugin installed"
        plugin_info
 }
@@ -229,7 +264,7 @@ do_scan_mount()
                fi
 
                (
-                       . $__meta_tmp/$plugin_meta_path
+                       parse_meta $__meta_tmp/$plugin_meta_path
 
                        plugin_abi_check || exit 1
 
@@ -237,8 +272,11 @@ do_scan_mount()
                        plugin_info
                        printf "\n"
                        printf "To run this plugin:\n"
-                       printf "  $0 run $plugin_path\n"
+                       printf "  $0 install $plugin_path\n"
                        printf "\n"
+
+                       pb-event plugin@$dev name=$PLUGIN_NAME \
+                               path=$plugin_path installed="no"
                )
                if [ $? = 0 ]
                then
@@ -250,9 +288,18 @@ do_scan_mount()
 
 do_scan()
 {
-       local found mnt
+       local found mnt dev locations
        found=0
-       for mnt in $__pb_mount_dir/*
+       dev=$1
+
+       if [ -z $dev ]; then
+               locations=$__pb_mount_dir/*
+       else
+               echo "Scanning device $dev"
+               locations=$dev
+       fi
+
+       for mnt in $locations
        do
                do_scan_mount $mnt
        done
@@ -371,7 +418,7 @@ do_create()
        fi
 
        # Sanity check metadata file
-       . $meta_file
+       parse_meta $meta_file
 
        errors=0
        warnings=0
@@ -501,10 +548,7 @@ do_lint()
                lint_fatal "No metadata file present (expecting" \
                        "$plugin_meta_path)"
 
-       (sh -e "$__dest/$plugin_meta_path") >/dev/null 2>&1  ||
-               lint_err "Plugin metadata file has shell errors"
-
-       . "$__dest/$plugin_meta_path"
+       parse_meta "$__dest/$plugin_meta_path"
        lint_metadata
 
        for executable in ${PLUGIN_EXECUTABLES}
@@ -816,7 +860,7 @@ __test)
        exit 1
        ;;
 *)
-       echo "Invalid command: $s" >&2
+       echo "Invalid command: $1" >&2
        usage
        exit 1
 esac