1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
4 * This file is part of Evergreen.
6 * Evergreen is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation, either version 2 of the License,
9 * or (at your option) any later version.
11 * Evergreen is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Evergreen. If not, see <http://www.gnu.org/licenses/>.
19 * This Source Code Form is derived from code that was originally
20 * subject to the terms of the Mozilla Public License, v. 2.0 and
21 * included in Evergreen. You may, therefore, use this Source Code
22 * Form under the terms of the Mozilla Public License 2.0. This
23 * licensing option does not affect the larger Evergreen project, only
24 * the Source Code Forms bearing this exception are affected. If a
25 * copy of the MPL was not distributed with this file, You can obtain
26 * one at http://mozilla.org/MPL/2.0/.
34 #include "mar_cmdline.h"
44 static void print_usage() {
46 printf("Create a MAR file:\n");
47 printf(" mar [-H MARChannelID] [-V ProductVersion] [-C workingDir] "
48 "{-c|-x|-t|-T} archive.mar [files...]\n");
49 printf("Print information on a MAR file:\n");
50 printf(" mar [-H MARChannelID] [-V ProductVersion] [-C workingDir] "
51 "-i unsigned_archive_to_refresh.mar\n");
52 printf("This program does not handle unicode file paths properly\n");
55 static int mar_test_callback(MarFile *mar,
58 printf("%u\t0%o\t%s\n", item->length, item->flags, item->name);
62 static int mar_test(const char *path) {
69 printf("SIZE\tMODE\tNAME\n");
70 mar_enum_items(mar, mar_test_callback, NULL);
76 int main(int argc, char **argv) {
77 char *MARChannelID = MAR_CHANNEL_ID;
78 char *productVersion = MOZ_APP_VERSION;
88 if (argv[1][0] == '-' && (argv[1][1] == 'c' ||
89 argv[1][1] == 't' || argv[1][1] == 'x' ||
90 argv[1][1] == 'i' || argv[1][1] == 'T')) {
92 /* -C workingdirectory */
93 } else if (argv[1][0] == '-' && argv[1][1] == 'C') {
98 } else if (argv[1][0] == '-' && argv[1][1] == 'H') {
99 MARChannelID = argv[2];
102 /* Product Version */
103 } else if (argv[1][0] == '-' && argv[1][1] == 'V') {
104 productVersion = argv[2];
114 if (argv[1][0] != '-') {
119 switch (argv[1][1]) {
121 struct ProductInformationBlock infoBlock;
122 infoBlock.MARChannelID = MARChannelID;
123 infoBlock.productVersion = productVersion;
124 return mar_create(argv[2], argc - 3, argv + 3, &infoBlock);
127 struct ProductInformationBlock infoBlock;
128 infoBlock.MARChannelID = MARChannelID;
129 infoBlock.productVersion = productVersion;
130 return refresh_product_info_block(argv[2], &infoBlock);
133 struct ProductInformationBlock infoBlock;
134 uint32_t numSignatures, numAdditionalBlocks;
135 int hasSignatureBlock, hasAdditionalBlock;
136 if (!get_mar_file_info(argv[2],
140 NULL, &numAdditionalBlocks)) {
141 if (hasSignatureBlock) {
142 printf("Signature block found with %d signature%s\n",
144 numSignatures != 1 ? "s" : "");
146 if (hasAdditionalBlock) {
147 printf("%d additional block%s found:\n",
149 numAdditionalBlocks != 1 ? "s" : "");
152 rv = read_product_info_block(argv[2], &infoBlock);
154 printf(" - Product Information Block:\n");
155 printf(" - MAR channel name: %s\n"
156 " - Product version: %s\n",
157 infoBlock.MARChannelID,
158 infoBlock.productVersion);
159 free((void *)infoBlock.MARChannelID);
160 free((void *)infoBlock.productVersion);
164 /* The fall through from 'T' to 't' is intentional */
167 return mar_test(argv[2]);
169 /* Extract a MAR file */
171 return mar_extract(argv[2]);