flectra/setup/redhat/postinstall.sh

62 lines
1.7 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
set -e
2018-01-16 12:47:23 +01:00
FLECTRA_CONFIGURATION_DIR=/etc/flectra
FLECTRA_CONFIGURATION_FILE=$FLECTRA_CONFIGURATION_DIR/flectra.conf
FLECTRA_DATA_DIR=/var/lib/flectra
FLECTRA_GROUP="flectra"
FLECTRA_LOG_DIR=/var/log/flectra
FLECTRA_LOG_FILE=$FLECTRA_LOG_DIR/flectra-server.log
FLECTRA_USER="flectra"
2018-01-16 12:47:23 +01:00
if ! getent passwd | grep -q "^flectra:"; then
groupadd $FLECTRA_GROUP
adduser --system --no-create-home $FLECTRA_USER -g $FLECTRA_GROUP
fi
2018-01-16 12:47:23 +01:00
# Register "$FLECTRA_USER" as a postgres user with "Create DB" role attribute
su - postgres -c "createuser -d -R -S $FLECTRA_USER" 2> /dev/null || true
# Configuration file
2018-01-16 12:47:23 +01:00
mkdir -p $FLECTRA_CONFIGURATION_DIR
# can't copy debian config-file as addons_path is not the same
2018-01-16 12:47:23 +01:00
if [ ! -f $FLECTRA_CONFIGURATION_FILE ]
then
echo "[options]
; This is the password that allows database operations:
; admin_passwd = admin
db_host = False
db_port = False
2018-01-16 12:47:23 +01:00
db_user = $FLECTRA_USER
db_password = False
2018-01-16 12:47:23 +01:00
addons_path = /usr/lib/python3.6/site-packages/flectra/addons
" > $FLECTRA_CONFIGURATION_FILE
chown $FLECTRA_USER:$FLECTRA_GROUP $FLECTRA_CONFIGURATION_FILE
chmod 0640 $FLECTRA_CONFIGURATION_FILE
fi
# Log
2018-01-16 12:47:23 +01:00
mkdir -p $FLECTRA_LOG_DIR
chown $FLECTRA_USER:$FLECTRA_GROUP $FLECTRA_LOG_DIR
chmod 0750 $FLECTRA_LOG_DIR
# Data dir
2018-01-16 12:47:23 +01:00
mkdir -p $FLECTRA_DATA_DIR
chown $FLECTRA_USER:$FLECTRA_GROUP $FLECTRA_DATA_DIR
2018-01-16 12:47:23 +01:00
INIT_FILE=/lib/systemd/system/flectra.service
touch $INIT_FILE
chmod 0700 $INIT_FILE
cat << EOF > $INIT_FILE
[Unit]
2018-01-16 12:47:23 +01:00
Description=Flectra Open Source ERP and CRM
After=network.target
[Service]
Type=simple
2018-01-16 12:47:23 +01:00
User=flectra
Group=flectra
ExecStart=/usr/bin/flectra --config $FLECTRA_CONFIGURATION_FILE --logfile $FLECTRA_LOG_FILE
KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF