1 | /* Copyright © 2005-2007 Roger Leigh <rleigh@debian.org> |
---|
2 | * |
---|
3 | * schroot is free software: you can redistribute it and/or modify it |
---|
4 | * under the terms of the GNU General Public License as published by |
---|
5 | * the Free Software Foundation, either version 3 of the License, or |
---|
6 | * (at your option) any later version. |
---|
7 | * |
---|
8 | * schroot is distributed in the hope that it will be useful, but |
---|
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | * General Public License for more details. |
---|
12 | * |
---|
13 | * You should have received a copy of the GNU General Public License |
---|
14 | * along with this program. If not, see |
---|
15 | * <http://www.gnu.org/licenses/>. |
---|
16 | * |
---|
17 | *********************************************************************/ |
---|
18 | |
---|
19 | #include <config.h> |
---|
20 | |
---|
21 | #include "dchroot-main.h" |
---|
22 | #include "dchroot-chroot-config.h" |
---|
23 | #include "dchroot-session.h" |
---|
24 | |
---|
25 | #include <cstdlib> |
---|
26 | #include <iostream> |
---|
27 | #include <locale> |
---|
28 | |
---|
29 | #include <sys/types.h> |
---|
30 | #include <sys/stat.h> |
---|
31 | #include <termios.h> |
---|
32 | #include <unistd.h> |
---|
33 | |
---|
34 | #include <boost/format.hpp> |
---|
35 | |
---|
36 | #include <syslog.h> |
---|
37 | |
---|
38 | using std::endl; |
---|
39 | using boost::format; |
---|
40 | using sbuild::_; |
---|
41 | using schroot::options_base; |
---|
42 | using namespace dchroot; |
---|
43 | |
---|
44 | main_base::main_base (std::string const& program_name, |
---|
45 | std::string const& program_usage, |
---|
46 | schroot::options_base::ptr& options): |
---|
47 | schroot::main_base(program_name, program_usage, options, true), |
---|
48 | use_dchroot_conf(false) |
---|
49 | { |
---|
50 | } |
---|
51 | |
---|
52 | main_base::~main_base () |
---|
53 | { |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | main_base::action_config () |
---|
58 | { |
---|
59 | std::cout << "# " |
---|
60 | // TRANSLATORS: %1% = program name |
---|
61 | // TRANSLATORS: %2% = program version |
---|
62 | // TRANSLATORS: %3% = current date |
---|
63 | << format(_("schroot configuration generated by %1% %2% on %3%")) |
---|
64 | % this->program_name % VERSION % sbuild::date(time(0)) |
---|
65 | << endl; |
---|
66 | if (this->use_dchroot_conf) |
---|
67 | { |
---|
68 | // Help text at head of new config. |
---|
69 | std::cout << "# " << endl |
---|
70 | << "# " |
---|
71 | // TODO: Quote "users" and "groups". |
---|
72 | // TRANSLATORS: Do not translate "users" and "groups"; |
---|
73 | // these are keywords used in the configuration file. |
---|
74 | << _("To allow users access to the chroots, use the users or groups keys.") << endl; |
---|
75 | std::cout << "# " |
---|
76 | // TODO: Quote "root-users" and "root-groups". |
---|
77 | // TRANSLATORS: Do not translate "root-users" and |
---|
78 | // "root-groups"; these are keywords used in the |
---|
79 | // configuration file. |
---|
80 | << _("To allow password-less root access, use the root-users or root-groups keys.") << endl; |
---|
81 | std::cout << "# " |
---|
82 | // TRANSLATORS: %1% = file |
---|
83 | << format(_("Remove '%1%' to use the new configuration.")) |
---|
84 | % DCHROOT_CONF |
---|
85 | << endl; |
---|
86 | } |
---|
87 | std::cout << endl; |
---|
88 | this->config->print_chroot_config(this->chroots, std::cout); |
---|
89 | } |
---|
90 | |
---|
91 | void |
---|
92 | main_base::action_list () |
---|
93 | { |
---|
94 | this->config->print_chroot_list_simple(std::cout); |
---|
95 | } |
---|
96 | |
---|
97 | void |
---|
98 | main_base::compat_check () |
---|
99 | { |
---|
100 | if (this->options->verbose) |
---|
101 | { |
---|
102 | sbuild::log_warning() |
---|
103 | // TRANSLATORS: %1% = program name |
---|
104 | << format(_("Running schroot in %1% compatibility mode")) |
---|
105 | % this->program_name |
---|
106 | << endl; |
---|
107 | sbuild::log_info() |
---|
108 | // TRANSLATORS: "full capabilities" in this context means "all |
---|
109 | // features" |
---|
110 | << _("Run \"schroot\" for full capabilities") |
---|
111 | << endl; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | main_base::check_dchroot_conf () |
---|
117 | { |
---|
118 | this->use_dchroot_conf = false; |
---|
119 | struct stat statbuf; |
---|
120 | if (stat(DCHROOT_CONF, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode)) |
---|
121 | { |
---|
122 | this->use_dchroot_conf = true; |
---|
123 | |
---|
124 | if (this->options->verbose) |
---|
125 | { |
---|
126 | sbuild::log_warning() |
---|
127 | // TRANSLATORS: %1% = program name |
---|
128 | // TRANSLATORS: %2% = configuration file |
---|
129 | << format(_("Using %1% configuration file: '%2%'")) |
---|
130 | % this->program_name % DCHROOT_CONF |
---|
131 | << endl; |
---|
132 | sbuild::log_info() |
---|
133 | << format(_("Run \"%1%\"")) |
---|
134 | % "dchroot --config >> " SCHROOT_CONF |
---|
135 | << endl; |
---|
136 | sbuild::log_info() |
---|
137 | << _("to migrate to a schroot configuration.") |
---|
138 | << endl; |
---|
139 | sbuild::log_info() |
---|
140 | << format(_("Edit '%1%' to add appropriate user and/or group access.")) |
---|
141 | % SCHROOT_CONF |
---|
142 | << endl; |
---|
143 | sbuild::log_info() |
---|
144 | << format(_("Remove '%1%' to use the new configuration.")) |
---|
145 | % DCHROOT_CONF |
---|
146 | << endl; |
---|
147 | } |
---|
148 | } |
---|
149 | } |
---|