63
#!/bin/bash
# This script is used change the users and passwords for manhttpd
# This script must be run as root or with sudo
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root or with sudo" 1>&2
exit 1
fi
helpMenu() {
echo 'usage: manhttpd-passwd [-c /path/to/manhttpd.conf] <username>'
echo ' -c: specify the path to the manhttpd.conf file, otherwise the default'
echo ' will be used (/etc/manhttpd/manhttpd.conf)'
echo
echo ' if the username already exists, the password for that user will be changed'
echo ' if the username does not exist, a new user will be created'
echo ' if a username exists and no password is given, the user will be deleted'
}
if [[ "$1" == "" || "$#" == "0" ]] ]]; then
helpMenu
exit 1
fi
if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "-?" || "$1" == "help" ]]; then
helpMenu
exit 0
fi
manhttpd_running() {
echo "manhttpd is running"
echo "Please stop all instances of manhttpd before running this script."
}
echo "Checking if manhttpd is running..."
systemctl is-active manhttpd >/dev/null 2>&1
if [[ "$?" == "0" ]]; then
manhttpd_running
exit 1
fi
ps x | grep -E '/.*bin.*/manhttpd$' > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
manhttpd_running
exit 1
fi
confFile="/etc/manhttpd/manhttpd.conf"
if [[ "$#" == "3" && "$1" == "-c" ]]; then
if [[ ! "$2" == *".conf" || ! -f "$2" ]]; then
echo "File $2 does not exist or is not a conf file."
exit 1
fi
confFile="$2"
username="$3"
elif [[ "$#" == "1" ]]; then
username="$1"
else
helpMenu
exit 1
fi
sudo -u manhttpd /usr/bin/manhttpd -c "$confFile" -pu "$username"