#!/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=$YNH_APP_ARG_PATH app=$YNH_APP_INSTANCE_NAME #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= ynh_print_info "Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die "This path already contains a folder" # Normalize the url path syntax path_url=$(ynh_normalize_url_path $path_url) # Register (book) web path ynh_webpath_register $app $domain $path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_print_info "Storing installation settings..." ynh_app_setting_set $app domain $domain ynh_app_setting_set $app path $path_url #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= ynh_print_info "Configuring firewall..." # Find a free port port=$(ynh_find_port 4242) # Open this port ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port ynh_app_setting_set $app port $port #================================================= # INSTALL DEPENDENCIES #================================================= ynh_print_info "Installing dependencies..." ynh_install_app_dependencies python-virtualenv sqlite3 libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info "Setting up source files..." ynh_app_setting_set $app final_path $final_path # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source "$final_path" #================================================= # NGINX CONFIGURATION #================================================= ynh_print_info "Configuring nginx..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= ynh_print_info "Configuring system user..." # Create a system user ynh_system_user_create $app #================================================= # SPECIFIC SETUP #================================================= # INSTALL PYTHONZ TO GET PYTHON 3.6 #================================================= # Get pythonz # curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install # ./pythonz-install ynh_setup_source "$final_path/.pythonz" pythonz export PYTHONZ_ROOT="$final_path/.pythonz" # Then install it python $final_path/.pythonz/pythonz_install.py # if ! grep --quiet "YunoRunner" /root/.bashrc # then # [[ -s $final_path/.pythonz/etc/bashrc ]] && source $final_path/.pythonz/etc/bashrc # Added by YunoRunner # fi # Install Python 3.6.6 $final_path/.pythonz/bin/pythonz install 3.6.6 #================================================= # INSTALL YUNORUNNER DEPENDENCIES #================================================= ( cd $final_path virtualenv -p $($final_path/.pythonz/bin/pythonz locate 3.6.6) ve3 ve3/bin/pip3 install -r requirements.txt ) #================================================= # SETUP SYSTEMD #================================================= ynh_print_info "Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config #================================================= # CHANGE PORT IN YUNORUNNER #================================================= ynh_replace_string "__PORT__" "$port" "/etc/systemd/system/$app.service" # Calculate and store the config file checksum into the app settings ynh_store_file_checksum "/etc/systemd/system/$app.service" systemctl daemon-reload #================================================= # GENERIC FINALISATION #================================================= # SECURING FILES AND DIRECTORIES #================================================= # Set permissions to app files chown -R $app:root $final_path #================================================= # ENABLE SERVICE IN ADMIN PANEL #================================================= yunohost service add $app --description "$app daemon for YunoRunner" #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring SSOwat..." # Make app public ynh_app_setting_set $app skipped_uris "/" #================================================= # RELOAD NGINX #================================================= ynh_print_info "Reloading nginx..." systemctl reload nginx #================================================= # START YUNORUNNER #================================================= ynh_system_reload --service_name=$app --action=start #================================================= # END OF SCRIPT #================================================= ynh_print_info "Installation of $app completed"