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 16:57:56 +01:00
|
|
|
mkdir /var/log/$app
|
|
|
|
chown "$app:$app" /var/log/$app
|
|
|
|
|
2024-01-04 15:16:51 +01:00
|
|
|
#=================================================
|
|
|
|
# Configure document storage
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring document storage..." --weight=1
|
|
|
|
|
2024-01-05 16:34:03 +01:00
|
|
|
document_dir=$data_dir/docs
|
|
|
|
ynh_app_setting_set --app="$app" --key=document_dir --value="$document_dir"
|
2024-01-04 15:16:51 +01:00
|
|
|
|
|
|
|
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-04-01 14:28:27 +02:00
|
|
|
# Let's create all databases needed, and assign them to the user
|
2024-04-01 14:44:15 +02:00
|
|
|
new_db_pwd=$(ynh_string_random) # Generate a random password
|
2024-04-01 14:28:27 +02:00
|
|
|
# If $db_pwd is not provided, use new_db_pwd instead for db_pwd
|
|
|
|
db_pwd="${db_pwd:-$new_db_pwd}"
|
|
|
|
|
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-05 16:27:40 +01:00
|
|
|
_install_restart_script_and_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"
|
|
|
|
|
2024-04-01 11:42:02 +02:00
|
|
|
for db_name in "${MONGO_DB_LIST[@]}"; do
|
|
|
|
ynh_mongo_setup_db --db_user="$db_user" --db_pwd="$db_pwd" --db_name="dontCode$tenant${db_name}"
|
|
|
|
done
|
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
|