mirror of
https://github.com/YunoHost-Apps/peertube_ynh.git
synced 2024-09-03 19:56:29 +02:00
129 lines
4.9 KiB
Bash
129 lines
4.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key="mail")
|
|
admin_pass=$(ynh_string_random --length=24)
|
|
secrets_peertube=$(ynh_string_random --length=24)
|
|
|
|
#=================================================
|
|
# STORE SETTINGS FROM MANIFEST
|
|
#=================================================
|
|
ynh_script_progression --message="Storing installation settings..."
|
|
|
|
ynh_app_setting_set --app=$app --key=secrets_peertube --value=$secrets_peertube
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
|
|
|
#=================================================
|
|
# CREATE A POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Creating a PostgreSQL database..."
|
|
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database=$db_name
|
|
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database=$db_name
|
|
|
|
#=================================================
|
|
# CONFIGURE REDIS
|
|
#=================================================
|
|
|
|
redis_db=$(ynh_redis_get_free_db)
|
|
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
|
|
|
|
#=================================================
|
|
# 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"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring NGINX web server..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
mkdir -p "/var/log/$app"
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
ynh_use_logrotate
|
|
|
|
yunohost service add $app --description="$app daemon for Peertube" --log="/var/log/$app/$app.log" --needs_exposed_ports $port_rtmp
|
|
|
|
#=================================================
|
|
# BUILD YARN DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Building Yarn dependencies..."
|
|
|
|
pushd "$install_dir"
|
|
ynh_use_nodejs
|
|
npm install -g npm
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install --production --pure-lockfile
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean
|
|
popd
|
|
|
|
#=================================================
|
|
# ADD A CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Adding a configuration file..."
|
|
|
|
ynh_add_config --template="../conf/production.yaml" --destination="$install_dir/config/production.yaml"
|
|
|
|
chmod 400 "$install_dir/config/production.yaml"
|
|
chown $app:$app "$install_dir/config/production.yaml"
|
|
|
|
ynh_add_config --template="../conf/local-production.json" --destination="$install_dir/config/local-production.json"
|
|
|
|
chmod 600 "$install_dir/config/local-production.json"
|
|
chown $app:$app "$install_dir/config/local-production.json"
|
|
|
|
#=================================================
|
|
# INSTALL LDAP PLUGIN
|
|
#=================================================
|
|
ynh_script_progression --message="Installing $app plugin and password..."
|
|
|
|
pushd "$install_dir"
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-auth-ldap
|
|
ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run plugin:install -- --npm-name peertube-plugin-livechat
|
|
echo $admin_pass | ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH NODE_CONFIG_DIR="$install_dir/config" NODE_ENV=production $ynh_npm run reset-password -- -u root
|
|
popd
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Started"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|