Browse Source

create-user.pl - added logic to handle multiple pwd. errors out if run in wrong pwd.

tags/release-00
gashapwn 3 years ago
parent
commit
33048f0887
1 changed files with 22 additions and 13 deletions
  1. +22
    -13
      perl-script/create-user.pl

+ 22
- 13
perl-script/create-user.pl View File

@@ -8,21 +8,9 @@ use JSON;
my $working_dir = "./";
my $account_dir = $working_dir."req/";

my $CONF_PATH = $working_dir."lyadmin.conf.json";
my $conf_path = $working_dir."lyadmin.conf.json";
my $SHELL_ENUM;

open FILE, $CONF_PATH or die "could not open file $CONF_PATH";
{
my $conf_str;
my $conf_obj;
local $/=undef;
$conf_str = <FILE>;
chomp $conf_str;
$conf_obj = decode_json($conf_str);
$SHELL_ENUM = $conf_obj->{"shell"};
};
close FILE;

my @g;

sub create($){
@@ -81,6 +69,27 @@ if(!(`id` =~ /uid=0/)){
die "please run this script as root";
}

if( `pwd` =~ /perl-script\/?\s*$/){
$working_dir = "../";
$account_dir = $working_dir."req/";
$conf_path = $working_dir."lyadmin.conf.json";
printf("%s\n", $conf_path);
}elsif(!(join(" ", glob("./*")) =~ /perl-script/)){
die "please run this script with ./perl-script/ as the present working directory";
}

open FILE, $conf_path or die "could not open file $conf_path";
{
my $conf_str;
my $conf_obj;
local $/=undef;
$conf_str = <FILE>;
chomp $conf_str;
$conf_obj = decode_json($conf_str);
$SHELL_ENUM = $conf_obj->{"shell"};
};
close FILE;

@g = glob("$account_dir*");
@g = map { s/.*\/([^\/]*).ident$/$1/; $_ } grep {$_ =~ /ident$/} @g;



Loading…
Cancel
Save