1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/codimd_ynh.git synced 2024-09-03 18:16:32 +02:00
codimd_ynh/scripts/install

183 lines
6.2 KiB
Text
Raw Normal View History

2018-11-21 16:11:09 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2020-05-21 12:49:24 +02:00
source _common.sh
2018-11-21 16:11:09 +01:00
source /usr/share/yunohost/helpers
#=================================================
2019-03-13 16:48:29 +01:00
# MANAGE SCRIPT FAILURE
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_clean_setup () {
ynh_clean_check_starting
}
2019-03-13 16:48:29 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2019-03-13 16:46:11 +01:00
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# RETRIEVE ARGUMENTS FROM THE MANIFEST
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
domain=$YNH_APP_ARG_DOMAIN
2021-06-13 10:36:34 +02:00
path_url="/"
2019-03-13 16:48:29 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2018-11-21 16:11:09 +01:00
app=$YNH_APP_INSTANCE_NAME
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Validating installation parameters..." --weight=1
2018-11-21 16:11:09 +01:00
2019-03-13 16:48:29 +01:00
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
2019-03-13 16:48:29 +01:00
# Register (book) web path
2020-05-29 23:02:01 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2018-11-21 16:11:09 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=2
2021-05-08 11:06:29 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
#=================================================
# STANDARD MODIFICATIONS
2020-05-21 12:49:24 +02:00
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-01-09 22:35:01 +01:00
ynh_script_progression --message="Finding an available port..." --weight=2
2019-11-28 02:05:34 +01:00
2020-05-21 12:49:24 +02:00
# Find an available port
2020-05-24 20:32:52 +02:00
port=$(ynh_find_port --port=3000)
2020-05-29 22:31:43 +02:00
ynh_app_setting_set --app=$app --key=port --value=$port
2019-11-28 02:05:34 +01:00
2018-11-21 16:11:09 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
# INSTALL DEPENDENCIES
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Installing dependencies..." --weight=20
2019-03-13 16:48:29 +01:00
2021-05-08 11:06:29 +02:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2020-05-21 12:49:24 +02:00
# Install Nodejs
2020-05-29 22:31:43 +02:00
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2018-11-21 16:35:21 +01:00
2021-05-08 11:06:29 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=2
# Create a system user
2021-06-02 18:36:39 +02:00
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-05-08 11:06:29 +02:00
#=================================================
# CREATE A POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
2019-03-13 16:48:29 +01:00
2020-05-21 12:49:24 +02:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
2021-05-08 11:23:20 +02:00
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
2020-05-29 22:31:43 +02:00
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
2020-05-23 09:14:00 +02:00
ynh_psql_test_if_first_run
2021-05-08 11:23:20 +02:00
ynh_psql_setup_db --db_user=$db_name --db_name=$db_name
2018-11-21 19:24:30 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2018-11-21 19:24:30 +01:00
#=================================================
2020-05-21 12:49:24 +02:00
ynh_script_progression --message="Setting up source files..." --weight=2
2018-11-21 19:24:30 +01:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2019-03-13 16:48:29 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2020-05-29 22:31:43 +02:00
ynh_setup_source --dest_dir=$final_path
2020-05-21 12:49:24 +02:00
2021-06-21 12:00:29 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2021-06-13 10:41:28 +02:00
2020-05-21 12:49:24 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=2
2020-05-21 12:49:24 +02:00
2020-10-12 22:05:07 +02:00
# Create a dedicated NGINX config
2020-05-21 12:49:24 +02:00
ynh_add_nginx_config
2018-11-21 16:11:09 +01:00
#=================================================
# SPECIFIC SETUP
#==============================================
# INSTALL CODIMD
#==============================================
2020-12-14 10:15:40 +01:00
ynh_script_progression --message="Building CodiMD... (this will take some time and resources!)" --weight=24
2021-06-13 11:14:42 +02:00
pushd $final_path
ynh_use_nodejs
2021-06-13 15:04:04 +02:00
ynh_exec_as $app env $ynh_node_load_PATH bin/setup
ynh_exec_as $app env $ynh_node_load_PATH npm run build
2021-06-13 11:14:42 +02:00
popd
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# MODIFY A CONFIG FILE
2018-11-21 16:11:09 +01:00
#=================================================
ynh_script_progression --message="Modifying a config file..."
2018-11-21 16:11:09 +01:00
2021-05-08 11:06:29 +02:00
path=${path_url:1}
ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config.json"
ynh_add_config --template="../conf/.sequelizerc.example" --destination="$final_path/.sequelizerc"
2021-06-02 18:36:39 +02:00
chmod 600 $final_path/config.json
chmod 600 $final_path/.sequelizerc
2021-06-13 11:14:42 +02:00
chmod +x $final_path/app.js
2021-06-13 10:11:00 +02:00
2021-05-08 15:31:11 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_add_systemd_config
2019-03-13 16:46:11 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
2018-11-21 16:11:09 +01:00
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2018-11-21 16:11:09 +01:00
2020-12-04 09:52:22 +01:00
yunohost service add $app --description="Collaborative Markdown notes" --log="/var/log/$app/$app.log"
2018-11-21 16:11:09 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
# START SYSTEMD SERVICE
2018-11-21 16:11:09 +01:00
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
2019-03-13 16:48:29 +01:00
# Start a systemd service
2021-05-08 12:13:28 +02:00
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="HTTP Server listening"
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# SETUP SSOWAT
2018-11-21 16:11:09 +01:00
#=================================================
2021-05-08 12:13:28 +02:00
ynh_script_progression --message="Configuring permissions..." --weight=1
2018-11-21 16:11:09 +01:00
2020-06-22 18:33:34 +02:00
# Make app public if necessary or protect it
2020-05-31 11:11:31 +02:00
if [ $is_public -eq 1 ]
then
2021-05-08 10:53:13 +02:00
ynh_permission_update --permission="main" --add="visitors"
2020-05-31 11:11:31 +02:00
fi
2019-03-13 16:48:29 +01:00
2019-11-28 02:05:34 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
2019-11-28 02:05:34 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-10-12 22:05:07 +02:00
ynh_script_progression --message="Installation of CodiMD completed" --last