#!/bin/bash
#parameter1: password

# usage from command line:
# ./omcpasswd '!213\213'
# this is wrong (from bash): ./omcpasswd "123"


exec >/dev/null 2>&1		#disable all stderr and stdout
newPass=$1

OSType=$(omgsysteminfo --val --filter=os.name)

if [ $OSType = "centos" ]; then
	echo "CentOS detected"
	htpasswd -cb /usr/fb/omgwww.htpasswd root "${newPass}"
	htpasswd -b /usr/fb/omgwww.htpasswd admin "${newPass}"
elif [ $OSType = "red" ]; then
	echo "RedHat detected"
	htpasswd -cb /usr/fb/omgwww.htpasswd root "${newPass}"
	htpasswd -b /usr/fb/omgwww.htpasswd admin "${newPass}"
elif [ $OSType = "ubuntu" ]; then
	echo "Ubuntu detected"
	sed -i /^root:.*/d /etc/nhttpd/htpasswd; crypt /etc/nhttpd/htpasswd root "${newPass}"
	sed -i /^admin:.*/d /etc/nhttpd/htpasswd; crypt /etc/nhttpd/htpasswd admin "${newPass}"
else
	echo "unknown OS"
fi


echo -E "omc:${newPass}" | chpasswd
echo -E "linetest:${newPass}" | chpasswd
echo -E "root:${newPass}" | chpasswd


grep -q "^#patched by omcpasswd" /etc/shadow || echo "#patched by omcpasswd" >> /etc/shadow

exit ${err}
