mirror of
https://github.com/YunoHost-Apps/dont-code_ynh.git
synced 2024-09-03 18:26:34 +02:00
132 lines
4.8 KiB
Bash
Executable file
132 lines
4.8 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_mongo_db__2
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..." --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:$app" "$install_dir"
|
|
|
|
mkdir /var/log/$app
|
|
chown "$app:$app" /var/log/$app
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|
|
|
ynh_add_config --template=".env" --destination="$install_dir/.env"
|
|
|
|
chmod 400 "$install_dir/.env"
|
|
chown $app:$app "$install_dir/.env"
|
|
|
|
#=================================================
|
|
# ADD SSH ACCESS
|
|
#=================================================
|
|
|
|
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"
|
|
|
|
chown -R "$app:$app" "$install_dir/.ssh"
|
|
chmod 700 "$install_dir/.ssh"
|
|
chmod 600 "$install_dir/.ssh/authorized_keys"
|
|
|
|
# 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"
|
|
|
|
# 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"
|
|
fi
|
|
|
|
#=================================================
|
|
# INSTALL MONGO
|
|
#=================================================
|
|
ynh_script_progression --message="Installing MongoDB..." --weight=1
|
|
|
|
# Install the required version of Mongo
|
|
ynh_install_mongo --mongo_version=$mongo_version
|
|
|
|
#=================================================
|
|
# CREATE A MONGO DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating the Mongo databases..." --weight=1
|
|
|
|
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]}"
|
|
|
|
#=================================================
|
|
# SYSTEM CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
|
|
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"
|
|
done
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting systemd services..." --weight=1
|
|
|
|
# Start a systemd service
|
|
for service_name in "${SERVICES_LIST[@]}"; do
|
|
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
|
|
done
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|