chroot calls are now generic "target env" calls.

main
Teo Mrnjavac 9 years ago
parent da79082b13
commit bf885d65db

@ -69,7 +69,7 @@ ProcessJob::exec()
int ec = 0; int ec = 0;
QString output; QString output;
if ( m_runInChroot ) if ( m_runInChroot )
ec = CalamaresUtils::chrootOutput( m_command, ec = CalamaresUtils::targetEnvOutput( m_command,
output, output,
m_workingPath, m_workingPath,
QString(), QString(),

@ -37,23 +37,23 @@ namespace bp = boost::python;
BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads,
CalamaresPython::mount, CalamaresPython::mount,
2, 4 ); 2, 4 );
BOOST_PYTHON_FUNCTION_OVERLOADS( chroot_call_str_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_str_overloads,
CalamaresPython::chroot_call, CalamaresPython::target_env_call,
1, 3 ); 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( chroot_call_list_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( target_env_call_list_overloads,
CalamaresPython::chroot_call, CalamaresPython::target_env_call,
1, 3 ); 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_call_str_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_str_overloads,
CalamaresPython::check_chroot_call, CalamaresPython::check_target_env_call,
1, 3 ); 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_call_list_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_call_list_overloads,
CalamaresPython::check_chroot_call, CalamaresPython::check_target_env_call,
1, 3 ); 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_output_str_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_str_overloads,
CalamaresPython::check_chroot_output, CalamaresPython::check_target_env_output,
1, 3 ); 1, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( check_chroot_output_list_overloads, BOOST_PYTHON_FUNCTION_OVERLOADS( check_target_env_output_list_overloads,
CalamaresPython::check_chroot_output, CalamaresPython::check_target_env_output,
1, 3 ); 1, 3 );
BOOST_PYTHON_MODULE( libcalamares ) BOOST_PYTHON_MODULE( libcalamares )
{ {
@ -115,11 +115,11 @@ BOOST_PYTHON_MODULE( libcalamares )
) )
); );
bp::def( bp::def(
"chroot_call", "target_env_call",
static_cast< int (*)( const std::string&, static_cast< int (*)( const std::string&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::chroot_call ), int ) >( &CalamaresPython::target_env_call ),
chroot_call_str_overloads( target_env_call_str_overloads(
bp::args( "command", bp::args( "command",
"stdin", "stdin",
"timeout" ), "timeout" ),
@ -132,11 +132,11 @@ BOOST_PYTHON_MODULE( libcalamares )
) )
); );
bp::def( bp::def(
"chroot_call", "target_env_call",
static_cast< int (*)( const bp::list&, static_cast< int (*)( const bp::list&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::chroot_call ), int ) >( &CalamaresPython::target_env_call ),
chroot_call_list_overloads( target_env_call_list_overloads(
bp::args( "args", bp::args( "args",
"stdin", "stdin",
"timeout" ), "timeout" ),
@ -150,11 +150,11 @@ BOOST_PYTHON_MODULE( libcalamares )
); );
bp::def( bp::def(
"check_chroot_call", "check_target_env_call",
static_cast< int (*)( const std::string&, static_cast< int (*)( const std::string&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::check_chroot_call ), int ) >( &CalamaresPython::check_target_env_call ),
check_chroot_call_str_overloads( check_target_env_call_str_overloads(
bp::args( "command", bp::args( "command",
"stdin", "stdin",
"timeout" ), "timeout" ),
@ -164,11 +164,11 @@ BOOST_PYTHON_MODULE( libcalamares )
) )
); );
bp::def( bp::def(
"check_chroot_call", "check_target_env_call",
static_cast< int (*)( const bp::list&, static_cast< int (*)( const bp::list&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::check_chroot_call ), int ) >( &CalamaresPython::check_target_env_call ),
check_chroot_call_list_overloads( check_target_env_call_list_overloads(
bp::args( "args", bp::args( "args",
"stdin", "stdin",
"timeout" ), "timeout" ),
@ -179,11 +179,11 @@ BOOST_PYTHON_MODULE( libcalamares )
); );
bp::def( bp::def(
"check_chroot_output", "check_target_env_output",
static_cast< std::string (*)( const std::string&, static_cast< std::string (*)( const std::string&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::check_chroot_output ), int ) >( &CalamaresPython::check_target_env_output ),
check_chroot_output_str_overloads( check_target_env_output_str_overloads(
bp::args( "command", bp::args( "command",
"stdin", "stdin",
"timeout" ), "timeout" ),
@ -193,11 +193,11 @@ BOOST_PYTHON_MODULE( libcalamares )
) )
); );
bp::def( bp::def(
"check_chroot_output", "check_target_env_output",
static_cast< std::string (*)( const bp::list&, static_cast< std::string (*)( const bp::list&,
const std::string&, const std::string&,
int ) >( &CalamaresPython::check_chroot_output ), int ) >( &CalamaresPython::check_target_env_output ),
check_chroot_output_list_overloads( check_target_env_output_list_overloads(
bp::args( "args", bp::args( "args",
"stdin", "stdin",
"timeout" ), "timeout" ),

@ -46,11 +46,11 @@ mount( const std::string& device_path,
int int
chroot_call( const std::string& command, target_env_call( const std::string& command,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
return CalamaresUtils::chrootCall( QString::fromStdString( command ), return CalamaresUtils::targetEnvCall( QString::fromStdString( command ),
QString(), QString(),
QString::fromStdString( stdin ), QString::fromStdString( stdin ),
timeout ); timeout );
@ -58,7 +58,7 @@ chroot_call( const std::string& command,
int int
chroot_call( const bp::list& args, target_env_call( const bp::list& args,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
@ -69,7 +69,7 @@ chroot_call( const bp::list& args,
bp::extract< std::string >( args[ i ] ) ) ); bp::extract< std::string >( args[ i ] ) ) );
} }
return CalamaresUtils::chrootCall( list, return CalamaresUtils::targetEnvCall( list,
QString(), QString(),
QString::fromStdString( stdin ), QString::fromStdString( stdin ),
timeout ); timeout );
@ -77,21 +77,21 @@ chroot_call( const bp::list& args,
int int
check_chroot_call( const std::string& command, check_target_env_call( const std::string& command,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
int ec = chroot_call( command, stdin, timeout ); int ec = target_env_call( command, stdin, timeout );
return _handle_check_chroot_call_error( ec, QString::fromStdString( command ) ); return _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
} }
int int
check_chroot_call( const bp::list& args, check_target_env_call( const bp::list& args,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
int ec = chroot_call( args, stdin, timeout ); int ec = target_env_call( args, stdin, timeout );
if ( !ec ) if ( !ec )
return ec; return ec;
@ -102,28 +102,28 @@ check_chroot_call( const bp::list& args,
bp::extract< std::string >( args[ i ] ) ) ); bp::extract< std::string >( args[ i ] ) ) );
} }
return _handle_check_chroot_call_error( ec, failedCmdList.join( ' ' ) ); return _handle_check_target_env_call_error( ec, failedCmdList.join( ' ' ) );
} }
std::string std::string
check_chroot_output( const std::string& command, check_target_env_output( const std::string& command,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
QString output; QString output;
int ec = CalamaresUtils::chrootOutput( QString::fromStdString( command ), int ec = CalamaresUtils::targetEnvOutput( QString::fromStdString( command ),
output, output,
QString(), QString(),
QString::fromStdString( stdin ), QString::fromStdString( stdin ),
timeout ); timeout );
_handle_check_chroot_call_error( ec, QString::fromStdString( command ) ); _handle_check_target_env_call_error( ec, QString::fromStdString( command ) );
return output.toStdString(); return output.toStdString();
} }
std::string std::string
check_chroot_output( const bp::list& args, check_target_env_output( const bp::list& args,
const std::string& stdin, const std::string& stdin,
int timeout ) int timeout )
{ {
@ -135,18 +135,18 @@ check_chroot_output( const bp::list& args,
bp::extract< std::string >( args[ i ] ) ) ); bp::extract< std::string >( args[ i ] ) ) );
} }
int ec = CalamaresUtils::chrootOutput( list, int ec = CalamaresUtils::targetEnvOutput( list,
output, output,
QString(), QString(),
QString::fromStdString( stdin ), QString::fromStdString( stdin ),
timeout ); timeout );
_handle_check_chroot_call_error( ec, list.join( ' ' ) ); _handle_check_target_env_call_error( ec, list.join( ' ' ) );
return output.toStdString(); return output.toStdString();
} }
int int
_handle_check_chroot_call_error( int ec, const QString& cmd ) _handle_check_target_env_call_error( int ec, const QString& cmd )
{ {
if ( !ec ) if ( !ec )
return ec; return ec;

@ -34,32 +34,32 @@ int mount( const std::string& device_path,
const std::string& filesystem_name = std::string(), const std::string& filesystem_name = std::string(),
const std::string& options = std::string() ); const std::string& options = std::string() );
int chroot_call( const std::string& command, int target_env_call( const std::string& command,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
int chroot_call( const boost::python::list& args, int target_env_call( const boost::python::list& args,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
int check_chroot_call( const std::string& command, int check_target_env_call( const std::string& command,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
int check_chroot_call( const boost::python::list& args, int check_target_env_call( const boost::python::list& args,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
std::string check_chroot_output( const std::string& command, std::string check_target_env_output( const std::string& command,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
std::string check_chroot_output( const boost::python::list& args, std::string check_target_env_output( const boost::python::list& args,
const std::string& stdin = std::string(), const std::string& stdin = std::string(),
int timeout = 0 ); int timeout = 0 );
inline int _handle_check_chroot_call_error( int ec, const QString& cmd ); inline int _handle_check_target_env_call_error( int ec, const QString& cmd );
void debug( const std::string& s ); void debug( const std::string& s );

@ -59,13 +59,13 @@ mount( const QString& devicePath,
} }
int int
chrootCall( const QStringList& args, targetEnvCall( const QStringList& args,
const QString& workingPath, const QString& workingPath,
const QString& stdInput, const QString& stdInput,
int timeoutSec ) int timeoutSec )
{ {
QString discard; QString discard;
return chrootOutput( args, return targetEnvOutput( args,
discard, discard,
workingPath, workingPath,
stdInput, stdInput,
@ -74,12 +74,12 @@ chrootCall( const QStringList& args,
int int
chrootCall( const QString& command, targetEnvCall( const QString& command,
const QString& workingPath, const QString& workingPath,
const QString& stdInput, const QString& stdInput,
int timeoutSec ) int timeoutSec )
{ {
return chrootCall( QStringList{ command }, return targetEnvCall( QStringList{ command },
workingPath, workingPath,
stdInput, stdInput,
timeoutSec ); timeoutSec );
@ -87,7 +87,7 @@ chrootCall( const QString& command,
int int
chrootOutput( const QStringList& args, targetEnvOutput( const QStringList& args,
QString& output, QString& output,
const QString& workingPath, const QString& workingPath,
const QString& stdInput, const QString& stdInput,
@ -165,13 +165,13 @@ chrootOutput( const QStringList& args,
int int
chrootOutput( const QString& command, targetEnvOutput( const QString& command,
QString& output, QString& output,
const QString& workingPath, const QString& workingPath,
const QString& stdInput, const QString& stdInput,
int timeoutSec ) int timeoutSec )
{ {
return chrootOutput( QStringList{ command }, return targetEnvOutput( QStringList{ command },
output, output,
workingPath, workingPath,
stdInput, stdInput,

@ -44,23 +44,23 @@ DLLEXPORT int mount( const QString& devicePath,
* -3 = bad arguments * -3 = bad arguments
* -4 = QProcess timeout * -4 = QProcess timeout
*/ */
DLLEXPORT int chrootCall( const QStringList& args, DLLEXPORT int targetEnvCall( const QStringList& args,
const QString& workingPath = QString(), const QString& workingPath = QString(),
const QString& stdInput = QString(), const QString& stdInput = QString(),
int timeoutSec = 0 ); int timeoutSec = 0 );
DLLEXPORT int chrootCall( const QString& command, DLLEXPORT int targetEnvCall( const QString& command,
const QString& workingPath = QString(), const QString& workingPath = QString(),
const QString& stdInput = QString(), const QString& stdInput = QString(),
int timeoutSec = 0 ); int timeoutSec = 0 );
DLLEXPORT int chrootOutput( const QStringList& args, DLLEXPORT int targetEnvOutput( const QStringList& args,
QString& output, QString& output,
const QString& workingPath = QString(), const QString& workingPath = QString(),
const QString& stdInput = QString(), const QString& stdInput = QString(),
int timeoutSec = 0 ); int timeoutSec = 0 );
DLLEXPORT int chrootOutput( const QString& command, DLLEXPORT int targetEnvOutput( const QString& command,
QString& output, QString& output,
const QString& workingPath = QString(), const QString& workingPath = QString(),
const QString& stdInput = QString(), const QString& stdInput = QString(),

@ -57,11 +57,11 @@ SetTimezoneJob::exec()
tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) ); tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );
// Make sure /etc/localtime doesn't exist, otherwise symlinking will fail // Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
CalamaresUtils::chrootCall( { "rm", CalamaresUtils::targetEnvCall( { "rm",
"-f", "-f",
localtimeSlink } ); localtimeSlink } );
int ec = CalamaresUtils::chrootCall( { "ln", int ec = CalamaresUtils::targetEnvCall( { "ln",
"-s", "-s",
zoneinfoPath, zoneinfoPath,
localtimeSlink } ); localtimeSlink } );

@ -108,7 +108,7 @@ CreateUserJob::exec()
foreach ( const QString& group, m_defaultGroups ) foreach ( const QString& group, m_defaultGroups )
if ( !groupsLines.contains( group ) ) if ( !groupsLines.contains( group ) )
CalamaresUtils::chrootCall( { "groupadd", group } ); CalamaresUtils::targetEnvCall( { "groupadd", group } );
QString defaultGroups = m_defaultGroups.join( ',' ); QString defaultGroups = m_defaultGroups.join( ',' );
if ( m_autologin ) if ( m_autologin )
@ -120,11 +120,11 @@ CreateUserJob::exec()
else else
autologinGroup = QStringLiteral( "autologin" ); autologinGroup = QStringLiteral( "autologin" );
CalamaresUtils::chrootCall( { "groupadd", autologinGroup } ); CalamaresUtils::targetEnvCall( { "groupadd", autologinGroup } );
defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) ); defaultGroups.append( QString( ",%1" ).arg( autologinGroup ) );
} }
int ec = CalamaresUtils::chrootCall( { "useradd", int ec = CalamaresUtils::targetEnvCall( { "useradd",
"-m", "-m",
"-s", "-s",
"/bin/bash", "/bin/bash",
@ -139,14 +139,14 @@ CreateUserJob::exec()
tr( "useradd terminated with error code %1." ) tr( "useradd terminated with error code %1." )
.arg( ec ) ); .arg( ec ) );
ec = CalamaresUtils::chrootCall( { "chfn", "-f", m_fullName, m_userName } ); ec = CalamaresUtils::targetEnvCall( { "chfn", "-f", m_fullName, m_userName } );
if ( ec ) if ( ec )
return Calamares::JobResult::error( tr( "Cannot set full name for user %1." ) return Calamares::JobResult::error( tr( "Cannot set full name for user %1." )
.arg( m_userName ), .arg( m_userName ),
tr( "chfn terminated with error code %1." ) tr( "chfn terminated with error code %1." )
.arg( ec ) ); .arg( ec ) );
ec = CalamaresUtils::chrootCall( { "chown", ec = CalamaresUtils::targetEnvCall( { "chown",
"-R", "-R",
QString( "%1:%2" ).arg( m_userName ) QString( "%1:%2" ).arg( m_userName )
.arg( m_userGroup ), .arg( m_userGroup ),

@ -61,7 +61,7 @@ SetPasswordJob::exec()
QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() ); QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() );
int ec = CalamaresUtils::chrootCall( { "usermod", int ec = CalamaresUtils::targetEnvCall( { "usermod",
"-p", "-p",
QString::fromLatin1( data ), QString::fromLatin1( data ),
m_userName } ); m_userName } );

Loading…
Cancel
Save