Commit | Line | Data |
---|---|---|
9ac667e6 SR |
1 | // |
2 | // pkgutils | |
3 | // | |
4 | // Copyright (c) 2000-2005 Per Liden | |
6fe55c25 | 5 | // Copyright (c) 2006-2007 by CRUX team (http://crux.nu) |
9ac667e6 SR |
6 | // |
7 | // This program is free software; you can redistribute it and/or modify | |
8 | // it under the terms of the GNU General Public License as published by | |
9 | // the Free Software Foundation; either version 2 of the License, or | |
10 | // (at your option) any later version. | |
11 | // | |
12 | // This program is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License | |
18 | // along with this program; if not, write to the Free Software | |
19 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
20 | // USA. | |
21 | // | |
22 | ||
23 | #include "pkgrm.h" | |
24 | #include <unistd.h> | |
25 | ||
26 | void pkgrm::run(int argc, char** argv) | |
27 | { | |
28 | // | |
29 | // Check command line options | |
30 | // | |
31 | string o_package; | |
32 | string o_root; | |
33 | ||
34 | for (int i = 1; i < argc; i++) { | |
35 | string option(argv[i]); | |
36 | if (option == "-r" || option == "--root") { | |
37 | assert_argument(argv, argc, i); | |
38 | o_root = argv[i + 1]; | |
39 | i++; | |
40 | } else if (option[0] == '-' || !o_package.empty()) { | |
41 | throw runtime_error("invalid option " + option); | |
42 | } else { | |
43 | o_package = option; | |
44 | } | |
45 | } | |
46 | ||
47 | if (o_package.empty()) | |
48 | throw runtime_error("option missing"); | |
49 | ||
50 | // | |
51 | // Check UID | |
52 | // | |
53 | if (getuid()) | |
54 | throw runtime_error("only root can remove packages"); | |
55 | ||
56 | // | |
57 | // Remove package | |
58 | // | |
59 | { | |
60 | db_lock lock(o_root, true); | |
61 | db_open(o_root); | |
62 | ||
63 | if (!db_find_pkg(o_package)) | |
64 | throw runtime_error("package " + o_package + " not installed"); | |
65 | ||
66 | db_rm_pkg(o_package); | |
67 | ldconfig(); | |
68 | db_commit(); | |
69 | } | |
70 | } | |
71 | ||
72 | void pkgrm::print_help() const | |
73 | { | |
74 | cout << "usage: " << utilname << " [options] <package>" << endl | |
75 | << "options:" << endl | |
76 | << " -r, --root <path> specify alternative installation root" << endl | |
77 | << " -v, --version print version and exit" << endl | |
78 | << " -h, --help print help and exit" << endl; | |
79 | } |