2022-12-27 17:59:56 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source ynh_mongo_db__2
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$install_dir"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R "$app:$app" "$install_dir"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-04 15:16:51 +01:00
|
|
|
#=================================================
|
|
|
|
# Configure document storage
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring document storage..." --weight=1
|
|
|
|
|
|
|
|
document_path=$data_dir/docs
|
|
|
|
ynh_app_setting_set --app="$app" --key=document_path --value="$document_path"
|
|
|
|
|
|
|
|
document_url=$(append_uri "https://${domain}${path}" "docs")
|
|
|
|
ynh_app_setting_set --app="$app" --key=document_url --value="$document_url"
|
|
|
|
|
|
|
|
# Add the status page
|
|
|
|
ynh_add_config --template="index.html" --destination="$data_dir/index.html"
|
|
|
|
|
|
|
|
chmod -R o-rwx "$data_dir"
|
|
|
|
chown -R $app:www-data "$data_dir"
|
|
|
|
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# ADD A CONFIGURATION
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_add_config --template=".env" --destination="$install_dir/.env"
|
2022-12-29 10:06:04 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
chmod 400 "$install_dir/.env"
|
|
|
|
chown $app:$app "$install_dir/.env"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# ADD SSH ACCESS
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
if [ -n "$public_key" ]; then
|
|
|
|
ynh_script_progression --message="Enabling ssh access for dev..." --weight=1
|
|
|
|
# enable ssh access to the files for updates
|
|
|
|
# todo: Secure it more with https://github.com/YunoHost-Apps/ssh_chroot_dir_ynh
|
|
|
|
mkdir --parents "$install_dir/.ssh"
|
|
|
|
ynh_add_config --template="authorized_keys" --destination="$install_dir/.ssh/authorized_keys"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
chown -R "$app:$app" "$install_dir/.ssh"
|
|
|
|
chmod 700 "$install_dir/.ssh"
|
|
|
|
chmod 600 "$install_dir/.ssh/authorized_keys"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
#=================================================
|
|
|
|
# Create restart services file
|
|
|
|
#=================================================
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
# Enable restarting of services from ssh
|
|
|
|
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
|
|
|
|
chown "$app:$app" "$install_dir/restart-services.sh"
|
|
|
|
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
|
2023-01-07 10:31:21 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
# Add sudoers file for this specific command
|
|
|
|
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
|
|
|
|
chown root:root "/etc/sudoers.d/$app-sudoers"
|
|
|
|
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
|
2022-12-27 17:59:56 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# INSTALL MONGO
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_script_progression --message="Installing MongoDB..." --weight=1
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
# Install the required version of Mongo
|
|
|
|
ynh_install_mongo --mongo_version=$mongo_version
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# CREATE A MONGO DATABASE
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_script_progression --message="Creating the Mongo databases..." --weight=1
|
2022-12-29 10:06:04 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
db_user=$(ynh_sanitize_dbid --db_name="${app}")
|
|
|
|
ynh_app_setting_set --app="$app" --key=db_user --value="$db_user"
|
|
|
|
|
|
|
|
# We should probably enable databases to the user, but for now, we connect through admin
|
|
|
|
# No need to create other databases: Mongo creates them on the fly
|
|
|
|
ynh_mongo_setup_db --db_user="$db_user" --db_name="${MONGO_DB_LIST[0]}"
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
# SYSTEM CONFIGURATION
|
2022-12-27 17:59:56 +01:00
|
|
|
#=================================================
|
2024-01-03 23:19:38 +01:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
2022-12-27 17:59:56 +01:00
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
2024-01-03 23:19:38 +01:00
|
|
|
for i in "${!SERVICES_LIST[@]}"; do
|
|
|
|
service_name="${SERVICES_LIST[i]}"
|
|
|
|
port="${PORT_LIST[i]}"
|
|
|
|
ynh_add_systemd_config --service="${app}-${service_name}"
|
|
|
|
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
|
2022-12-29 10:06:04 +01:00
|
|
|
done
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-12-29 10:06:04 +01:00
|
|
|
ynh_script_progression --message="Starting systemd services..." --weight=1
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
# Start a systemd service
|
2024-01-03 23:19:38 +01:00
|
|
|
for service_name in "${SERVICES_LIST[@]}"; do
|
|
|
|
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
|
2022-12-29 10:06:04 +01:00
|
|
|
done
|
2022-12-27 17:59:56 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|