1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/tandoor_ynh.git synced 2024-09-03 20:35:56 +02:00
tandoor_ynh/scripts/install

133 lines
4.5 KiB
Text
Raw Normal View History

2022-08-06 19:00:44 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-01-27 15:12:48 +01:00
# INITIALIZE AND STORE SETTINGS
2022-08-06 19:00:44 +02:00
#=================================================
2022-08-06 23:20:30 +02:00
secretkey=$(ynh_string_random --length=12)
2024-01-27 15:12:48 +01:00
ynh_app_setting_set --app=$app --key=secretkey --value="$secretkey"
2022-08-06 19:00:44 +02:00
2024-01-27 15:12:48 +01:00
timezone="$(cat /etc/timezone)"
2022-08-06 19:00:44 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-01-27 15:12:48 +01:00
ynh_script_progression --message="Installing NodeJS..." --weight=3
2022-08-06 19:00:44 +02:00
2022-08-06 23:20:30 +02:00
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2022-08-06 19:00:44 +02:00
#=================================================
2022-08-06 23:20:30 +02:00
# CREATE A PostgreSQL DATABASE
2022-08-06 19:00:44 +02:00
#=================================================
2024-01-27 15:12:48 +01:00
ynh_script_progression --message="Configuring a PostgreSQL database..." --weight=1
2022-08-06 23:20:30 +02:00
2024-01-27 15:12:48 +01:00
ynh_psql_execute_as_root --sql="GRANT ALL PRIVILEGES ON DATABASE $db_name TO $db_user;"
ynh_psql_execute_as_root --sql="ALTER DATABASE $db_name OWNER TO $db_user;"
ynh_psql_execute_as_root --sql="ALTER USER $db_name WITH SUPERUSER;"
2022-08-06 19:00:44 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2022-08-07 20:41:00 +02:00
ynh_script_progression --message="Setting up source files..." --weight=1
2022-08-06 19:00:44 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2024-01-27 15:12:48 +01:00
ynh_setup_source --dest_dir="$install_dir"
2022-08-06 19:00:44 +02:00
2024-01-27 15:12:48 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
2022-08-09 22:53:41 +02:00
2024-01-27 15:12:48 +01:00
chmod 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
2022-08-10 02:40:47 +02:00
2022-08-06 19:00:44 +02:00
#=================================================
2022-08-06 23:20:30 +02:00
# ADD A CONFIGURATION
#=================================================
2022-08-07 20:41:00 +02:00
ynh_script_progression --message="Adding a configuration file..." --weight=1
2022-08-06 23:20:30 +02:00
2024-01-27 15:12:48 +01:00
ynh_add_config --template=".env.template" --destination="$install_dir/.env"
2022-08-06 23:20:30 +02:00
2024-01-27 15:12:48 +01:00
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
2022-08-06 23:20:30 +02:00
2022-08-10 00:43:15 +02:00
version=$(ynh_app_upstream_version)
2024-01-27 15:12:48 +01:00
ynh_add_config --template="version.py" --destination="$install_dir/recipes/version.py"
chmod 400 "$install_dir/recipes/version.py"
chown $app:$app "$install_dir/recipes/version.py"
2022-08-10 00:43:15 +02:00
2022-08-06 19:00:44 +02:00
#=================================================
2022-08-06 23:20:30 +02:00
# SPECIFIC SETUP
2022-08-06 19:00:44 +02:00
#=================================================
2022-08-06 23:57:01 +02:00
ynh_script_progression --message="Setting up Tandoor venv..." --weight=1
2022-08-06 23:20:30 +02:00
2022-08-08 06:44:05 +02:00
if [[ $(ynh_get_debian_release) == "bullseye" ]]; then
py_app_version="python3"
else
myynh_install_python --python="$py_required_version"
fi
2024-01-27 15:12:48 +01:00
ynh_exec_as $app $py_app_version -m venv "$install_dir/venv"
2022-08-06 23:20:30 +02:00
2022-08-07 20:38:59 +02:00
ynh_script_progression --message="Installing dependencies via pip..." --weight=4
2024-01-27 15:12:48 +01:00
pushd "$install_dir"
ynh_exec_warn_less ynh_exec_as $app "$install_dir/venv/bin/pip3" install -r requirements.txt
2022-08-06 23:20:30 +02:00
popd
2022-08-06 23:57:01 +02:00
ynh_script_progression --message="Building frontend..." --weight=5
2024-01-27 15:12:48 +01:00
pushd "$install_dir/vue"
2022-08-06 23:20:30 +02:00
ynh_use_nodejs
2022-08-07 22:08:40 +02:00
ynh_exec_warn_less yarn install
ynh_exec_warn_less yarn build
2022-08-06 23:20:30 +02:00
popd
2022-08-07 22:08:40 +02:00
ynh_script_progression --message="Running migrations and generating static files..." --weight=2
2024-01-27 15:12:48 +01:00
pushd "$install_dir"
2022-08-07 20:38:59 +02:00
# load environment variables
export $(cat "/var/www/$app/.env" |grep "^[^#]" | xargs)
2024-01-27 15:12:48 +01:00
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py migrate
2022-08-07 03:44:38 +02:00
ynh_psql_execute_as_root --sql="ALTER USER $app WITH NOSUPERUSER;"
2024-01-27 15:12:48 +01:00
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py collectstatic --no-input
ynh_exec_as $app "$install_dir/venv/bin/python3" manage.py collectstatic_js_reverse
2022-08-06 23:20:30 +02:00
popd
2022-08-06 19:00:44 +02:00
#=================================================
2024-01-27 15:12:48 +01:00
# SYSTEM CONFIGURATION
2022-08-06 19:00:44 +02:00
#=================================================
2024-01-27 15:12:48 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2022-08-06 19:00:44 +02:00
2024-01-27 15:12:48 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2022-08-06 19:00:44 +02:00
2024-01-27 15:12:48 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
yunohost service add "$app" --description="Smart recipe management" --log="/var/log/$app/$app.log"
2022-08-06 19:00:44 +02:00
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# START SYSTEMD SERVICE
#=================================================
2022-08-07 20:41:00 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2022-08-06 19:00:44 +02:00
# Start a systemd service
2024-01-27 15:12:48 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
2022-08-06 19:00:44 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-08-07 20:41:00 +02:00
ynh_script_progression --message="Installation of $app completed" --last