2007-02-22 19:39:02 by steve
Added new command line flag --admins, which allows new users to be setup upon the host system with the xen-shell.
This commit is contained in:
parent
158515e726
commit
a700941d06
@ -25,6 +25,9 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH.
|
||||
|
||||
--accounts Copy all non-system accounts to the guest image
|
||||
|
||||
--admins Specify that some administrators should be created for
|
||||
this image, using xen-shell.
|
||||
|
||||
--boot Boot the new instance after creating it.
|
||||
|
||||
--cache Cache .deb files on the host when installing the new guest
|
||||
@ -517,7 +520,7 @@ Install an X11 server, using VNC and XDM
|
||||
--
|
||||
http://www.steve.org.uk/
|
||||
|
||||
$Id: xen-create-image,v 1.124 2007-02-22 19:15:25 steve Exp $
|
||||
$Id: xen-create-image,v 1.125 2007-02-22 19:39:02 steve Exp $
|
||||
|
||||
=cut
|
||||
|
||||
@ -865,6 +868,28 @@ E_O_ERROR
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Make sure that xen-shell is installed if we've got an --admin
|
||||
# flag specified
|
||||
#
|
||||
if ( $CONFIG{'admins'} )
|
||||
{
|
||||
my $shell = undef;
|
||||
$shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
|
||||
if ( !defined( $shell ) )
|
||||
{
|
||||
print <<EOF;
|
||||
|
||||
You've specified administrator accounts for use with the xen-shell,
|
||||
however that doesn't appear to be installed.
|
||||
|
||||
Aborting.
|
||||
EOF
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1085,6 +1110,7 @@ sub parseCommandLineArguments
|
||||
|
||||
# Misc. options
|
||||
"accounts", \$CONFIG{'accounts'},
|
||||
"admins=s", \$CONFIG{'admins'},
|
||||
"arch=s", \$CONFIG{'arch'},
|
||||
"fs=s", \$CONFIG{'fs'},
|
||||
"boot", \$CONFIG{'boot'},
|
||||
@ -1113,7 +1139,7 @@ sub parseCommandLineArguments
|
||||
|
||||
if ( $VERSION )
|
||||
{
|
||||
my $REVISION = '$Revision: 1.124 $';
|
||||
my $REVISION = '$Revision: 1.125 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -2496,12 +2522,23 @@ sub runXenConfigCreation
|
||||
|
||||
my $command = 'xt-create-xen-config --output=/etc/xen';
|
||||
|
||||
#
|
||||
# Add the template if specified
|
||||
#
|
||||
if ( ( defined( $CONFIG{'template'} ) ) &&
|
||||
( -e $CONFIG{'template'} ) )
|
||||
{
|
||||
$command .= " --template=" . $CONFIG{'template'};
|
||||
}
|
||||
|
||||
#
|
||||
# Add the admins, if any.
|
||||
#
|
||||
if ( defined( $CONFIG{'admins'} ) )
|
||||
{
|
||||
$command .= " --admins=$CONFIG{'admins'}";
|
||||
}
|
||||
|
||||
logprint( "\nCreating Xen configuration file\n" );
|
||||
runCommand( $command );
|
||||
logprint( "Done\n" );
|
||||
|
||||
@ -10,10 +10,17 @@ xt-create-config - Create a Xen configuration file for a new guest
|
||||
|
||||
xt-create-config [options]
|
||||
|
||||
General Options:
|
||||
--admins Specify some administrator accounts which should be
|
||||
created for use by the xen-shell.
|
||||
|
||||
--template Specify the template file to use when creating the
|
||||
Xen configuration file.
|
||||
|
||||
Help Options:
|
||||
--help Show this scripts help information.
|
||||
--manual Read this scripts manual.
|
||||
--version Show the version number and exit.
|
||||
--help Show this scripts help information.
|
||||
--manual Read this scripts manual.
|
||||
--version Show the version number and exit.
|
||||
|
||||
Debugging Options:
|
||||
--verbose Be verbose in our execution.
|
||||
@ -96,7 +103,7 @@ xt-create-config - Create a Xen configuration file for a new guest
|
||||
--
|
||||
http://www.steve.org.uk/
|
||||
|
||||
$Id: xt-create-xen-config,v 1.30 2007-02-06 20:38:21 steve Exp $
|
||||
$Id: xt-create-xen-config,v 1.31 2007-02-22 19:39:03 steve Exp $
|
||||
|
||||
=cut
|
||||
|
||||
@ -160,6 +167,17 @@ checkArguments();
|
||||
createXenConfig();
|
||||
|
||||
|
||||
#
|
||||
# If we've been given any administrators then set them up.
|
||||
#
|
||||
if ( $CONFIG{'admins'} )
|
||||
{
|
||||
setupAdminUsers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Exit cleanly - any errors which have already occurred will result
|
||||
# in "exit 1".
|
||||
@ -189,6 +207,7 @@ sub parseCommandLineArguments
|
||||
# Parse options.
|
||||
#
|
||||
GetOptions(
|
||||
"admins=s", \$CONFIG{'admins'},
|
||||
"output=s", \$CONFIG{'output'},
|
||||
"template=s", \$CONFIG{'template'},
|
||||
"verbose", \$CONFIG{'verbose'},
|
||||
@ -203,7 +222,7 @@ sub parseCommandLineArguments
|
||||
|
||||
if ( $VERSION )
|
||||
{
|
||||
my $REVISION = '$Revision: 1.30 $';
|
||||
my $REVISION = '$Revision: 1.31 $';
|
||||
if ( $REVISION =~ /1.([0-9.]+) / )
|
||||
{
|
||||
$REVISION = $1;
|
||||
@ -388,3 +407,52 @@ sub createXenConfig
|
||||
close( FILE );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
=begin doc
|
||||
|
||||
This routine is designed to ensure that any users specified with
|
||||
the --admins flag are setup as administrators of the new instance.
|
||||
|
||||
=end doc
|
||||
|
||||
=cut
|
||||
|
||||
sub setupAdminUsers
|
||||
{
|
||||
#
|
||||
# Find the path to the xen-login-shell
|
||||
#
|
||||
my $shell = undef;
|
||||
$shell = "/usr/bin/xen-login-shell" if ( -x "/usr/bin/xen-login-shell" );
|
||||
$shell = "/usr/local/bin/xen-login-shell" if ( -x "/usr/bin/local/xen-login-shell" );
|
||||
|
||||
return if ( !defined( $shell ) );
|
||||
|
||||
#
|
||||
# For each user make sure they exist, and setup the
|
||||
# login shell for them.
|
||||
#
|
||||
foreach my $user ( split( /,/, $CONFIG{'admins'} ) )
|
||||
{
|
||||
# Strip leading and trailing whitespace.
|
||||
$user =~ s/^\s+//;
|
||||
$user =~ s/\s+$//;
|
||||
|
||||
# Does the user exist?
|
||||
if ( getpwnam($user) )
|
||||
{
|
||||
# Change shell.
|
||||
$CONFIG{'verbose'} && print "Changing shell for $user: $shell\n";
|
||||
system( "chsh", "-s", $shell, $user );
|
||||
}
|
||||
else
|
||||
{
|
||||
# Add a new user.
|
||||
$CONFIG{'verbose'} && print "Adding new user: $user\n";
|
||||
system( "useradd", "-s", $shell, $user );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,3 +76,9 @@ on_poweroff = 'destroy'
|
||||
on_reboot = 'restart'
|
||||
on_crash = 'restart'
|
||||
|
||||
|
||||
{ if ( $admins )
|
||||
{
|
||||
$OUT .= "xen_shell = '$admins'\n";
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user