#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= ynh_clean_setup () { ### Remove this function if there's nothing to clean before calling the remove script. true } # 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="/" version=$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep 'tag_name' | cut -d\" -f4) admin=$YNH_APP_ARG_ADMIN password=$(ynh_string_random --length=12) sitename=$YNH_APP_ARG_SITENAME random=$(ynh_string_random --length=10) app=$YNH_APP_INSTANCE_NAME #================================================= # 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=1 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=admin --value=$admin ynh_app_setting_set --app=$app --key=password --value=$password ynh_app_setting_set --app=$app --key=sitename --value=$sitename ynh_app_setting_set --app=$app --key=random --value=$random #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_script_progression --message="Finding an available port..." --weight=1 # Find an available port port_lemmy=$(ynh_find_port --port=8536) port_ui=$(ynh_find_port --port=1235) port_pictrs=$(ynh_find_port --port=8537) port_iframely=$(ynh_find_port --port=8061) ynh_app_setting_set --app=$app --key=port_lemmy --value=$port_lemmy ynh_app_setting_set --app=$app --key=port_ui --value=$port_ui ynh_app_setting_set --app=$app --key=port_pictrs --value=$port_pictrs ynh_app_setting_set --app=$app --key=port_iframely --value=$port_iframely #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --weight=1 #ynh_install_app_dependencies $pkg_dependencies # Install Docker and compose curl -sSL https://get.docker.com | sh systemctl enable docker --quiet curl -L https://github.com/docker/compose/releases/download/${version}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path mkdir "$final_path" cp -f ../conf/default.yml "$final_path/docker-compose.yml" cp -f ../conf/default.yml "$final_path/lemmy.hjson" cp -f ../conf/default.yml "$final_path/iframely.config.local.js" pushd "$final_path" mkdir -p volumes/pictrs chown -R 991:991 volumes/pictrs popd #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config 'port_lemmy port_ui port_pictrs port_iframely' #================================================= # MODIFY A CONFIG FILE #================================================= ynh_replace_string --match_string="__ADMIN__" --replace_string="$admin" --target_file="$final_path/lemmy.hjson" ynh_replace_string --match_string="__ADMIN_PASS__" --replace_string="$password" --target_file="$final_path/lemmy.hjson" ynh_replace_string --match_string="__NAME__" --replace_string="$sitename" --target_file="$final_path/lemmy.hjson" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/lemmy.hjson" ynh_replace_string --match_string="__RANDOM__" --replace_string="$random" --target_file="$final_path/lemmy.hjson" ynh_replace_string --match_string="__PORT__LEMMY__" --replace_string="$port_lemmy" --target_file="$final_path/docker-compose.yml" ynh_replace_string --match_string="__PORT_UI__" --replace_string="$port_ui" --target_file="$final_path/docker-compose.yml" ynh_replace_string --match_string="__PORT_PICTRS__" --replace_string="replace_string" --target_file="$final_path/docker-compose.yml" ynh_replace_string --match_string="__PORT_IFRAMELY__" --replace_string="$port_pictrs" --target_file="$final_path/docker-compose.yml" ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/iframely.config.local.js" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 ynh_permission_update --permission="main" --add="visitors" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # Run Lemmy through Docker #================================================= cd "$final_path" && docker-compose up -d #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last