Reduce disk writes in post-compile triggers
[gitolite.git] / src / commands / htpasswd
blobbbfacc7449e6630d275188b06cd6b62cd37270d1
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use lib $ENV{GL_LIBDIR};
7 use Gitolite::Rc;
8 use Gitolite::Common;
10 =for usage
11 Usage: ssh git@host htpasswd
13 Sets your htpasswd, assuming your admin has enabled it.
15 (Admins: You need to add HTPASSWD_FILE to the rc file, pointing to an
16 existing, writable, but possibly an initially empty, file, as well as adding
17 'htpasswd' to the ENABLE list).
18 =cut
20 # usage and sanity checks
21 usage() if @ARGV and $ARGV[0] eq '-h';
22 $ENV{GL_USER} or _die "GL_USER not set";
23 my $htpasswd_file = $rc{HTPASSWD_FILE} || '';
24 die "htpasswd not enabled\n" unless $htpasswd_file;
25 die "$htpasswd_file doesn't exist or is not writable\n" unless -w $htpasswd_file;
27 # prompt
28 $|++;
29 print <<EOFhtp;
30 Please type in your new htpasswd at the prompt. You only have to type it once.
32 NOTE THAT THE PASSWORD WILL BE ECHOED, so please make sure no one is
33 shoulder-surfing, and make sure you clear your screen as well as scrollback
34 history after you're done (or close your terminal instance).
36 EOFhtp
37 print "new htpasswd: ";
39 # get the password and run htpasswd
40 my $password = <>;
41 $password =~ s/[\n\r]*$//;
42 die "empty passwords are not allowed\n" unless $password;
43 my $res = system( "htpasswd", "-mb", $htpasswd_file, $ENV{GL_USER}, $password );
44 die "htpasswd command seems to have failed with return code: $res.\n" if $res;