summaryrefslogtreecommitdiffstats
path: root/tools/ideviceprovision.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ideviceprovision.c')
-rw-r--r--tools/ideviceprovision.c240
1 files changed, 127 insertions, 113 deletions
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c
index 754b84d..981a7ee 100644
--- a/tools/ideviceprovision.c
+++ b/tools/ideviceprovision.c
@@ -29,6 +29,7 @@
29#include <stdio.h> 29#include <stdio.h>
30#include <stdlib.h> 30#include <stdlib.h>
31#include <string.h> 31#include <string.h>
32#include <getopt.h>
32#include <sys/stat.h> 33#include <sys/stat.h>
33#include <errno.h> 34#include <errno.h>
34#ifndef WIN32 35#ifndef WIN32
@@ -46,40 +47,40 @@
46#include <libimobiledevice/misagent.h> 47#include <libimobiledevice/misagent.h>
47#include <libimobiledevice-glue/utils.h> 48#include <libimobiledevice-glue/utils.h>
48 49
49static void print_usage(int argc, char **argv) 50static void print_usage(int argc, char **argv, int is_error)
50{ 51{
51 char *name = NULL; 52 char *name = strrchr(argv[0], '/');
52 53 fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS] COMMAND\n", (name ? name + 1: argv[0]));
53 name = strrchr(argv[0], '/'); 54 fprintf(is_error ? stderr : stdout,
54 printf("Usage: %s [OPTIONS] COMMAND\n", (name ? name + 1: argv[0])); 55 "\n"
55 printf("\n"); 56 "Manage provisioning profiles on a device.\n"
56 printf("Manage provisioning profiles on a device.\n"); 57 "\n"
57 printf("\n"); 58 "Where COMMAND is one of:\n"
58 printf("Where COMMAND is one of:\n"); 59 " install FILE Installs the provisioning profile specified by FILE.\n"
59 printf(" install FILE\tInstalls the provisioning profile specified by FILE.\n"); 60 " A valid .mobileprovision file is expected.\n"
60 printf(" \tA valid .mobileprovision file is expected.\n"); 61 " list Get a list of all provisioning profiles on the device.\n"
61 printf(" list\t\tGet a list of all provisioning profiles on the device.\n"); 62 " copy PATH Retrieves all provisioning profiles from the device and\n"
62 printf(" copy PATH\tRetrieves all provisioning profiles from the device and\n"); 63 " stores them into the existing directory specified by PATH.\n"
63 printf(" \tstores them into the existing directory specified by PATH.\n"); 64 " The files will be stored as UUID.mobileprovision\n"
64 printf(" \tThe files will be stored as UUID.mobileprovision\n"); 65 " copy UUID PATH Retrieves the provisioning profile identified by UUID\n"
65 printf(" copy UUID PATH Retrieves the provisioning profile identified by UUID\n"); 66 " from the device and stores it into the existing directory\n"
66 printf(" \tfrom the device and stores it into the existing directory\n"); 67 " specified by PATH. The file will be stored as UUID.mobileprovision.\n"
67 printf(" \tspecified by PATH. The file will be stored as UUID.mobileprovision.\n"); 68 " remove UUID Removes the provisioning profile identified by UUID.\n"
68 printf(" remove UUID\tRemoves the provisioning profile identified by UUID.\n"); 69 " remove-all Removes all installed provisioning profiles.\n"
69 printf(" remove-all\tRemoves all installed provisioning profiles.\n"); 70 " dump FILE Prints detailed information about the provisioning profile\n"
70 printf(" dump FILE\tPrints detailed information about the provisioning profile\n"); 71 " specified by FILE.\n"
71 printf(" \tspecified by FILE.\n"); 72 "\n"
72 printf("\n"); 73 "The following OPTIONS are accepted:\n"
73 printf("The following OPTIONS are accepted:\n"); 74 " -u, --udid UDID target specific device by UDID\n"
74 printf(" -u, --udid UDID target specific device by UDID\n"); 75 " -n, --network connect to network device\n"
75 printf(" -n, --network connect to network device\n"); 76 " -x, --xml print XML output when using the 'dump' command\n"
76 printf(" -x, --xml print XML output when using the 'dump' command\n"); 77 " -d, --debug enable communication debugging\n"
77 printf(" -d, --debug enable communication debugging\n"); 78 " -h, --help prints usage information\n"
78 printf(" -h, --help prints usage information\n"); 79 " -v, --version prints version information\n"
79 printf(" -v, --version prints version information\n"); 80 "\n"
80 printf("\n"); 81 "Homepage: <" PACKAGE_URL ">\n"
81 printf("Homepage: <" PACKAGE_URL ">\n"); 82 "Bug Reports: <" PACKAGE_BUGREPORT ">\n"
82 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n"); 83 );
83} 84}
84 85
85enum { 86enum {
@@ -302,102 +303,115 @@ int main(int argc, char *argv[])
302 const char* param = NULL; 303 const char* param = NULL;
303 const char* param2 = NULL; 304 const char* param2 = NULL;
304 int use_network = 0; 305 int use_network = 0;
306 int c = 0;
307 const struct option longopts[] = {
308 { "debug", no_argument, NULL, 'd' },
309 { "help", no_argument, NULL, 'h' },
310 { "udid", required_argument, NULL, 'u' },
311 { "network", no_argument, NULL, 'n' },
312 { "version", no_argument, NULL, 'v' },
313 { "xml", no_argument, NULL, 'x' },
314 { NULL, 0, NULL, 0}
315 };
305 316
306#ifndef WIN32 317#ifndef WIN32
307 signal(SIGPIPE, SIG_IGN); 318 signal(SIGPIPE, SIG_IGN);
308#endif 319#endif
309 /* parse cmdline args */ 320 /* parse cmdline args */
310 for (i = 1; i < argc; i++) { 321 while ((c = getopt_long(argc, argv, "dhu:nvx", longopts, NULL)) != -1) {
311 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { 322 switch (c) {
323 case 'd':
312 idevice_set_debug_level(1); 324 idevice_set_debug_level(1);
313 continue; 325 break;
314 } 326 case 'u':
315 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { 327 if (!*optarg) {
316 i++; 328 fprintf(stderr, "ERROR: UDID argument must not be empty!\n");
317 if (!argv[i] || !*argv[i]) { 329 print_usage(argc, argv, 1);
318 print_usage(argc, argv); 330 return 2;
319 return 0;
320 } 331 }
321 udid = argv[i]; 332 udid = optarg;
322 continue; 333 break;
323 } 334 case 'n':
324 else if (!strcmp(argv[i], "-n") || !strcmp(argv[i], "--network")) {
325 use_network = 1; 335 use_network = 1;
326 continue; 336 break;
327 } 337 case 'h':
328 else if (!strcmp(argv[i], "install")) { 338 print_usage(argc, argv, 0);
329 i++; 339 return 0;
330 if (!argv[i] || (strlen(argv[i]) < 1)) { 340 case 'v':
331 print_usage(argc, argv); 341 printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION);
332 return 0; 342 return 0;
333 } 343 case 'x':
334 param = argv[i]; 344 output_xml = 1;
335 op = OP_INSTALL; 345 break;
336 continue; 346 default:
337 } 347 print_usage(argc, argv, 1);
338 else if (!strcmp(argv[i], "list")) { 348 return 2;
339 op = OP_LIST;
340 }
341 else if (!strcmp(argv[i], "copy")) {
342 i++;
343 if (!argv[i] || (strlen(argv[i]) < 1)) {
344 print_usage(argc, argv);
345 return 0;
346 }
347 param = argv[i];
348 op = OP_COPY;
349 i++;
350 if (argv[i] && (strlen(argv[i]) > 0)) {
351 param2 = argv[i];
352 }
353 continue;
354 }
355 else if (!strcmp(argv[i], "remove")) {
356 i++;
357 if (!argv[i] || (strlen(argv[i]) < 1)) {
358 print_usage(argc, argv);
359 return 0;
360 }
361 param = argv[i];
362 op = OP_REMOVE;
363 continue;
364 }
365 else if (!strcmp(argv[i], "remove-all")) {
366 i++;
367 op = OP_REMOVE;
368 continue;
369 } 349 }
370 else if (!strcmp(argv[i], "dump")) { 350 }
371 i++; 351 argc -= optind;
372 if (!argv[i] || (strlen(argv[i]) < 1)) { 352 argv += optind;
373 print_usage(argc, argv); 353
374 return 0; 354 if (!argv[0]) {
375 } 355 fprintf(stderr, "ERROR: Missing command.\n");
376 param = argv[i]; 356 print_usage(argc+optind, argv-optind, 1);
377 op = OP_DUMP; 357 return 2;
378 continue; 358 }
359
360 i = 0;
361 if (!strcmp(argv[i], "install")) {
362 op = OP_INSTALL;
363 i++;
364 if (!argv[i] || !*argv[i]) {
365 fprintf(stderr, "Missing argument for 'install' command.\n");
366 print_usage(argc+optind, argv-optind, 1);
367 return 2;
379 } 368 }
380 else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { 369 param = argv[i];
381 output_xml = 1; 370 }
382 continue; 371 else if (!strcmp(argv[i], "list")) {
372 op = OP_LIST;
373 }
374 else if (!strcmp(argv[i], "copy")) {
375 op = OP_COPY;
376 i++;
377 if (!argv[i] || !*argv[i]) {
378 fprintf(stderr, "Missing argument for 'copy' command.\n");
379 print_usage(argc+optind, argv-optind, 1);
380 return 2;
383 } 381 }
384 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { 382 param = argv[i];
385 print_usage(argc, argv); 383 i++;
386 return 0; 384 if (argv[i] && (strlen(argv[i]) > 0)) {
385 param2 = argv[i];
387 } 386 }
388 else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { 387 }
389 printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); 388 else if (!strcmp(argv[i], "remove")) {
390 return 0; 389 op = OP_REMOVE;
390 i++;
391 if (!argv[i] || !*argv[i]) {
392 fprintf(stderr, "Missing argument for 'remove' command.\n");
393 print_usage(argc+optind, argv-optind, 1);
394 return 2;
391 } 395 }
392 else { 396 param = argv[i];
393 print_usage(argc, argv); 397 }
394 return 0; 398 else if (!strcmp(argv[i], "remove-all")) {
399 op = OP_REMOVE;
400 }
401 else if (!strcmp(argv[i], "dump")) {
402 op = OP_DUMP;
403 i++;
404 if (!argv[i] || !*argv[i]) {
405 fprintf(stderr, "Missing argument for 'remove' command.\n");
406 print_usage(argc+optind, argv-optind, 1);
407 return 2;
395 } 408 }
409 param = argv[i];
396 } 410 }
397
398 if ((op == -1) || (op >= NUM_OPS)) { 411 if ((op == -1) || (op >= NUM_OPS)) {
399 print_usage(argc, argv); 412 fprintf(stderr, "ERROR: Unsupported command '%s'\n", argv[i]);
400 return 0; 413 print_usage(argc+optind, argv-optind, 1);
414 return 2;
401 } 415 }
402 416
403 if (op == OP_DUMP) { 417 if (op == OP_DUMP) {