#!/bin/bash
# create ssl certificate for quasselcore
#
# Copyright (C) 2008 Harald Sitter <apachelogger@ubuntu.com>
#
#  This package is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This package is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this package; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

QUASSEL_HOME=/var/lib/quassel/.quassel

if [ -w $QUASSEL_HOME/ ]; then
    openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout $QUASSEL_HOME/quasselCert.pem -out $QUASSEL_HOME/quasselCert.pem
    chown quasselcore:quassel $QUASSEL_HOME/quasselCert.pem
else
    echo "You have to execute this script with root privilege (sudo)."
    if [ -x $0 ]; then
        echo "...because it's you, I'll take care of this ;-)"
        echo "###############################################"
        sudo $0
    fi
fi

exit 0
