2
# This hook runs when the config has changed
5
# A large portion of this script is derived from the package configure script.
7
# some variables - defined by quassel-core package
9
QUASSEL_USER=quasselcore
10
QUASSEL_HOME=/var/lib/quassel
11
QUASSEL_LOG=/var/log/quassel
12
CERT=$QUASSEL_HOME/quasselCert.pem
15
LOGROT=/etc/logrotate.d/quassel-core
20
if [ ! -d "$QUASSEL_HOME" ]; then
21
# called before package configuration has completed; do nothing
22
echo "$QUASSEL_HOME directory does not exist; exiting"
26
if [ -z "$(getent passwd $QUASSEL_USER)" ]; then
27
# called before package configuration has completed; do nothing
28
echo "$QUASSEL_USER user does not exist; exiting"
32
if [ -z "$(getent group $QUASSEL_GROUP)" ]; then
33
# called before package configuration has completed; do nothing
34
echo "$QUASSEL_GROUP group does not exist; exiting"
38
# check certificate - if number of key bits has changed, regenerate it
39
certificate_days=$(config-get certificate-days)
40
key_size=$(config-get key-size)
43
bits=$(openssl rsa -in $CERT -text 2>&1 | grep '^Private-Key:' | grep -Eo '[0-9]+')
44
if [ "$bits" -ne "$key_size" ]; then
45
# key size changed - remove certificate
46
echo "$CERT is $bits bits - need $key_size bits; removing"
51
if [ ! -e $CERT ]; then
52
echo "Generating SSL certificate $CERT - $key_size bits, validity $certificate_days days"
53
openssl req -x509 -nodes -batch -days $certificate_days -newkey rsa:$key_size -keyout $CERT -out $CERT
54
chown $QUASSEL_USER:$QUASSEL_GROUP $CERT
58
# check quassel configuration
59
listen_port=$(config-get listen-port)
60
log_level=$(config-get log-level)
62
if [ ! -e $CFG ]; then
63
# new install - create configuration and open port
65
open-port $listen_port
67
# existing configuration
68
port=$(grep '^PORT=' $CFG | grep -Eo '[0-9]+')
69
if [ "$port" -ne "$listen_port" ]; then
71
open-port $listen_port
74
levelnow=$(grep '^LOGLEVEL=' $CFG | cut -d= -f2 | cut -d\" -f2 | tr '[A-Z]' '[a-z]')
75
levelcfg=$(echo $log_level | tr '[A-Z]' '[a-z]')
76
if [ "$levelnow" != "$levelcfg" ]; then
81
# create a new configuration, if required
82
if [ "$newconfigreqd" -eq 1 ]; then
86
# Defaults for $SVC initscript
87
# sourced by /etc/init.d/$SVC
89
# This file is managed by the quassel-core juju charm - do not edit here
91
# Loglevel Debug|Info|Warning|Error. Default is: Info
94
# The port $SVC will listen at. Default is: 4242
100
# restart quassel-core, if required
101
if [ "$restartreqd" -eq 1 ]; then
102
service $SVC restart || service $SVC start
105
# overwrite logrotate configuration
106
log_keep_days=$(config-get log-keep-days)
109
# This file is managed by the quassel-core juju charm - do not edit here
110
/var/log/quassel/core.log {
111
rotate $log_keep_days