commit:e86a3948865fd612ee55d2d3706d680bf7d330c0
author:Chip Black
committer:Chip Black
date:Tue Aug 19 20:29:11 2008 -0500
parents:9c7cde8e92c615aa2a2733b12269e7358d3dde40
Added user checking bits to ag-password so that normal users can use it
diff --git a/ag-passwd b/ag-passwd
line changes: +22/-5
index ebd0bc8..8ed9bcc
--- a/ag-passwd
+++ b/ag-passwd
@@ -44,17 +44,34 @@ sub OpenBSD_Bcrypt {
 	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