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

179 lines
6.1 KiB
Text
Raw Normal View History

2018-11-21 16:11:09 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-11-28 02:05:34 +01:00
source ynh_add_extra_apt_repos__3
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
#=================================================
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
2019-11-27 16:27:54 +01:00
path_url="/"
2019-03-13 16:48:29 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
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
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Validating installation parameters..."
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 "This path already contains a folder"
# Register (book) web path
2019-11-28 10:30:38 +01:00
ynh_webpath_register "$app" "$domain" $path_url
2018-11-21 16:11:09 +01:00
2019-11-28 02:05:34 +01:00
port=$(ynh_find_port 3000)
db_user=$app
db_name=$app
db_pass=$(ynh_string_random 20)
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# STORE SETTINGS FROM MANIFEST
2018-11-21 16:11:09 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Storing installation settings..."
2018-11-21 16:11:09 +01:00
2019-11-28 10:30:38 +01:00
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path $path_url
ynh_app_setting_set "$app" is_public "$is_public"
ynh_app_setting_set "$app" port "$port"
ynh_app_setting_set "$app" db_pass "$db_pass"
ynh_app_setting_set "$app" final_path "$final_path"
2018-11-21 16:35:21 +01:00
2019-03-13 16:48:29 +01:00
#==============================================
# INSTALL POSTGRES
#==============================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Installing dependencies..."
2019-03-13 16:48:29 +01:00
ynh_install_app_dependencies postgresql apt-transport-https
2018-11-21 16:35:21 +01:00
2019-11-28 02:05:34 +01:00
# Install Yarn
ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
2019-03-13 16:48:29 +01:00
2020-03-09 18:06:43 +01:00
ynh_install_nodejs 10
2019-03-13 16:48:29 +01:00
#==============================================
# CREATE DB
#==============================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Creating a database..."
2019-03-13 16:48:29 +01:00
ynh_psql_test_if_first_run
2019-11-28 10:30:38 +01:00
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pass"
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
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Setting up source files..."
2018-11-21 19:24:30 +01:00
2019-03-13 16:48:29 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
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
#=================================================
2019-03-13 16:48:29 +01:00
# Main config File
2019-11-28 02:05:34 +01:00
ynh_replace_string "__PORT__" "$port" "../conf/config.json.example"
ynh_replace_string "__DOMAIN__" "$domain" "../conf/config.json.example"
ynh_replace_string "__PATH__" "${path_url:1}" "../conf/config.json.example"
ynh_replace_string "__DB_USER__" "$db_user" "../conf/config.json.example"
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/config.json.example"
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/config.json.example"
2019-11-28 10:30:38 +01:00
cp ../conf/config.json.example "$final_path"/config.json
2019-11-28 02:05:34 +01:00
ynh_store_file_checksum "$final_path/config.json"
2019-03-13 16:48:29 +01:00
# DB Config File
ynh_replace_string "__DB_USER__" "$db_user" "../conf/.sequelizerc.example"
ynh_replace_string "__DB_NAME__" "$db_name" "../conf/.sequelizerc.example"
ynh_replace_string "__DB_PASS__" "$db_pass" "../conf/.sequelizerc.example"
2019-11-28 10:30:38 +01:00
cp ../conf/.sequelizerc.example "$final_path"/.sequelizerc
2019-03-13 16:48:29 +01:00
#==============================================
# INSTALL CODIMD
#==============================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Building application... (this may take some time and resources!)"
2019-03-13 16:48:29 +01:00
2019-11-28 10:30:38 +01:00
pushd "$final_path" || exit
2019-11-28 02:05:34 +01:00
./bin/setup
yarn run build
#node_modules/.bin/sequelize db:migrate
2019-11-28 10:30:38 +01:00
popd || exit
2018-11-21 16:11:09 +01:00
2018-11-21 20:09:14 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# NGINX CONFIGURATION
2018-11-21 20:09:14 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Configuring nginx web server..."
2018-11-21 20:09:14 +01:00
2019-03-13 16:48:29 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2018-11-21 20:09:14 +01:00
2018-11-21 16:11:09 +01:00
#=================================================
2019-03-13 16:48:29 +01:00
# CREATE DEDICATED USER
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Configuring system user..."
2019-03-13 16:48:29 +01:00
# Create a system user
2019-11-28 10:30:38 +01:00
ynh_system_user_create "$app"
chown -R "$app":"$app" "$final_path"
2019-03-13 16:48:29 +01:00
2019-03-13 16:46:11 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
# SETUP SYSTEMD
2018-11-21 16:11:09 +01:00
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Configuring a systemd service..."
2018-11-21 16:11:09 +01:00
2019-11-28 02:05:34 +01:00
ynh_replace_string "__APP__" "$app" "../conf/systemd.service"
ynh_replace_string "__FINALPATH__" "$final_path" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
ynh_add_systemd_config
2018-11-21 16:11:09 +01:00
2019-11-28 10:30:38 +01:00
yunohost service add "$app" --description "CodiMD daemon"
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
#=================================================
2019-03-13 16:48:29 +01:00
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Starting $app..."
2019-03-13 16:48:29 +01:00
2019-11-28 10:30:38 +01:00
ynh_systemd_action --service_name="$app" --action="start"
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
#=================================================
2019-11-28 02:05:34 +01:00
ynh_script_progression --message="Configuring SSOwat..."
2019-03-13 16:48:29 +01:00
# If app is public, add url to SSOWat conf as skipped_uris
2019-11-28 10:30:38 +01:00
if [ "$is_public" -eq 1 ]; then
2019-03-13 16:48:29 +01:00
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
fi
2019-11-28 02:05:34 +01:00
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading nginx web server..."
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last