1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00

Update install

This commit is contained in:
frju365 2018-11-03 21:46:35 +01:00 committed by GitHub
parent f0cbda925e
commit 970155b30e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,10 +13,17 @@ source /usr/share/yunohost/helpers
# MANAGE SCRIPT FAILURE # 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 # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
# Retrieve arguments #=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
domain=$YNH_APP_ARG_DOMAIN domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
@ -25,76 +32,117 @@ app=$YNH_APP_INSTANCE_NAME
script_dir=$PWD script_dir=$PWD
# Check variables are not empty #=================================================
CHECK_VAR "$app" "app name not set" # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
CHECK_VAR "$script_dir" "script_dir not set" #=================================================
CHECK_PATH # Check and fix path syntax ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app".
CHECK_DOMAINPATH # Check and fix domain disponibility ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
final_path=/var/www/$app
test ! -e "$final_path" || ynh_die "This path already contains a folder"
CHECK_FINALPATH # Check final path
# Check domain with regex
domain_regex=$(echo "$domain" | sed 's@-@.@g') domain_regex=$(echo "$domain" | sed 's@-@.@g')
# Normalize the url path syntax
path_url=$(ynh_normalize_url_path $path_url)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
CHECK_VAR "$domain_regex" "domain_regex empty" CHECK_VAR "$domain_regex" "domain_regex empty"
FIND_PORT 8096 # Check port availability #=================================================
# FIND AND OPEN A PORT
#=================================================
# Find a free port
port=$(ynh_find_port 8095)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
# Save app settings
ynh_app_setting_set $app domain $domain ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app is_public $is_public ynh_app_setting_set $app is_public $is_public
ynh_app_setting_set $app port $port ynh_app_setting_set $app port $port
# Install dependencies #=================================================
ynh_package_update # INSTALL DEPENDENCIES
ynh_package_install build-essential libssl-dev libpq-dev #=================================================
# Copy files to the right place
sudo mkdir "${final_path}"
ynh_app_setting_set $app final_path $final_path
# Get source
SETUP_SOURCE
# Copy it to Nginx conf directory
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
if [ $is_public -eq 1 ];
then
sudo sed -i "s@#--PRIVATE--@@g" /etc/nginx/conf.d/$domain.d/$app.conf
fi
## Copy and fix variable into lstu config
sudo cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
sudo sed -i "s@__DOMAIN__@$domain@g" "${final_path}/lstu.conf"
sudo sed -i "s@__PATH__@$path@g" "${final_path}/lstu.conf"
sudo sed -i "s@__PORT__@$port@g" "${final_path}/lstu.conf"
secret=$(ynh_string_random 24)
CHECK_VAR "$secret" "secret empty"
sudo sed -i "s@__SECRET__@$secret@g" "${final_path}/lstu.conf"
STORE_MD5_CONFIG "lstu.conf" "${final_path}/lstu.conf"
# Install systemd script
sudo cp ../conf/lstu.service /etc/systemd/system/lstu.service
sudo chown root: /etc/systemd/system/lstu.service
sudo sed -i "s@__FINALPATH__@$final_path/@g" /etc/systemd/system/lstu.service
# Install logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/$app
sudo sed -i "s@__FINALPATH__@$final_path@g" /etc/logrotate.d/$app
ynh_install_app_dependencies build-essential libssl-dev libpq-dev
# Install Carton # Install Carton
echo yes | sudo cpan Carton echo yes | sudo cpan Carton
# Install lstu's dependencies via carton #=================================================
sudo mkdir -p /var/log/$app/ # DOWNLOAD, CHECK AND UNPACK SOURCE
cd $final_path #=================================================
sudo carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
# Change variables in nginx configuration ynh_app_setting_set $app final_path $final_path
sudo sed -i "s@__PATH__@$path@g" /etc/nginx/conf.d/$domain.d/$app.conf # Download, check integrity, uncompress and patch the source from app.src
sudo sed -i "s@__PORT__@$port@g" /etc/nginx/conf.d/$domain.d/$app.conf ynh_setup_source "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
### `ynh_add_nginx_config` will use the file conf/nginx.conf
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
## Copy and fix variable into lstu config
#=================================================
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
secret=$(ynh_string_random 24)
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
ynh_store_file_checksum "${final_path}/lstu.conf"
#=================================================
# SETUP SYSTEMD
#=================================================
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# Install lstu's dependencies via carton
#=================================================
carton install 2>&1 | sudo tee -a "/var/log/$app/setup_carton.log"
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage application logfile(s)
ynh_use_logrotate
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app.log"
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public or private # Make app public or private
ynh_app_setting_set $app skipped_uris "/" ynh_app_setting_set $app skipped_uris "/"
@ -104,34 +152,35 @@ then # If the app is private, only the shortened URLs are publics
path="" path=""
fi fi
ynh_app_setting_set $app protected_regex "$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$" ynh_app_setting_set $app protected_regex "$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$"
else
ynh_replace_string "#--PRIVATE--" "" "/etc/nginx/conf.d/$domain.d/$app.conf"
fi fi
#=================================================
# Making log symbolic link to /var/log # Making log symbolic link to /var/log
sudo touch /var/log/$app/production.log #=================================================
sudo chown www-data: /var/log/$app/production.log
sudo ln -s /var/log/$app/production.log "$final_path/log/production.log"
touch /var/log/$app/production.log
chown $app:$app /var/log/$app/production.log
ln -s /var/log/$app/production.log "$final_path/log/production.log"
#=================================================
# Configure owner # Configure owner
sudo chown -R www-data: $final_path #=================================================
sudo chown -R $app:$app $final_path
#=================================================
# Start lstu # Start lstu
sudo systemctl daemon-reload #=================================================
sudo systemctl start lstu.service
sudo systemctl enable lstu.service
# Set right permissions on new files created at first start systemctl enable lstu.service
sudo chown -R www-data: "$final_path" systemctl start lstu.service
# Add lstu as a service #=================================================
sudo yunohost service add lstu -l $final_path/log/production.log # RELOAD NGINX
#=================================================
if [ $is_public -eq 0 ];
then
# Delete public access
ynh_app_setting_delete $app unprotected_uris
# Regenerate SSOwat's configuration
sudo yunohost app ssowatconf
fi
# Reload Nginx # Reload Nginx
sudo service nginx reload sudo service nginx reload