provision.pl - Add prompt for user creation
This commit is contained in:
parent
b1a69ac103
commit
656183e45b
@ -23,6 +23,55 @@ my $pwuid;
|
|||||||
my $admin_un;
|
my $admin_un;
|
||||||
my $admin_home_dir;
|
my $admin_home_dir;
|
||||||
|
|
||||||
|
# Given a username... prompts and creates that user
|
||||||
|
sub create(){
|
||||||
|
my $id;
|
||||||
|
|
||||||
|
my $username;
|
||||||
|
my $user_email;
|
||||||
|
my $pub_key;
|
||||||
|
|
||||||
|
my $p0;
|
||||||
|
|
||||||
|
# Prompts...
|
||||||
|
$p0 = [
|
||||||
|
"Enter username: ",
|
||||||
|
"Enter pubkey: "
|
||||||
|
];
|
||||||
|
|
||||||
|
# read in username and validate
|
||||||
|
printf($p0->[0]);
|
||||||
|
$username = <STDIN>;
|
||||||
|
chomp $username;
|
||||||
|
|
||||||
|
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
||||||
|
printf("%s is an INVALID username\n", $id);
|
||||||
|
die ("oh no");
|
||||||
|
}
|
||||||
|
|
||||||
|
# read in pub key
|
||||||
|
printf($p0->[1]);
|
||||||
|
$pub_key = <STDIN>;
|
||||||
|
chomp $pub_key;
|
||||||
|
|
||||||
|
{
|
||||||
|
# Prompt to make sure the username looks OK
|
||||||
|
my $cmd;
|
||||||
|
$cmd = "useradd -m " . $username;
|
||||||
|
printf("Y/N is this command OK?: %s\n", $cmd);
|
||||||
|
|
||||||
|
if(!(<STDIN> =~ /^y/i)){
|
||||||
|
die "provision cancelled...";
|
||||||
|
}
|
||||||
|
|
||||||
|
# create the user
|
||||||
|
system($cmd);
|
||||||
|
system("echo '".$pub_key."' > /home/$username/.ssh/authorized_keys");
|
||||||
|
system("chmod 711 /home/$username");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Make sure we're running as root
|
# Make sure we're running as root
|
||||||
$pwuid = getpwuid( $< );
|
$pwuid = getpwuid( $< );
|
||||||
|
|
||||||
@ -31,13 +80,18 @@ if($pwuid ne "root"){
|
|||||||
}
|
}
|
||||||
|
|
||||||
unless( ($admin_un) = `tail /etc/passwd | grep -v "nobody:"` =~ /([^:\n]+):[^:]+:[0-9]{4,}/){
|
unless( ($admin_un) = `tail /etc/passwd | grep -v "nobody:"` =~ /([^:\n]+):[^:]+:[0-9]{4,}/){
|
||||||
system("pkg_add p5-JSON");
|
|
||||||
|
|
||||||
`wget --quiet https://git.lain.church/gashapwn/lyadmin/raw/branch/gasha-branch/perl-script/create_user.pl -O create_admin.pl`;
|
|
||||||
|
|
||||||
printf("to provision the instance there must be a non root user with an authorized_keys file");
|
printf("to provision the instance there must be a non root user with an authorized_keys file");
|
||||||
printf("run create_admin.pl to create an admin user\n");
|
printf("creating user...\n");
|
||||||
die "or add with useradd and add an ssh key to ~/.ssh/authorized_keys\n";
|
create();
|
||||||
|
|
||||||
|
# TODO: Getting rid of this part...
|
||||||
|
# system("pkg_add p5-JSON");
|
||||||
|
|
||||||
|
# `wget --quiet https://git.lain.church/gashapwn/lyadmin/raw/branch/gasha-branch/perl-script/create_user.pl -O create_admin.pl`;
|
||||||
|
|
||||||
|
# printf("to provision the instance there must be a non root user with an authorized_keys file");
|
||||||
|
# printf("run create_admin.pl to create an admin user\n");
|
||||||
|
# die "or add with useradd and add an ssh key to ~/.ssh/authorized_keys\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# install git
|
# install git
|
||||||
|
Loading…
Reference in New Issue
Block a user