2020-11-09 22:28:22 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
path_url="/"
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2020-11-10 11:53:07 +01:00
|
|
|
language=$YNH_APP_ARG_LANGUAGE
|
2022-03-03 23:47:47 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
email=$(ynh_user_get_info --username=$admin --key=mail)
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2022-01-14 19:09:22 +01:00
|
|
|
registration_enabled="true"
|
|
|
|
login_enabled="true"
|
|
|
|
captcha_enabled="true"
|
|
|
|
|
2020-11-09 22:28:22 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Validating installation parameters..." --weight=1
|
|
|
|
|
|
|
|
final_path=/var/www/$app
|
|
|
|
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
|
|
|
|
|
|
|
# Register (book) web path
|
|
|
|
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Storing installation settings..." --weight=2
|
|
|
|
|
2021-05-23 10:25:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
|
|
|
ynh_app_setting_set --app=$app --key=path --value=$path_url
|
2021-03-03 21:40:32 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=language --value=$language
|
2022-03-03 23:47:47 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=admin --value=$admin
|
|
|
|
ynh_app_setting_set --app=$app --key=email --value=$email
|
2022-01-14 19:09:22 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=registration_enabled --value=$registration_enabled
|
|
|
|
ynh_app_setting_set --app=$app --key=login_enabled --value=$login_enabled
|
|
|
|
ynh_app_setting_set --app=$app --key=captcha_enabled --value=$captcha_enabled
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD MODIFICATIONS
|
|
|
|
#=================================================
|
|
|
|
# FIND AND OPEN A PORT
|
|
|
|
#=================================================
|
2021-01-09 22:43:59 +01:00
|
|
|
ynh_script_progression --message="Finding an available port..." --weight=0
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
# Find an available port
|
|
|
|
port=$(ynh_find_port --port=3000)
|
|
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2021-05-23 10:38:54 +02:00
|
|
|
ynh_script_progression --message="Installing dependencies..." --weight=15
|
2020-11-09 22:28:22 +01:00
|
|
|
|
2021-03-03 22:02:35 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
2021-10-03 09:12:48 +02:00
|
|
|
ynh_exec_warn_less curl -fsSL https://crystal-lang.org/install.sh | bash -s -- --channel=stable
|
2021-05-23 09:54:30 +02:00
|
|
|
|
2021-05-23 10:38:54 +02:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring system user..." --weight=1
|
|
|
|
|
|
|
|
# Create a system user
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
2020-11-09 22:28:22 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE A POSTGRESQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=2
|
|
|
|
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
db_user=$db_name
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
ynh_psql_test_if_first_run
|
2022-03-27 16:56:30 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=4
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
|
|
|
2023-02-08 12:04:39 +01:00
|
|
|
mkdir -p "$final_path"
|
2023-02-14 19:58:29 +01:00
|
|
|
chown -R $app:www-data "$final_path"
|
2023-02-08 09:44:10 +01:00
|
|
|
|
2023-02-14 20:48:57 +01:00
|
|
|
git config --system --add safe.directory $final_path
|
|
|
|
|
2020-11-10 23:21:34 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from GitHub
|
2023-02-14 20:33:14 +01:00
|
|
|
ynh_exec_as $app git clone https://github.com/iv-org/invidious "$final_path" --quiet
|
2023-02-14 19:56:34 +01:00
|
|
|
|
2021-07-28 15:43:49 +02:00
|
|
|
pushd "$final_path"
|
2023-02-14 20:33:14 +01:00
|
|
|
ynh_exec_as $app git reset --hard --quiet $version_commit
|
2021-07-28 15:43:49 +02:00
|
|
|
popd
|
|
|
|
|
2020-11-10 08:47:46 +01:00
|
|
|
for i in $final_path/config/sql/*.sql ; do
|
|
|
|
ynh_replace_string --match_string="kemal" --replace_string=$db_user --target_file="$i" ;
|
2020-11-10 11:23:51 +01:00
|
|
|
ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < "$i" ;
|
2020-11-10 08:47:46 +01:00
|
|
|
done
|
2020-11-10 08:09:41 +01:00
|
|
|
|
2021-05-23 10:27:58 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2020-11-09 22:28:22 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring NGINX web server..." --weight=3
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC SETUP
|
|
|
|
#=================================================
|
|
|
|
# INSTALL INVIDIOUS
|
|
|
|
#=================================================
|
2021-05-23 10:27:58 +02:00
|
|
|
ynh_script_progression --message="Building Invidious.. (this will take some time and resources!)" --weight=60
|
2020-11-09 22:28:22 +01:00
|
|
|
|
2021-10-02 16:23:12 +02:00
|
|
|
pushd "$final_path"
|
2022-02-25 19:27:51 +01:00
|
|
|
ynh_exec_warn_less shards install --production
|
2021-10-03 08:14:50 +02:00
|
|
|
ynh_exec_warn_less crystal build $final_path/src/invidious.cr --release
|
2021-10-02 16:23:12 +02:00
|
|
|
popd
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MODIFY A CONFIG FILE
|
|
|
|
#=================================================
|
2022-03-27 16:58:34 +02:00
|
|
|
ynh_script_progression --message="Modifying a config file..." --weight=1
|
2020-11-09 22:28:22 +01:00
|
|
|
|
2021-03-03 21:04:16 +01:00
|
|
|
ynh_add_config --template="../conf/config.yml" --destination="$final_path/config/config.yml"
|
2022-03-27 16:58:34 +02:00
|
|
|
|
|
|
|
chmod 600 "$final_path/config/config.yml"
|
|
|
|
chown $app:$app "$final_path/config/config.yml"
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP CRON
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setuping a cron..." --weight=1
|
|
|
|
|
2021-03-03 21:04:16 +01:00
|
|
|
ynh_add_config --template="../conf/cron_invidious" --destination="/etc/cron.d/$app"
|
2021-10-03 07:40:37 +02:00
|
|
|
chown root: "/etc/cron.d/$app"
|
|
|
|
chmod 644 "/etc/cron.d/$app"
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
|
2020-12-04 12:11:13 +01:00
|
|
|
yunohost service add $app --description="Invidious is an alternative front-end to YouTube" --log="/var/log/$app/$app.log"
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=2
|
|
|
|
|
|
|
|
# Start a systemd service
|
2021-03-03 21:04:16 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2021-03-03 21:04:16 +01:00
|
|
|
ynh_script_progression --message="Configuring permissions..." --weight=1
|
2020-11-09 22:28:22 +01:00
|
|
|
|
|
|
|
# Make app public if necessary or protect it
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
then
|
2021-03-03 21:04:16 +01:00
|
|
|
ynh_permission_update --permission="main" --add="visitors"
|
2020-11-09 22:28:22 +01:00
|
|
|
fi
|
|
|
|
|
2022-03-03 23:47:47 +01:00
|
|
|
ynh_permission_create --permission="api" --url="/api" --allowed="visitors" --show_tile="false" --protected="true"
|
|
|
|
|
2020-11-09 22:28:22 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of Invidious completed" --last
|