fwupdmgr/fwupdtool: Move firmware builder from fwupdmgr to fwupdtool

This command is really a power user command and should live in
fwupdtool with similar debugging and development features.
This commit is contained in:
Mario Limonciello 2018-10-18 12:57:10 -05:00 committed by Richard Hughes
parent cdcd6a2423
commit f6d01b16de
4 changed files with 51 additions and 51 deletions

View File

@ -1,5 +1,4 @@
_fwupdmgr_cmd_list=(
'build-firmware'
'clear-history'
'clear-offline'
'clear-results'
@ -147,23 +146,6 @@ _fwupdmgr()
_show_modifiers
fi
;;
build-firmware)
#file in
if [[ "$prev" = "$command" ]]; then
_filedir
#file out
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
_filedir
#script
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
_filedir
#output
elif [[ "$prev" = "${COMP_WORDS[4]}" ]]; then
_filedir
else
_show_modifiers
fi
;;
*)
#find first command
if [[ ${COMP_CWORD} = 1 ]]; then

View File

@ -1,4 +1,5 @@
_fwupdtool_cmd_list=(
'build-firmware'
'get-details'
'get-devices'
'get-plugins'
@ -66,6 +67,23 @@ _fwupdtool()
_show_modifiers
fi
;;
build-firmware)
#file in
if [[ "$prev" = "$command" ]]; then
_filedir
#file out
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
_filedir
#script
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
_filedir
#output
elif [[ "$prev" = "${COMP_WORDS[4]}" ]]; then
_filedir
else
_show_modifiers
fi
;;
*)
#find first command
if [[ ${COMP_CWORD} = 1 ]]; then

View File

@ -906,6 +906,33 @@ fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error)
return TRUE;
}
static gboolean
fu_util_firmware_builder (FuUtilPrivate *priv, gchar **values, GError **error)
{
const gchar *script_fn = "startup.sh";
const gchar *output_fn = "firmware.bin";
g_autoptr(GBytes) archive_blob = NULL;
g_autoptr(GBytes) firmware_blob = NULL;
if (g_strv_length (values) < 2) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_ARGS,
"Invalid arguments");
return FALSE;
}
archive_blob = fu_common_get_contents_bytes (values[0], error);
if (archive_blob == NULL)
return FALSE;
if (g_strv_length (values) > 2)
script_fn = values[2];
if (g_strv_length (values) > 3)
output_fn = values[3];
firmware_blob = fu_common_firmware_builder (archive_blob, script_fn, output_fn, error);
if (firmware_blob == NULL)
return FALSE;
return fu_common_set_contents_bytes (values[1], firmware_blob, error);
}
int
main (int argc, char *argv[])
{
@ -957,6 +984,12 @@ main (int argc, char *argv[])
/* add commands */
priv->cmd_array = g_ptr_array_new_with_free_func ((GDestroyNotify) fu_util_item_free);
fu_util_add (priv->cmd_array,
"build-firmware",
"FILE-IN FILE-OUT [SCRIPT] [OUTPUT]",
/* TRANSLATORS: command description */
_("Build firmware using a sandbox"),
fu_util_firmware_builder);
fu_util_add (priv->cmd_array,
"smbios-dump",
"FILE",

View File

@ -1970,33 +1970,6 @@ fu_util_changed_cb (FwupdClient *client, gpointer user_data)
g_print ("%s\n", _("Changed"));
}
static gboolean
fu_util_firmware_builder (FuUtilPrivate *priv, gchar **values, GError **error)
{
const gchar *script_fn = "startup.sh";
const gchar *output_fn = "firmware.bin";
g_autoptr(GBytes) archive_blob = NULL;
g_autoptr(GBytes) firmware_blob = NULL;
if (g_strv_length (values) < 2) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_INVALID_ARGS,
"Invalid arguments");
return FALSE;
}
archive_blob = fu_common_get_contents_bytes (values[0], error);
if (archive_blob == NULL)
return FALSE;
if (g_strv_length (values) > 2)
script_fn = values[2];
if (g_strv_length (values) > 3)
output_fn = values[3];
firmware_blob = fu_common_firmware_builder (archive_blob, script_fn, output_fn, error);
if (firmware_blob == NULL)
return FALSE;
return fu_common_set_contents_bytes (values[1], firmware_blob, error);
}
static gboolean
fu_util_monitor (FuUtilPrivate *priv, gchar **values, GError **error)
{
@ -2503,12 +2476,6 @@ main (int argc, char *argv[])
/* TRANSLATORS: command description */
_("Monitor the daemon for events"),
fu_util_monitor);
fu_util_add (priv->cmd_array,
"build-firmware",
"FILE-IN FILE-OUT [SCRIPT] [OUTPUT]",
/* TRANSLATORS: command description */
_("Build firmware using a sandbox"),
fu_util_firmware_builder);
fu_util_add (priv->cmd_array,
"modify-remote",
"REMOTE-ID KEY VALUE",