#!/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")"