Branch data Line data Source code
1 : : /*
2 : : * dpkg-split - splitting and joining of multipart *.deb archives
3 : : * main.c - main program
4 : : *
5 : : * Copyright © 1994-1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 : : * Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
7 : : *
8 : : * This is free software; you can redistribute it and/or modify
9 : : * it under the terms of the GNU General Public License as published by
10 : : * the Free Software Foundation; either version 2 of the License, or
11 : : * (at your option) any later version.
12 : : *
13 : : * This is distributed in the hope that it will be useful,
14 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : : * GNU General Public License for more details.
17 : : *
18 : : * You should have received a copy of the GNU General Public License
19 : : * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 : : */
21 : : #include <config.h>
22 : : #include <compat.h>
23 : :
24 : : #include <sys/types.h>
25 : :
26 : : #include <errno.h>
27 : : #include <limits.h>
28 : : #include <inttypes.h>
29 : : #ifdef HAVE_LOCALE_H
30 : : #include <locale.h>
31 : : #endif
32 : : #include <string.h>
33 : : #include <stdlib.h>
34 : : #include <stdio.h>
35 : :
36 : : #include <dpkg/macros.h>
37 : : #include <dpkg/i18n.h>
38 : : #include <dpkg/dpkg.h>
39 : : #include <dpkg/dpkg-db.h>
40 : : #include <dpkg/debug.h>
41 : : #include <dpkg/fsys.h>
42 : : #include <dpkg/options.h>
43 : :
44 : : #include "dpkg-split.h"
45 : :
46 : : static int
47 : 21 : printversion(const char *const *argv)
48 : : {
49 : 21 : printf(_("Debian '%s' package split/join tool; version %s.\n"),
50 : : SPLITTER, PACKAGE_RELEASE);
51 : :
52 : 21 : printf(_(
53 : : "This is free software; see the GNU General Public License version 2 or\n"
54 : : "later for copying conditions. There is NO warranty.\n"));
55 : :
56 : 21 : m_output(stdout, _("<standard output>"));
57 : :
58 : 21 : return 0;
59 : : }
60 : :
61 : : static int
62 : 1 : usage(const char *const *argv)
63 : : {
64 : 1 : printf(_(
65 : : "Usage: %s [<option> ...] <command>\n"
66 : : "\n"), SPLITTER);
67 : :
68 : 1 : printf(_(
69 : : "Commands:\n"
70 : : " -s|--split <file> [<prefix>] Split an archive.\n"
71 : : " -j|--join <part> <part> ... Join parts together.\n"
72 : : " -I|--info <part> ... Display info about a part.\n"
73 : : " -a|--auto -o <complete> <part> Auto-accumulate parts.\n"
74 : : " -l|--listq List unmatched pieces.\n"
75 : : " -d|--discard [<filename> ...] Discard unmatched pieces.\n"
76 : : "\n"));
77 : :
78 : 1 : printf(_(
79 : : " -?, --help Show this help message.\n"
80 : : " --version Show the version.\n"
81 : : "\n"));
82 : :
83 : 1 : printf(_(
84 : : "Options:\n"
85 : : " --depotdir <directory> Use <directory> instead of %s/%s.\n"
86 : : " --admindir <directory> Use <directory> instead of %s.\n"
87 : : " --root <directory> Use <directory> instead of %s.\n"
88 : : " -S, --partsize <size> In KiB, for -s (default is 450).\n"
89 : : " -o, --output <file> Filename, for -j (default is\n"
90 : : " <package>_<version>_<arch>.deb).\n"
91 : : " -Q, --npquiet Be quiet when -a is not a part.\n"
92 : : " --msdos Generate 8.3 filenames.\n"
93 : : "\n"), ADMINDIR, PARTSDIR, ADMINDIR, "/");
94 : :
95 : 1 : printf(_(
96 : : "Exit status:\n"
97 : : " 0 = ok\n"
98 : : " 1 = with --auto, file is not a part\n"
99 : : " 2 = trouble\n"));
100 : :
101 : :
102 : 1 : m_output(stdout, _("<standard output>"));
103 : :
104 : 1 : return 0;
105 : : }
106 : :
107 : : static const char printforhelp[] = N_("Type dpkg-split --help for help.");
108 : :
109 : : off_t opt_maxpartsize = SPLITPARTDEFMAX;
110 : : const char *opt_depotdir;
111 : : const char *opt_outputfile = NULL;
112 : : int opt_npquiet = 0;
113 : : int opt_msdos = 0;
114 : :
115 : : void DPKG_ATTR_NORET
116 : 1 : read_fail(int rc, const char *filename, const char *what)
117 : : {
118 [ + - ]: 1 : if (rc >= 0)
119 : 1 : ohshit(_("unexpected end of file in %s in %.255s"), what, filename);
120 : : else
121 : 0 : ohshite(_("error reading %s from file %.255s"), what, filename);
122 : : }
123 : :
124 : : static void
125 : 1 : set_part_size(const struct cmdinfo *cip, const char *value)
126 : : {
127 : : off_t newpartsize;
128 : : char *endp;
129 : :
130 : 1 : errno = 0;
131 : 1 : newpartsize = strtoimax(value, &endp, 10);
132 [ + - - + ]: 1 : if (value == endp || *endp)
133 : 0 : badusage(_("invalid integer for --%s: '%.250s'"), cip->olong, value);
134 [ + - + - : 1 : if (newpartsize <= 0 || newpartsize > (INT_MAX >> 10) || errno == ERANGE)
- + ]
135 : 0 : badusage(_("part size is far too large or is not positive"));
136 : :
137 : 1 : opt_maxpartsize = newpartsize << 10;
138 [ - + ]: 1 : if (opt_maxpartsize <= HEADERALLOWANCE)
139 : 0 : badusage(_("part size must be at least %d KiB (to allow for header)"),
140 : : (HEADERALLOWANCE >> 10) + 1);
141 : 1 : }
142 : :
143 : : static const struct cmdinfo cmdinfos[]= {
144 : : ACTION("split", 's', 0, do_split),
145 : : ACTION("join", 'j', 0, do_join),
146 : : ACTION("info", 'I', 0, do_info),
147 : : ACTION("auto", 'a', 0, do_auto),
148 : : ACTION("listq", 'l', 0, do_queue),
149 : : ACTION("discard", 'd', 0, do_discard),
150 : : ACTION("help", '?', 0, usage),
151 : : ACTION("version", 0, 0, printversion),
152 : :
153 : : { "admindir", 0, 1, NULL, NULL, set_admindir, 0 },
154 : : { "root", 0, 1, NULL, NULL, set_root, 0 },
155 : : { "depotdir", 0, 1, NULL, &opt_depotdir, NULL },
156 : : { "partsize", 'S', 1, NULL, NULL, set_part_size },
157 : : { "output", 'o', 1, NULL, &opt_outputfile, NULL },
158 : : { "npquiet", 'Q', 0, &opt_npquiet, NULL, NULL, 1 },
159 : : { "msdos", 0, 0, &opt_msdos, NULL, NULL, 1 },
160 : : { NULL, 0 }
161 : : };
162 : :
163 : 34 : int main(int argc, const char *const *argv) {
164 : : int ret;
165 : :
166 : 34 : dpkg_locales_init(PACKAGE);
167 : 34 : dpkg_program_init(SPLITTER);
168 : 34 : dpkg_options_parse(&argv, cmdinfos, printforhelp);
169 : :
170 : 34 : debug(dbg_general, "root=%s admindir=%s", dpkg_fsys_get_dir(), dpkg_db_get_dir());
171 : :
172 [ + - ]: 34 : if (opt_depotdir == NULL)
173 : 34 : opt_depotdir = dpkg_db_get_path(PARTSDIR);
174 : :
175 [ - + ]: 34 : if (!cipaction) badusage(_("need an action option"));
176 : :
177 : 34 : ret = cipaction->action(argv);
178 : :
179 : 32 : m_output(stderr, _("<standard error>"));
180 : :
181 : 32 : dpkg_program_done();
182 : 32 : dpkg_locales_done();
183 : :
184 : 32 : return ret;
185 : : }
|