00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include "dchroot-main.h"
00023 #include "dchroot-chroot-config.h"
00024 #include "dchroot-session.h"
00025
00026 #include <cstdlib>
00027 #include <iostream>
00028 #include <locale>
00029
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <termios.h>
00033 #include <unistd.h>
00034
00035 #include <boost/format.hpp>
00036
00037 #include <syslog.h>
00038
00039 using std::endl;
00040 using boost::format;
00041 using schroot::options_base;
00042 using namespace dchroot;
00043
00044 main_base::main_base (std::string const& program_name,
00045 std::string const& program_usage,
00046 schroot::options_base::ptr& options):
00047 schroot::main_base(program_name, program_usage, options),
00048 use_dchroot_conf(false)
00049 {
00050 }
00051
00052 main_base::~main_base ()
00053 {
00054 }
00055
00056 void
00057 main_base::action_config ()
00058 {
00059 std::cout << "# "
00060
00061
00062
00063 << format(_("schroot configuration generated by %1% %2% on %3%"))
00064 % this->program_name % VERSION % sbuild::date(time(0))
00065 << endl;
00066 if (this->use_dchroot_conf)
00067 {
00068
00069 std::cout << "# " << endl
00070 << "# "
00071
00072
00073
00074 << _("To allow users access to the chroots, use the users or groups keys.") << endl;
00075 std::cout << "# "
00076
00077
00078
00079
00080 << _("To allow password-less root access, use the root-users or root-groups keys.") << endl;
00081 std::cout << "# "
00082
00083 << format(_("Remove '%1%' to use the new configuration."))
00084 % DCHROOT_CONF
00085 << endl;
00086 }
00087 std::cout << endl;
00088 this->config->print_chroot_config(this->chroots, std::cout);
00089 }
00090
00091 void
00092 main_base::action_list ()
00093 {
00094 this->config->print_chroot_list_simple(std::cout);
00095 }
00096
00097 void
00098 main_base::compat_check ()
00099 {
00100 if (this->options->verbose)
00101 {
00102 sbuild::log_warning()
00103
00104 << format(_("Running schroot in %1% compatibility mode"))
00105 % this->program_name
00106 << endl;
00107 sbuild::log_info()
00108
00109
00110 << _("Run \"schroot\" for full capabilities")
00111 << endl;
00112 }
00113 }
00114
00115 void
00116 main_base::check_dchroot_conf ()
00117 {
00118 this->use_dchroot_conf = false;
00119 struct stat statbuf;
00120 if (stat(DCHROOT_CONF, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
00121 {
00122 this->use_dchroot_conf = true;
00123
00124 if (this->options->verbose)
00125 {
00126 sbuild::log_warning()
00127
00128
00129 << format(_("Using %1% configuration file: '%2%'"))
00130 % this->program_name % DCHROOT_CONF
00131 << endl;
00132 sbuild::log_info()
00133 << format(_("Run \"%1%\""))
00134 % "dchroot --config >> " SCHROOT_CONF
00135 << endl;
00136 sbuild::log_info()
00137 << _("to migrate to a schroot configuration.")
00138 << endl;
00139 sbuild::log_info()
00140 << format(_("Edit '%1%' to add appropriate user and/or group access."))
00141 % SCHROOT_CONF
00142 << endl;
00143 sbuild::log_info()
00144 << format(_("Remove '%1%' to use the new configuration."))
00145 % DCHROOT_CONF
00146 << endl;
00147 }
00148 }
00149 }