~dricottone/my-utils

my-utils/crypto/mkhtpasswd -rwxr-xr-x 885 bytes
ef6d4cd1Dominic Ricottone Incomplete work on hardware/media utils 4 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

name="mkhtpasswd"
version="1.0"
read -r -d '' help_message <<-EOF
	Create an Apache htpasswd file
	Usage: mkhtpasswd [OPTIONS] >>.htpasswd
	Options:
	 -h, --help     print this message and exit
	 -q, --quiet    suppress error messages and prompts
	 -v, --verbose  show additional messages
	 -V, --version  print version number and exit
EOF

source /usr/local/lib/mylib.bash
. /usr/local/lib/myparse.bash

# Get username
user=
/usr/bin/printf "Enter username: " >&2
read user
if [[ -z "$user" ]]; then
  error_msg "expected non-empty username"
fi

# Get password
passwd=
/usr/bin/printf "Enter password:" >&2
read -s passwd
/usr/bin/printf "\n" >&2
if [[ -z "$passwd" ]]; then
  debug_msg "Using empty password"
else
  debug_msg "Using a non-empty password"
fi

# Print out the htpasswd file
/usr/bin/printf '%s:%s\n' "$user" "$(/usr/bin/openssl passwd -crypt "$passwd")"