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 sbuild::_;
00042 using schroot::options_base;
00043 using namespace dchroot;
00044
00045 main_base::main_base (std::string const& program_name,
00046 std::string const& program_usage,
00047 schroot::options_base::ptr& options):
00048 schroot::main_base(program_name, program_usage, options, true),
00049 use_dchroot_conf(false)
00050 {
00051 }
00052
00053 main_base::~main_base ()
00054 {
00055 }
00056
00057 void
00058 main_base::action_config ()
00059 {
00060 std::cout << "# "
00061
00062
00063
00064 << format(_("schroot configuration generated by %1% %2% on %3%"))
00065 % this->program_name % VERSION % sbuild::date(time(0))
00066 << endl;
00067 if (this->use_dchroot_conf)
00068 {
00069
00070 std::cout << "# " << endl
00071 << "# "
00072
00073
00074
00075 << _("To allow users access to the chroots, use the users or groups keys.") << endl;
00076 std::cout << "# "
00077
00078
00079
00080
00081 << _("To allow password-less root access, use the root-users or root-groups keys.") << endl;
00082 std::cout << "# "
00083
00084 << format(_("Remove '%1%' to use the new configuration."))
00085 % DCHROOT_CONF
00086 << endl;
00087 }
00088 std::cout << endl;
00089 this->config->print_chroot_config(this->chroots, std::cout);
00090 }
00091
00092 void
00093 main_base::action_list ()
00094 {
00095 this->config->print_chroot_list_simple(std::cout);
00096 }
00097
00098 void
00099 main_base::compat_check ()
00100 {
00101 if (this->options->verbose)
00102 {
00103 sbuild::log_warning()
00104
00105 << format(_("Running schroot in %1% compatibility mode"))
00106 % this->program_name
00107 << endl;
00108 sbuild::log_info()
00109
00110
00111 << _("Run \"schroot\" for full capabilities")
00112 << endl;
00113 }
00114 }
00115
00116 void
00117 main_base::check_dchroot_conf ()
00118 {
00119 this->use_dchroot_conf = false;
00120 struct stat statbuf;
00121 if (stat(DCHROOT_CONF, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
00122 {
00123 this->use_dchroot_conf = true;
00124
00125 if (this->options->verbose)
00126 {
00127 sbuild::log_warning()
00128
00129
00130 << format(_("Using %1% configuration file: '%2%'"))
00131 % this->program_name % DCHROOT_CONF
00132 << endl;
00133 sbuild::log_info()
00134 << format(_("Run \"%1%\""))
00135 % "dchroot --config >> " SCHROOT_CONF
00136 << endl;
00137 sbuild::log_info()
00138 << _("to migrate to a schroot configuration.")
00139 << endl;
00140 sbuild::log_info()
00141 << format(_("Edit '%1%' to add appropriate user and/or group access."))
00142 % SCHROOT_CONF
00143 << endl;
00144 sbuild::log_info()
00145 << format(_("Remove '%1%' to use the new configuration."))
00146 % DCHROOT_CONF
00147 << endl;
00148 }
00149 }
00150 }