1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/tracim_ynh.git synced 2024-10-01 13:34:52 +02:00
tracim_ynh/scripts/install

138 lines
5.6 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
api_key=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key="api_key" --value="$api_key"
session_secret=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key="session_secret" --value="$session_secret"
website_title="YunoHost Tracim"
ynh_app_setting_set --app="$app" --key="website_title" --value="$website_title"
admin_mail=$(ynh_user_get_info --username="$admin" --key=mail)
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing NodeJS..."
ynh_install_nodejs --nodejs_version=$nodejs_version
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir/sources"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_add_config --template="development.ini.sample" --destination="$install_dir/sources/backend/development.ini"
chmod 400 "$install_dir/sources/backend/development.ini"
chown "$app:$app" "$install_dir/sources/backend/development.ini"
ynh_add_config --template="configEnv.json.sample" --destination="$install_dir/sources/frontend/configEnv.json"
chmod 400 "$install_dir/sources/frontend/configEnv.json"
chown "$app:$app" "$install_dir/sources/frontend/configEnv.json"
#=================================================
# BUILD APP
#=================================================
ynh_script_progression --message="Building app..."
cp -r "$install_dir/sources/frontend/dist/assets/branding.sample" "$install_dir/sources/frontend/dist/assets/branding"
python3 -m venv "$install_dir/venv"
pushd "$install_dir/sources/backend"
ynh_exec_warn_less "$install_dir/venv/bin/pip" install -r requirements-build.txt
ynh_exec_warn_less "$install_dir/venv/bin/pip" install -r requirements.txt
ynh_exec_warn_less "$install_dir/venv/bin/pip" install -r requirements-full-preview-generator.txt
ynh_exec_warn_less "$install_dir/venv/bin/pip" install -r requirements-db-postgres.txt
ynh_exec_warn_less "$install_dir/venv/bin/pip" install -e "."
popd
ynh_use_nodejs
_corepack_enable
export PATH="$install_dir/bin:$PATH"
pushd "$install_dir/sources"
ynh_exec_warn_less "$ynh_npm" install "i18next-conv@<8" -g
ynh_exec_warn_less ./update_i18n_json_file.sh || exit 1
echo 'nodeLinker: node-modules' >> .yarnrc.yml
ynh_exec_warn_less yarn install
ynh_exec_warn_less ./build_full_frontend.sh
ynh_secure_remove --file="$install_dir/www"
popd
cp -R "$install_dir/sources/frontend/dist" "$install_dir/www"
pushd "$install_dir"
mkdir sessions_data sessions_lock previews
ynh_exec_warn_less tracimcli db init
ynh_exec_warn_less tracimcli user create -e "$admin_mail" -u "$admin" --lang "$language" -p "$password" --profile administrators
ynh_exec_warn_less tracimcli user delete -l admin@admin.admin
popd
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
# Create a dedicated systemd config
ynh_add_supervisor_config --service="$app" --template="supervisord.conf"
yunohost service add uwsgi --log="/var/log/uwsgi/app/$app-web.log"
yunohost service add supervisor --log="/var/log/supervisor/supervisord.log"
ynh_add_config --template="web.ini" --destination="/etc/uwsgi/apps-available/$app-web.ini"
chmod 400 "/etc/uwsgi/apps-available/$app-web.ini"
chown "$app:$app" "/etc/uwsgi/apps-available/$app-web.ini"
ln -sf "/etc/uwsgi/apps-available/$app-web.ini" "/etc/uwsgi/apps-enabled/$app-web.ini"
ynh_add_config --template="webdav.ini" --destination="/etc/uwsgi/apps-available/$app-webdav.ini"
chmod 400 "/etc/uwsgi/apps-available/$app-webdav.ini"
chown "$app:$app" "/etc/uwsgi/apps-available/$app-webdav.ini"
ln -sf "/etc/uwsgi/apps-available/$app-webdav.ini" "/etc/uwsgi/apps-enabled/$app-webdav.ini"
ynh_add_config --template="caldav.ini" --destination="/etc/uwsgi/apps-available/$app-caldav.ini"
chmod 400 "/etc/uwsgi/apps-available/$app-caldav.ini"
chown "$app:$app" "/etc/uwsgi/apps-available/$app-caldav.ini"
ln -sf "/etc/uwsgi/apps-available/$app-caldav.ini" "/etc/uwsgi/apps-enabled/$app-caldav.ini"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting $app's systemd service..."
ynh_systemd_action --service_name="uwsgi" --action="restart" --log_path="/var/log/uwsgi/app/$app-web.log" --line_match="spawned uWSGI"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed"