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