snikket_ynh/scripts/install
NorbiPeti 2464193a1c Add Snikket custom steps
TODO:
- Apply patches
- Handle the rest of the tasks
2024-05-22 23:37:55 +02:00

143 lines
4.5 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# DISABLE METRONOME
#=================================================
ynh_script_progression --message="Disabling Metronome..."
if systemctl list-unit-files metronome.service &>/dev/null
then
ynh_systemd_action --service_name="metronome" --action="stop"
systemctl disable metronome.service --quiet
fi
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
builddir="$(mktemp -d)"
ynh_setup_source --dest_dir="$builddir" --source_id=prosody
snikketdir="$(mktemp -d)"
ynh_setup_source --dest_dir="$snikketdir"
moddir="$(mktemp -d)"
ynh_setup_source --dest_dir="$moddir" --source_id=prosody-modules
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD PROSODY
#=================================================
ynh_script_progression --message="Building Prosody..."
update-alternatives --set lua-interpreter /usr/bin/lua${luaversion}
pushd "$builddir"
./configure --sysconfdir="/etc/$app" --datadir="/var/lib/$app"
make
make install
# Install Prosody-Migrator
pushd "tools/migration"
make install
popd
popd
ynh_secure_remove --file="$builddir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding Prosody configuration..."
config_path=/etc/$app
ynh_app_setting_set --app=$app --key=config_path --value=$config_path
mkdir -p $config_path
mkdir -p $config_path/{certs,conf.avail,conf.d}
mkdir -p $config_path/firewall
ynh_add_config --template="$snikketdir/ansible/files/prosody.cfg.lua" --destination="$config_path/prosody.cfg.lua"
ynh_add_config --template="$snikketdir/ansible/files/restricted_users.pfw" --destination="$config_path/restricted_users.pfw"
# Add Prosody-Migrator config
ynh_add_config --template="$snikketdir/ansible/files/migrator.cfg.lua" --destination="$config_path/migrator.cfg.lua"
chown root:root "$config_path"
chmod 755 "$config_path"
chown root:$app "$config_path/conf.d"
chmod 754 "$config_path/conf.d"
chown root:$app "$config_path/conf.avail"
chmod 754 "$config_path/conf.avail"
chown root:$app "$config_path/certs"
chmod 750 "$config_path/certs"
#=================================================
# SETUP MODULES
#=================================================
ynh_script_progression --message="Intalling modules..."
mkdir -p "/etc/$app/modules"
while read module
do
cp -r "$moddir/$module" "/etc/$app/modules/$module"
done < "../sources/prosody-modules.txt"
while read module
do
cp -r "$snikketdir/snikket-modules/$module" "/etc/$app/modules/$module"
done < "../sources/snikket-modules.txt"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..."
mkdir -p "/var/log/$app"
chmod 750 "/var/log/$app"
chmod -R o-rwx "/var/log/$app"
chown -R $app:adm "/var/log/$app"
chown -R $app:$app "/var/lib/$app"
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"