#!/bin/sh -e

CONFIG_FILE=/etc/jabber-mrim/mrim.conf
#CONFIG_FILE=mrim/mrim.conf.example

TEMP=`getopt -n "$0" -o '' -l port,host,password,set-port:,set-host:,set-password: -- "$@"` || exit 1
eval set -- "$TEMP"

while :; do
	case "$1" in
	--port) sed -n '/^port = / s/^port = //p' <$CONFIG_FILE
		;;
	--host) sed -n '/^name = / s/^name = //p' <$CONFIG_FILE
		;;
	--password) sed -n '/^password = / s/^password = //p' <$CONFIG_FILE
		;;
	--set-port)
		sed -i "s/^port = .*$/port = $2/" $CONFIG_FILE
		shift
		;;
	--set-host)
		sed -i "s/^name = .*$/name = $2/" $CONFIG_FILE
		shift
		;;
	--set-password)
		sed -i "s/^password = .*$/password = $2/" $CONFIG_FILE
		shift
		;;
	--) shift; break
		;;
	*)
		echo "Invalid command: $1"
		exit 2
		;;
	esac
	shift
done
