Added user checking bits to ag-password so that normal users can use it
return $p;
}
-my $user = shift;
-if (!$user) {
- print "usage: ag-passwd user\n";
- exit 1;
+my $user;
+if (exists $ENV{SUDO_USER}) {
+ $user = $ENV{SUDO_USER};
+} else {
+ $user = shift;
+ if (!$user) {
+ if ($> == 0) {
+ print "When used by root, you must specify a username\n";
+ } else {
+ chomp(my $sudo = `which sudo`);
+ if ($sudo) {
+ print "Attempting to sudo myself...\n";
+ exec "$sudo $0";
+ } else {
+ print "You are not root and you don't have sudo installed. Sorry.\n";
+ }
+ }
+ exit 1;
+ }
}
if (!AwesomeGrid::User::exists($user)) {
- print "User does not exist\n";
+ print "User $user does not exist\n";
exit 1;
}
+print "Changing password for $user\n";
+
my $aguser = AwesomeGrid::User->load($user) || exit 1;
# Restore sanity in case of emergency