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

188 lines
5.7 KiB
Text
Raw Normal View History

2018-08-26 19:04:08 +02:00
#!/bin/bash
#=================================================
2019-02-14 19:32:04 +01:00
# GENERIC START
2018-08-26 19:04:08 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2019-02-14 19:32:04 +01:00
# MANAGE SCRIPT FAILURE
2018-08-26 19:04:08 +02:00
#=================================================
2019-02-14 19:32:04 +01:00
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
2018-08-26 19:04:08 +02:00
#=================================================
# 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
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Validating installation parameters..."
2018-08-26 19:04:08 +02:00
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
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Storing installation settings..."
2018-08-26 19:04:08 +02:00
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Configuring firewall..."
2018-08-26 19:04:08 +02:00
2019-02-14 19:32:04 +01:00
# Find a free port
port=$(ynh_find_port 4242)
2019-02-14 19:32:04 +01:00
# Open this port
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port
ynh_app_setting_set $app port $port
2018-08-26 19:04:08 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Installing dependencies..."
2018-08-26 19:04:08 +02:00
2018-08-27 01:00:52 +02:00
ynh_install_app_dependencies python-virtualenv sqlite3 libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev
2018-08-26 19:04:08 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Setting up source files..."
2018-08-26 19:04:08 +02:00
ynh_app_setting_set $app final_path $final_path
2019-02-14 19:32:04 +01:00
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2018-08-26 19:04:08 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Configuring nginx..."
2018-08-26 19:04:08 +02:00
2019-02-14 19:32:04 +01:00
# Create a dedicated nginx config
2018-08-26 19:04:08 +02:00
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Configuring system user..."
# Create a system user
ynh_system_user_create $app
2018-08-26 19:04:08 +02:00
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL PYTHONZ TO GET PYTHON 3.6
#=================================================
# Get pythonz
# curl -kL https://raw.githubusercontent.com/saghul/pythonz/master/pythonz-install
# ./pythonz-install
2018-08-26 21:45:44 +02:00
ynh_setup_source "$final_path/.pythonz" pythonz
2018-08-26 22:53:39 +02:00
export PYTHONZ_ROOT="$final_path/.pythonz"
2018-08-26 19:04:08 +02:00
# Then install it
2018-08-26 21:45:44 +02:00
python $final_path/.pythonz/pythonz_install.py
2018-08-26 19:04:08 +02:00
# if ! grep --quiet "YunoRunner" /root/.bashrc
# then
2018-08-26 21:45:44 +02:00
# [[ -s $final_path/.pythonz/etc/bashrc ]] && source $final_path/.pythonz/etc/bashrc # Added by YunoRunner
2018-08-26 19:04:08 +02:00
# fi
# Install Python 3.6.6
2018-08-26 21:45:44 +02:00
$final_path/.pythonz/bin/pythonz install 3.6.6
2018-08-26 19:04:08 +02:00
#=================================================
# INSTALL YUNORUNNER DEPENDENCIES
#=================================================
( cd $final_path
2018-08-26 21:45:44 +02:00
virtualenv -p $($final_path/.pythonz/bin/pythonz locate 3.6.6) ve3
2018-08-26 19:04:08 +02:00
ve3/bin/pip3 install -r requirements.txt )
#=================================================
# SETUP SYSTEMD
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Configuring a systemd service..."
2018-08-26 19:04:08 +02:00
2019-02-14 19:32:04 +01:00
# Create a dedicated systemd config
2018-08-26 19:04:08 +02:00
ynh_add_systemd_config
#=================================================
# CHANGE PORT IN YUNORUNNER
#=================================================
2018-11-04 20:48:37 +01:00
ynh_replace_string "__PORT__" "$port" "/etc/systemd/system/$app.service"
2019-02-14 19:32:04 +01:00
# Calculate and store the config file checksum into the app settings
2018-11-04 20:48:37 +01:00
ynh_store_file_checksum "/etc/systemd/system/$app.service"
systemctl daemon-reload
2018-08-26 19:04:08 +02:00
#=================================================
# GENERIC FINALISATION
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
2019-02-14 19:32:04 +01:00
# Set permissions to app files
2018-08-28 12:47:16 +02:00
chown -R $app:root $final_path
2018-08-26 19:04:08 +02:00
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
2019-02-14 19:32:04 +01:00
yunohost service add $app --description "$app daemon for YunoRunner"
2018-08-26 19:04:08 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2019-02-14 19:32:04 +01:00
ynh_script_progression --message="Configuring SSOwat..."
2018-08-26 19:04:08 +02:00
# Make app public
ynh_app_setting_set $app skipped_uris "/"
#=================================================
# RELOAD NGINX
#=================================================
2019-02-14 19:32:04 +01:00
ynh_print_info "Reloading nginx..."
2018-08-26 19:04:08 +02:00
2019-02-14 19:32:04 +01:00
systemctl reload nginx
2018-08-26 19:36:20 +02:00
#=================================================
# START YUNORUNNER
#=================================================
ynh_system_reload --service_name=$app --action=start
2019-02-14 19:32:04 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info "Installation of $app completed"