mirror of
https://github.com/YunoHost-Apps/haste_ynh.git
synced 2024-09-03 20:36:28 +02:00
[enh] REFACTORING
This commit is contained in:
parent
702cd0105f
commit
b5391bbfec
1 changed files with 149 additions and 19 deletions
168
scripts/install
168
scripts/install
|
@ -1,33 +1,163 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit on command errors and treat unset variables as an error
|
#=================================================
|
||||||
set -eu
|
# GENERIC STARTING
|
||||||
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Load common variables and functions
|
source _common.sh
|
||||||
source ./_common.sh
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# MANAGE FAILURE OF THE SCRIPT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_abort_if_errors # Active trap pour arrêter le script si une erreur est détectée.
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# 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
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
#=================================================
|
||||||
|
|
||||||
if ! [ "$path" = "/" ]
|
if sudo yunohost domain list | grep -q $domain # Vérifie la liste des domaines
|
||||||
then
|
then # Si le domaine existe dans Yunohost
|
||||||
ynh_die "Path must be /"
|
if sudo yunohost app map | grep -q $domain # Vérifie la liste des apps par domaine
|
||||||
|
then # Si une app est installée sur ce domaine.
|
||||||
|
WARNING echo "An app is already installed on the domain $domain. cryptpad needs a whole domain or subdomain to himself."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save app settings
|
path_url=$(ynh_normalize_url_path $path_url) # Check and normalize path
|
||||||
ynh_app_setting_set "$app" is_public "$is_public"
|
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
|
||||||
|
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
|
||||||
|
|
||||||
# Install the app
|
#=================================================
|
||||||
install_haste $domain $path $is_public
|
# STORE SETTINGS FROM MANIFEST
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Start Haste
|
ynh_app_setting_set $app domain "$domain"
|
||||||
sudo systemctl start "$app".service
|
ynh_app_setting_set $app is_public "$is_public"
|
||||||
|
ynh_app_setting_set $app path_url "$path_url"
|
||||||
|
|
||||||
# Add Haste to YunoHost's monitored services
|
#=================================================
|
||||||
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
# STANDARD MODIFICATIONS
|
||||||
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
port=$(ynh_find_port 3000) # Cherche un port libre.
|
||||||
|
ynh_app_setting_set $app port $port
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL NODEJS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_install_nodejs $NODEJS_VERSION
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# CREATE DEDICATED USER
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_system_user_create $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SPECIFIC SETUP
|
||||||
|
#=================================================
|
||||||
|
# HANDLE LOG FILES AND LOGROTATE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Créer le dossier de log
|
||||||
|
sudo mkdir -p /var/log/$app
|
||||||
|
sudo touch /var/log/$app/$app.log
|
||||||
|
sudo chown $app -R /var/log/$app
|
||||||
|
|
||||||
|
# Setup logrotate
|
||||||
|
ynh_use_logrotate
|
||||||
|
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
final_path=/var/www/$app
|
||||||
|
ynh_app_setting_set $app final_path $final_path
|
||||||
|
ynh_setup_source $final_path
|
||||||
|
|
||||||
|
# Set files ownership during installation
|
||||||
|
sudo chown $app: $final_path -R
|
||||||
|
sudo chmod 755 $final_path -R
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_nginx_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# ADD SYSTEMD SERVICE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
||||||
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
||||||
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
||||||
|
ynh_systemd_config
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# INSTALL HASTEBIN
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
script_dir="$PWD"
|
||||||
|
pushd "$final_path"
|
||||||
|
sudo chown -R $app: $final_path
|
||||||
|
sudo_path npm install
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Configure haste with config.js file
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
sudo cp ../conf/config.js "$DESTDIR"/config.js
|
||||||
|
sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# Add HASTE AS A BINARY FILE
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_replace_string "YNH_HASTE_URL" "${DOMAIN}${path%/}" "../conf/haste.sh"
|
||||||
|
sudo cp ../conf/haste.sh /usr/bin/"$app"
|
||||||
|
sudo chmod +x /usr/bin/"$app"
|
||||||
|
|
||||||
|
=================================================
|
||||||
|
# ENABLE SERVICE IN ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Ajoute le service au monitoring de Yunohost.
|
||||||
|
sudo yunohost service add $app --log "/var/log/$app/$app.log"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START HASTEBIN IN BACKGROUND
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
sudo systemctl start $app
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# SETUP SSOWAT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
if [ $is_public -eq 1 ];
|
||||||
|
then
|
||||||
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
|
Loading…
Reference in a new issue