63
#!/bin/bash
# This script is used change the users and passwords for manweb
# 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: manweb-passwd [-c /path/to/manweb.conf] <username>'
echo ' -c: specify the path to the manweb.conf file, otherwise the default'
echo ' will be used (/etc/manweb/manweb.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
manweb_running() {
echo "manweb is running"
echo "Please stop all instances of manweb before running this script."
}
echo "Checking if manweb is running..."
systemctl is-active manweb >/dev/null 2>&1
if [[ "$?" == "0" ]]; then
manweb_running
exit 1
fi
ps x | grep -E '/.*bin.*/manweb$' > /dev/null 2>&1
if [[ "$?" == "0" ]]; then
manweb_running
exit 1
fi
confFile="/etc/manweb/manweb.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 manweb /usr/bin/manweb -c "$confFile" -pu "$username"