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

Complete refactoring

This commit is contained in:
Maniack Crudelis 2017-11-29 15:42:21 +01:00
parent 226e2a4cf7
commit 6e7ac9f7f5
12 changed files with 267 additions and 219 deletions

View file

@ -1,8 +1,3 @@
# See here for more informations
# https://github.com/YunoHost/package_check#syntax-check_process-file
# Move this file from check_process.default to check_process when you have filled it.
;; Test complet
; Manifest
domain="domain.tld" (DOMAIN)

View file

@ -34,7 +34,7 @@
"storage": {
"type": "file",
"file": "YNH_DATA_PATH"
"file": "__YNH_DATA_PATH__"
},
"documents": {

View file

@ -3,7 +3,7 @@
set -e
set -u
PASTE_URL="YNH_HASTE_URL"
PASTE_URL="__YNH_HASTE_URL__"
_die() {
printf "Error: %s\n" "$*"

View file

@ -1,8 +1,13 @@
location / {
location __PATH__ {
if ($scheme = http) {
rewrite ^ https://$server_name$request_uri? permanent;
}
proxy_pass http://localhost:__PORT__;
proxy_set_header Host $host;
proxy_buffering off;
fastcgi_param REMOTE_USER $remote_user;
client_max_body_size 50M;
# Include SSOWAT user panel.

View file

@ -10,7 +10,7 @@ Group=__APP__
ExecStartPre=__NODEJS__
WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__"
ExecStart=/opt/node_n/n/versions/node/4/bin/npm start
ExecStart=__NODEPATH__/npm start
Restart=always
[Install]

View file

@ -6,12 +6,12 @@
"en": "Haste is an open-source pastebin software written in node.js",
"fr": "Haste is an open-source pastebin software written in node.js"
},
"version": "f19c5d10498e214b8323fff9e5eab77cbb7eebff",
"url": "https://github.com/seejohnrun/haste-server",
"license": "MIT",
"maintainer": {
"name": "mbugeia",
"email": "maxime.bugeia@gmail.com",
"url": "https://github.com/YunoHost-Apps/haste_ynh"
"email": "maxime.bugeia@gmail.com"
},
"requirements": {
"yunohost": ">= 2.7.2"

View file

@ -1,4 +1,3 @@
#!/bin/bash
# INFOS
# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
# C'est ainsi qu'il change de version
@ -17,6 +16,19 @@ node_version_path="/opt/node_n/n/versions/node"
# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
export N_PREFIX="$n_install_dir"
ynh_install_n () {
echo "Installation of N - Node.js version management" >&2
# Build an app.src for n
mkdir -p "../conf"
echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz
SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src"
# Download and extract n
ynh_setup_source "$n_install_dir/git" n
# Install n
(cd "$n_install_dir/git"
PREFIX=$N_PREFIX make install 2>&1)
}
ynh_use_nodejs () {
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
@ -52,9 +64,10 @@ ynh_install_nodejs () {
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
# If n is not previously setup, install it
n --version > /dev/null 2>&1 || \
( echo "Installation of N - Node.js version management" >&2; \
curl -sL $n_install_script | N_PREFIX=$N_PREFIX bash -s -- -y - 2>&1 )
if ! test n --version > /dev/null 2>&1
then
ynh_install_n
fi
# Modify the default N_PREFIX in n script
ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"

View file

@ -29,7 +29,6 @@ app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get $app final_path)
domain=$(ynh_app_setting_get $app domain)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# STANDARD BACKUP STEPS
@ -53,9 +52,20 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP DATADIR DIRECTORY
#=================================================
ynh_backup "/home/yunohost.app/$app"
#=================================================
# BACKUP BINARY
#=================================================
ynh_backup "/usr/bin/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"

View file

@ -13,7 +13,8 @@ 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.
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
@ -35,6 +36,10 @@ 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)
if [ "$path_url" != "/" ]; then
ynh_die "Only / is allowed"
fi
# Check web path availability
ynh_webpath_available $domain $path_url
# Register (book) web path
@ -56,14 +61,24 @@ ynh_app_setting_set $app path_url "$path_url"
# Find a free port
port=$(ynh_find_port 7777)
# Open this port
yunohost firewall allow --no-upnp TCP $port 2>&1
ynh_app_setting_set $app port $port
echo "port=$port" >&2
#=================================================
# INSTALL NODEJS
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_install_nodejs 4
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
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
@ -73,43 +88,19 @@ ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
# INSTALL NODEJS
#=================================================
# Créer le dossier de log
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
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
chown $app: $final_path -R
chmod 755 $final_path -R
#=================================================
# Modify Nginx configuration file and copy it to Nginx conf directory
#=================================================
ynh_add_nginx_config
ynh_install_nodejs 4
#=================================================
# 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_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
@ -117,30 +108,65 @@ ynh_add_systemd_config
#=================================================
ynh_use_nodejs
script_dir="$PWD"
pushd "$final_path"
chown -R $app: $final_path
npm install
popd
DATA_PATH="/home/yunohost.app/"$app
mkdir -p $DATA_PATH
chown -R "$app":"$app" $final_path $DATA_PATH
(cd "$final_path"
chown -R $app: "$final_path"
npm install)
#=================================================
# Configure haste with config.js file
# CREATE DIRECTORY FOR DATA
#=================================================
ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js"
data_path="/home/yunohost.app/$app"
mkdir -p "$data_path"
#=================================================
# CONFIGURE HASTE
#=================================================
cp ../conf/config.js "$final_path/config.js"
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.js"
#=================================================
# ADD HASTE AS A BINARY FILE
#=================================================
ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url}" "../conf/haste.sh"
sudo cp ../conf/haste.sh /usr/bin/$app
sudo chmod +x /usr/bin/"$app"
echo "Please use 'cmd | $app' to paste the output of the command to your Haste server." >&2
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R root: $final_path
chown -R $app "$final_path/static"
chown -R $app "$data_path"
#=================================================
# HANDLE LOG FILES AND SETUP LOGROTATE
#=================================================
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown $app -R /var/log/$app
ynh_use_logrotate
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
# Ajoute le service au monitoring de Yunohost.
yunohost service add $app --log "/var/log/$app/$app.log"
#=================================================
# START HASTEBIN IN BACKGROUND
# START HASTEBIN
#=================================================
systemctl start $app
@ -151,17 +177,9 @@ systemctl start $app
if [ $is_public -eq 1 ];
then
ynh_app_setting_set "$app" unprotected_uris "/"
ynh_app_setting_set $app skipped_uris "/"
fi
#=================================================
# Add HASTE AS A BINARY FILE
#=================================================
ynh_replace_string "YNH_HASTE_URL" "${domain}${path_url%/}" "../conf/haste.sh"
sudo cp ../conf/haste.sh /usr/bin/"$app"
sudo chmod +x /usr/bin/"$app"
#=================================================
# RELOAD NGINX
#=================================================

View file

@ -16,8 +16,6 @@ source /usr/share/yunohost/helpers
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
port=$(ynh_app_setting_get $app port)
db_name=$(ynh_app_setting_get $app db_name)
final_path=$(ynh_app_setting_get $app final_path)
#=================================================
@ -39,42 +37,43 @@ then
yunohost service remove $app
fi
#=================================================
# REMOVE APP MAIN DIR
#=================================================
# Remove the app directory securely
ynh_secure_remove "$final_path"
#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
# Remove the dedicated nginx config
ynh_remove_nginx_config
#=================================================
# REMOVE LOGROTATE CONFIGURATION
#=================================================
# Remove the app-specific logrotate config
ynh_remove_logrotate
#=================================================
# CLOSE A PORT
#=================================================
if yunohost firewall list | grep -q "\- $port$"
then
echo "Close port $port"
yunohost firewall disallow TCP $port 2>&1
fi
#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE HASTE BINARY
#=================================================
ynh_secure_remove "/usr/bin/$app"
#=================================================
# REMOVE DATADIR DIRECTORY
#=================================================
ynh_secure_remove "$data_path"
#=================================================
# REMOVE NODEJS
#=================================================
ynh_remove_nodejs
#=================================================
# GENERIC FINALIZATION

View file

@ -31,7 +31,6 @@ app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
@ -56,7 +55,6 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file "$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
@ -65,36 +63,28 @@ ynh_restore_file "$final_path"
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
# SPECIFIC RESTORE
#=================================================
# HANDLE LOG FILES AND RESTORE LOGROTATE
#=================================================
# Restore permissions on app files
chown -R root: $final_path
mkdir -p /var/log/$app
touch /var/log/$app/$app.log
chown $app -R /var/log/$app
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# SPECIFIC RESTORATION
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 4
#=================================================
# INSTALL HASTEBIN
#=================================================
ynh_use_nodejs
script_dir="$PWD"
pushd "$final_path"
chown -R $app: $final_path
npm install
DATA_PATH="/home/yunohost.app/"$app
mkdir -p $DATA_PATH
chown -R "$app":"$app" $final_path $DATA_PATH
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
yunohost service add $app --log "/var/log/$app/$app.log"
#=================================================
# RESTORE SYSTEMD
@ -104,17 +94,25 @@ ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# START HASTEBIN IN BACKGROUND
# RESTORE DATADIR DIRECTORY
#=================================================
ynh_restore_file "/home/yunohost.app/$app"
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R root: $final_path
chown -R $app "$final_path/static"
chown -R $app "/home/yunohost.app/$app"
#=================================================
# START HASTEBIN
#=================================================
systemctl start $app
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================

View file

@ -34,12 +34,6 @@ elif [ "$is_public" = "No" ]; then
is_public=0
fi
# If db_name doesn't exist, create it
if [ -z $db_name ]; then
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
# If final_path doesn't exist, create it
if [ -z $final_path ]; then
final_path=/var/www/$app
@ -67,92 +61,108 @@ ynh_abort_if_errors
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# INSTALL NODEJS
# STOP HASTE
#=================================================
ynh_install_nodejs 4
systemctl stop $app
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
# Set files ownership during installation
chown $app: $final_path -R
chmod 755 $final_path -R
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# ADD SYSTEMD SERVICE
# SPECIFIC UPGRADE
#=================================================
# UPGRADE NODEJS
#=================================================
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_add_systemd_config
ynh_install_nodejs 4
#=================================================
# INSTALL HASTEBIN
# UPGRADE NPM MODULES
#=================================================
ynh_use_nodejs
script_dir="$PWD"
pushd "$final_path"
chown -R $app: $final_path
npm install
DATA_PATH="/home/yunohost.app/"$app
mkdir -p $DATA_PATH
chown -R "$app":"$app" $final_path $DATA_PATH
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/config.js"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.js"
npm cache clean
npm update
#=================================================
# SETUP LOGROTATE
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
# UPGRADE HASTE CONFIGURATION
#=================================================
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/config.js"
cp ../conf/config.js "$final_path/config.js"
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
data_path="/home/yunohost.app/$app"
ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.js"
#=================================================
# UPGRADE HASTE BINARY
#=================================================
ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url}" "../conf/haste.sh"
sudo cp ../conf/haste.sh /usr/bin/$app
sudo chmod +x /usr/bin/"$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
chown -R root: $final_path
chown -R $app "$final_path/static"
chown -R $app "$data_path"
#=================================================
# START HASTEBIN
#=================================================
systemctl start $app
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 0 ]
then # Remove the public access
ynh_app_setting_delete $app skipped_uris
fi
# Make app public if necessary
if [ $is_public -eq 1 ]
if [ $is_public -eq 1 ];
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
ynh_app_setting_set $app skipped_uris "/"
fi
#=================================================