1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shuri_ynh.git synced 2024-09-03 20:16:20 +02:00

refactoring

This commit is contained in:
frju365 2018-10-28 21:24:13 +01:00 committed by GitHub
parent 5730d87cad
commit 4ac7a71dd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,35 +1,73 @@
#!/bin/bash #!/bin/bash
source .fonctions #=================================================
set -eu # 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
#=================================================
# Retrieve arguments
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
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Source app helpers
source /usr/share/yunohost/helpers
script_dir=$PWD script_dir=$PWD
# Vérifie que les variables ne sont pas vides. #=================================================
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 # Vérifie et corrige la syntaxe du path. ### 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 # Vérifie la disponibilité du path et du domaine. ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app"
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Copy files to the right place
final_path=/var/www/$app final_path=/var/www/$app
sudo git clone https://github.com/pips-/shuri.git $final_path 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)
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
ynh_webpath_register $app $domain $path_url
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app path $path_url
ynh_app_setting_set $app is_public $is_public
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
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"
#=================================================
# Install Composer + install Dependencies
#=================================================
pushd $final_path pushd $final_path
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
@ -39,23 +77,40 @@ sudo ./composer.phar install
sudo mkdir db sudo mkdir db
popd popd
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# Files owned by root, www-data can just read # Files owned by root, www-data can just read
sudo chown www-data:www-data $final_path -R #=================================================
sudo chmod 755 $final_path -R
# Modify Nginx configuration file and copy it to Nginx conf directory chown $app:$app $final_path -R
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf chmod 755 $final_path -R
sed -i "s@YNH_WWW_ALIAS@$final_path/@g" ../conf/nginx.conf
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
ynh_app_setting_set "$app" is_public "$is_public" #=================================================
if [ "$is_public" = "Yes" ]; # NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# SETUP SSOWAT
#=================================================
# Make app public if necessary
if [ $is_public -eq 1 ]
then then
ynh_app_setting_set "$app" unprotected_uris "/" # unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set $app unprotected_uris "/"
fi fi
sudo service nginx reload #=================================================
sudo yunohost app ssowatconf # RELOAD NGINX
#=================================================
systemctl reload nginx