sbsign,sbverify: help2man-ize usage output

Update the usage output of sbsign and sbverify so that it can be better
parsed by help2man. Also, add --version and --help.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
Jeremy Kerr 2012-05-23 11:52:22 +08:00
parent e83712388f
commit fcf3cdf70a
3 changed files with 47 additions and 15 deletions

View file

@ -42,6 +42,8 @@ sbsign: $(sbsign_objs) $(ccan_objs)
sbverify: $(sbverify_objs) $(ccan_objs)
$(LINK.o) -o $@ $^ $(libs)
sbsign.o sbverify.o: CPPFLAGS+=-DVERSION=\"$(version)\"
gen-keyfiles: gen-keyfiles.o $(ccan_objs)
$(LINK.o) -o $@ $^ $(libs)
gen-keyfiles: libs = -luuid

View file

@ -41,6 +41,8 @@
#include "idc.h"
#include "image.h"
static const char *toolname = "sbsign";
struct sign_context {
struct image *image;
const char *infilename;
@ -53,21 +55,28 @@ static struct option options[] = {
{ "cert", required_argument, NULL, 'c' },
{ "key", required_argument, NULL, 'k' },
{ "verbose", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
};
static void usage(const char *progname)
static void usage(void)
{
fprintf(stderr,
"usage: %s --key <keyfile> --cert <certfile> "
printf("Usage: %s [options] --key <keyfile> --cert <certfile> "
"<efi-boot-image>\n"
"options:\n"
"Sign an EFI boot image for use with secure boot.\n\n"
"Options:\n"
"\t--key <keyfile> signing key (PEM-encoded RSA "
"private key)\n"
"\t--cert <certfile> certificate (x509 certificate)\n"
"\t--output <file> write signed data to <file>\n"
"\t (default <efi-boot-image>.signed)\n"
, progname);
"\t (default <efi-boot-image>.signed)\n",
toolname);
}
static void version(void)
{
printf("%s %s\n", toolname, VERSION);
}
static void set_default_outfilename(struct sign_context *ctx)
@ -106,11 +115,17 @@ int main(int argc, char **argv)
case 'd':
ctx->verbose = 1;
break;
case 'V':
version();
return EXIT_SUCCESS;
case 'h':
usage();
return EXIT_SUCCESS;
}
}
if (argc != optind + 1) {
usage(argv[0]);
usage();
return EXIT_FAILURE;
}
@ -121,13 +136,13 @@ int main(int argc, char **argv)
if (!certfilename) {
fprintf(stderr,
"error: No certificate specified (with --cert)\n");
usage(argv[0]);
usage();
return EXIT_FAILURE;
}
if (!keyfilename) {
fprintf(stderr,
"error: No key specified (with --key)\n");
usage(argv[0]);
usage();
return EXIT_FAILURE;
}

View file

@ -35,6 +35,8 @@
#include <openssl/pem.h>
#include <openssl/x509v3.h>
static const char *toolname = "sbverify";
enum verify_status {
VERIFY_FAIL = 0,
VERIFY_OK = 1,
@ -43,17 +45,24 @@ enum verify_status {
static struct option options[] = {
{ "cert", required_argument, NULL, 'c' },
{ "no-verify", no_argument, NULL, 'n' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
};
static void usage(const char *progname)
static void usage(void)
{
fprintf(stderr,
"usage: %s --cert <certfile> <efi-boot-image>\n"
"options:\n"
printf("Usage: %s [options] --cert <certfile> <efi-boot-image>\n"
"Verify a UEFI secure boot image.\n\n"
"Options:\n"
"\t--cert <certfile> certificate (x509 certificate)\n"
"\t--no-verify don't perform certificate verification\n",
progname);
toolname);
}
static void version(void)
{
printf("%s %s\n", toolname, VERSION);
}
int load_cert(X509_STORE *certs, const char *filename)
@ -135,12 +144,18 @@ int main(int argc, char **argv)
case 'n':
verify = 0;
break;
case 'V':
version();
return EXIT_SUCCESS;
case 'h':
usage();
return EXIT_SUCCESS;
}
}
if (argc != optind + 1) {
usage(argv[0]);
usage();
return EXIT_FAILURE;
}