2 * dpkg - main program for package management
3 * select.c - by-hand (rather than dselect-based) package selection
5 * Copyright © 1995,1996 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2006, 2008-2015 Guillem Jover <guillem@debian.org>
7 * Copyright © 2011 Linaro Limited
8 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
10 * This is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 #include <dpkg/i18n.h>
33 #include <dpkg/c-ctype.h>
34 #include <dpkg/dpkg.h>
35 #include <dpkg/dpkg-db.h>
36 #include <dpkg/pkg-array.h>
37 #include <dpkg/pkg-show.h>
38 #include <dpkg/pkg-spec.h>
39 #include <dpkg/options.h>
45 static void getsel1package(struct pkginfo *pkg) {
49 if (pkg->want == PKG_WANT_UNKNOWN)
51 pkgname = pkg_name(pkg, pnaw_nonambig);
57 printf("%s%.*s%s\n", pkgname, l, "\t\t\t\t\t\t", pkg_want_name(pkg));
61 getselections(const char *const *argv)
63 struct pkg_array array;
68 modstatdb_open(msdbrw_readonly);
70 pkg_array_init_from_db(&array);
71 pkg_array_sort(&array, pkg_sorter_by_nonambig_name_arch);
74 for (i = 0; i < array.n_pkgs; i++) {
76 if (pkg->status == PKG_STAT_NOTINSTALLED)
81 while ((thisarg= *argv++)) {
82 struct pkg_spec pkgspec;
85 pkg_spec_init(&pkgspec, PKG_SPEC_PATTERNS | PKG_SPEC_ARCH_WILDCARD);
86 pkg_spec_parse(&pkgspec, thisarg);
88 for (i = 0; i < array.n_pkgs; i++) {
90 if (!pkg_spec_match_pkg(&pkgspec, pkg, &pkg->installed))
92 getsel1package(pkg); found++;
95 notice(_("no packages found matching %s"), thisarg);
97 pkg_spec_destroy(&pkgspec);
101 m_output(stdout, _("<standard output>"));
102 m_output(stderr, _("<standard error>"));
104 pkg_array_destroy(&array);
106 modstatdb_shutdown();
112 setselections(const char *const *argv)
114 enum modstatdb_rw msdbflags;
115 const struct namevalue *nv;
118 struct varbuf namevb = VARBUF_INIT;
119 struct varbuf selvb = VARBUF_INIT;
120 bool db_possibly_outdated = false;
123 badusage(_("--%s takes no arguments"), cipaction->olong);
125 msdbflags = msdbrw_available_readonly;
127 msdbflags |= msdbrw_readonly;
129 msdbflags |= msdbrw_write;
131 modstatdb_open(msdbflags);
132 pkg_infodb_upgrade();
136 struct dpkg_error err;
142 } while (c != EOF && c_isspace(c));
145 do { c= getchar(); if (c == '\n') lno++; } while (c != EOF && c != '\n');
149 varbuf_reset(&namevb);
150 while (!c_isspace(c)) {
151 varbuf_add_char(&namevb, c);
154 ohshit(_("unexpected end of file in package name at line %d"), lno);
155 if (c == '\n') ohshit(_("unexpected end of line in package name at line %d"),lno);
157 varbuf_end_str(&namevb);
159 while (c != EOF && c_isspace(c)) {
162 ohshit(_("unexpected end of file after package name at line %d"), lno);
163 if (c == '\n') ohshit(_("unexpected end of line after package name at line %d"),lno);
166 varbuf_reset(&selvb);
167 while (c != EOF && !c_isspace(c)) {
168 varbuf_add_char(&selvb, c);
171 varbuf_end_str(&selvb);
173 while (c != EOF && c != '\n') {
176 ohshit(_("unexpected data after package and selection at line %d"),lno);
178 pkg = pkg_spec_parse_pkg(namevb.buf, &err);
180 ohshit(_("illegal package name at line %d: %.250s"), lno, err.str);
182 if (!pkg_is_informative(pkg, &pkg->installed) &&
183 !pkg_is_informative(pkg, &pkg->available)) {
184 db_possibly_outdated = true;
185 warning(_("package not in status nor available database at line %d: %.250s"), lno, namevb.buf);
189 nv = namevalue_find_by_name(wantinfos, selvb.buf);
191 ohshit(_("unknown wanted status at line %d: %.250s"), lno, selvb.buf);
193 pkg_set_want(pkg, nv->value);
197 if (ferror(stdin)) ohshite(_("read error on standard input"));
198 modstatdb_shutdown();
199 varbuf_destroy(&namevb);
200 varbuf_destroy(&selvb);
202 if (db_possibly_outdated)
203 warning(_("found unknown packages; this might mean the available database\n"
204 "is outdated, and needs to be updated through a frontend method;\n"
205 "please see the FAQ <https://wiki.debian.org/Teams/Dpkg/FAQ>"));
211 clearselections(const char *const *argv)
213 enum modstatdb_rw msdbflags;
214 struct pkgiterator *iter;
218 badusage(_("--%s takes no arguments"), cipaction->olong);
221 msdbflags = msdbrw_readonly;
223 msdbflags = msdbrw_write;
225 modstatdb_open(msdbflags);
226 pkg_infodb_upgrade();
228 iter = pkg_db_iter_new();
229 while ((pkg = pkg_db_iter_next_pkg(iter))) {
230 if (!pkg->installed.essential)
231 pkg_set_want(pkg, PKG_WANT_DEINSTALL);
233 pkg_db_iter_free(iter);
235 modstatdb_shutdown();