1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ergo_ynh.git synced 2024-09-03 18:26:31 +02:00
ergo_ynh/scripts/install
2024-01-28 05:57:48 +01:00

133 lines
4.4 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
install_dir_www=/var/www/$app
ynh_app_setting_set --app=$app --key=install_dir_www --value=$install_dir_www
test ! -e "$install_dir_www" || ynh_die --message="This path already contains a folder"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=10
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --dest_dir="$install_dir" --source_id=ldap
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod +x "$install_dir/ergo"
# Copy help file
mkdir -p "$install_dir_www/help"
if test -e "$YNH_APP_BASEDIR/sources/extra_files/help"; then
cp --archive "$YNH_APP_BASEDIR/sources/extra_files/help/." "$install_dir_www/help"
fi
ynh_replace_vars --file="$install_dir_www/help/index.html"
chmod 750 "$install_dir_www"
chmod -R o-rwx "$install_dir_www"
chown -R "www-data":"www-data" "$install_dir_www"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=2
# Get Password Hash
passwordhash=$((echo "$password"; echo "$password") | $install_dir/ergo genpasswd)
# Enable ldap authentication if necessary
ldapoption=false
if [ $enable_ldap -eq 1 ]
then
ldapoption=true
fi
server=$domain
ynh_add_config --template="../conf/default.yaml" --destination="$install_dir/ircd.yaml"
ynh_add_config --template="../conf/ldap-config.yaml" --destination="$install_dir/ldap-config.yaml"
ynh_add_config --template="../conf/ircd.motd" --destination="$install_dir/ircd.motd"
chmod 400 "$install_dir/ircd.yaml"
chown $app: "$install_dir/ircd.yaml"
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=3
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=2
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# SPECIFIC SETUP
#=================================================
# adding the ergo dedicated user to the 'ssl-cert' group
# to permit the use of the Let's Encrypt certs
usermod -a -G ssl-cert "$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
# Build the ports list
needed_ports=()
needed_ports+=( "$port" )
needed_ports+=( "$port_secure" )
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="A modern IRC server" --log="/var/log/$app/$app.log" ${needed_ports:+--needs_exposed_ports} "${needed_ports[@]}"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
# 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" --last