freedombonee/src/freedombone-addxmpp

101 lines
2.5 KiB
Plaintext
Raw Normal View History

2015-04-05 14:38:01 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Adds an xmpp user
# License
# =======
#
2016-10-31 17:24:49 +01:00
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
2015-04-05 14:38:01 +02:00
#
# This program is free software: you can redistribute it and/or modify
2016-02-13 23:09:27 +01:00
# it under the terms of the GNU Affero General Public License as published by
2015-04-05 14:38:01 +02:00
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2016-02-13 23:09:27 +01:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2015-04-05 14:38:01 +02:00
#
2016-02-13 23:09:27 +01:00
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-04-05 14:38:01 +02:00
2015-11-27 12:42:16 +01:00
PROJECT_NAME='freedombone'
2015-11-27 17:52:23 +01:00
export TEXTDOMAIN=${PROJECT_NAME}-addxmpp
2015-11-27 12:42:16 +01:00
export TEXTDOMAINDIR="/usr/share/locale"
2015-04-05 14:38:01 +02:00
EMAIL_ADDRESS=
2015-10-26 15:25:58 +01:00
NEW_USER_PASSWORD=
2015-04-05 14:38:01 +02:00
function show_help {
echo ''
2015-12-08 17:22:48 +01:00
echo $"${PROJECT_NAME}-addxmpp -e [email address] -p [password]"
2015-04-05 14:38:01 +02:00
echo ''
exit 0
}
while [[ $# > 1 ]]
do
2016-07-24 14:19:56 +02:00
key="$1"
2015-04-05 14:38:01 +02:00
2016-07-24 14:19:56 +02:00
case $key in
2016-08-28 10:55:47 +02:00
-h|--help)
show_help
;;
-e|--email)
shift
EMAIL_ADDRESS="$1"
;;
-p|--password|--passphrase)
shift
NEW_USER_PASSWORD="$1"
;;
*)
# unknown option
;;
2016-07-24 14:19:56 +02:00
esac
2015-10-26 15:25:58 +01:00
shift
2015-04-05 14:38:01 +02:00
done
2015-10-26 15:25:58 +01:00
if [ ! -d /etc/prosody ]; then
2015-11-27 16:29:43 +01:00
echo $'xmpp server is not installed'
2015-10-26 18:25:59 +01:00
exit 0
2015-10-26 15:25:58 +01:00
fi
2015-04-05 14:38:01 +02:00
if [ ! $EMAIL_ADDRESS ]; then
show_help
2015-10-26 18:25:59 +01:00
exit 1
2015-04-05 14:38:01 +02:00
fi
2016-08-28 10:58:07 +02:00
USERNAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $1}')
2015-10-26 15:25:58 +01:00
if [ ! $NEW_USER_PASSWORD ]; then
prosodyctl adduser $EMAIL_ADDRESS
else
DOMAIN_NAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $2}')
2015-11-27 12:42:16 +01:00
prosodyctl register $USERNAME $DOMAIN_NAME "$NEW_USER_PASSWORD"
2015-10-26 18:25:59 +01:00
if [ ! "$?" = "0" ]; then
2016-08-28 10:55:47 +02:00
exit 2
fi
fi
# add the xmpp address to email headers
if [ -f /home/$USERNAME/.muttrc ]; then
if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
2016-08-28 10:58:07 +02:00
echo "my_hdr Jabber-ID: $EMAIL_ADDRESS" >> /home/$USERNAME/.muttrc
else
sed -i "s|my_hdr Jabber-ID.*|my_hdr Jabber-ID: $EMAIL_ADDRESS|g" /home/$USERNAME/.muttrc
2015-10-26 18:25:59 +01:00
fi
2015-10-26 15:25:58 +01:00
fi
2015-04-05 14:38:01 +02:00
exit 0