mirror of
https://github.com/YunoHost-Apps/haste_ynh.git
synced 2024-09-03 20:36:28 +02:00
Merge pull request #6 from YunoHost-Apps/refactoring
Complete refactoring
This commit is contained in:
commit
e7439b9cc4
12 changed files with 267 additions and 219 deletions
|
@ -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
|
;; Test complet
|
||||||
; Manifest
|
; Manifest
|
||||||
domain="domain.tld" (DOMAIN)
|
domain="domain.tld" (DOMAIN)
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
"storage": {
|
"storage": {
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"file": "YNH_DATA_PATH"
|
"file": "__YNH_DATA_PATH__"
|
||||||
},
|
},
|
||||||
|
|
||||||
"documents": {
|
"documents": {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
PASTE_URL="YNH_HASTE_URL"
|
PASTE_URL="__YNH_HASTE_URL__"
|
||||||
|
|
||||||
_die() {
|
_die() {
|
||||||
printf "Error: %s\n" "$*"
|
printf "Error: %s\n" "$*"
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
location / {
|
location __PATH__ {
|
||||||
|
|
||||||
|
if ($scheme = http) {
|
||||||
|
rewrite ^ https://$server_name$request_uri? permanent;
|
||||||
|
}
|
||||||
|
|
||||||
proxy_pass http://localhost:__PORT__;
|
proxy_pass http://localhost:__PORT__;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
fastcgi_param REMOTE_USER $remote_user;
|
|
||||||
client_max_body_size 50M;
|
client_max_body_size 50M;
|
||||||
|
|
||||||
# Include SSOWAT user panel.
|
# Include SSOWAT user panel.
|
||||||
|
|
|
@ -10,7 +10,7 @@ Group=__APP__
|
||||||
ExecStartPre=__NODEJS__
|
ExecStartPre=__NODEJS__
|
||||||
WorkingDirectory=__FINALPATH__
|
WorkingDirectory=__FINALPATH__
|
||||||
Environment="PATH=__ENV_PATH__"
|
Environment="PATH=__ENV_PATH__"
|
||||||
ExecStart=/opt/node_n/n/versions/node/4/bin/npm start
|
ExecStart=__NODEPATH__/npm start
|
||||||
Restart=always
|
Restart=always
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
"en": "Haste is an open-source pastebin software written in node.js",
|
"en": "Haste is an open-source pastebin software written in node.js",
|
||||||
"fr": "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",
|
"url": "https://github.com/seejohnrun/haste-server",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "mbugeia",
|
"name": "mbugeia",
|
||||||
"email": "maxime.bugeia@gmail.com",
|
"email": "maxime.bugeia@gmail.com"
|
||||||
"url": "https://github.com/YunoHost-Apps/haste_ynh"
|
|
||||||
},
|
},
|
||||||
"requirements": {
|
"requirements": {
|
||||||
"yunohost": ">= 2.7.2"
|
"yunohost": ">= 2.7.2"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#!/bin/bash
|
|
||||||
# INFOS
|
# INFOS
|
||||||
# n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
|
# 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
|
# 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.
|
# N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
|
||||||
export N_PREFIX="$n_install_dir"
|
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 () {
|
ynh_use_nodejs () {
|
||||||
nodejs_version=$(ynh_app_setting_get $app nodejs_version)
|
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
|
test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
|
||||||
|
|
||||||
# If n is not previously setup, install it
|
# If n is not previously setup, install it
|
||||||
n --version > /dev/null 2>&1 || \
|
if ! test n --version > /dev/null 2>&1
|
||||||
( echo "Installation of N - Node.js version management" >&2; \
|
then
|
||||||
curl -sL $n_install_script | N_PREFIX=$N_PREFIX bash -s -- -y - 2>&1 )
|
ynh_install_n
|
||||||
|
fi
|
||||||
|
|
||||||
# Modify the default N_PREFIX in n script
|
# 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"
|
ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"
|
||||||
|
|
|
@ -29,7 +29,6 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
final_path=$(ynh_app_setting_get $app final_path)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
db_name=$(ynh_app_setting_get $app db_name)
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD BACKUP STEPS
|
# STANDARD BACKUP STEPS
|
||||||
|
@ -53,9 +52,20 @@ ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
ynh_backup "/etc/logrotate.d/$app"
|
ynh_backup "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP DATADIR DIRECTORY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/home/yunohost.app/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# BACKUP BINARY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/usr/bin/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP SYSTEMD
|
# BACKUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup "/etc/systemd/system/$app.service"
|
ynh_backup "/etc/systemd/system/$app.service"
|
||||||
|
|
||||||
|
|
126
scripts/install
126
scripts/install
|
@ -13,7 +13,8 @@ source /usr/share/yunohost/helpers
|
||||||
# MANAGE FAILURE OF THE SCRIPT
|
# 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
|
# 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
|
# Normalize the url path syntax
|
||||||
path_url=$(ynh_normalize_url_path $path_url)
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
|
if [ "$path_url" != "/" ]; then
|
||||||
|
ynh_die "Only / is allowed"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check web path availability
|
# Check web path availability
|
||||||
ynh_webpath_available $domain $path_url
|
ynh_webpath_available $domain $path_url
|
||||||
# Register (book) web path
|
# Register (book) web path
|
||||||
|
@ -56,14 +61,24 @@ ynh_app_setting_set $app path_url "$path_url"
|
||||||
|
|
||||||
# Find a free port
|
# Find a free port
|
||||||
port=$(ynh_find_port 7777)
|
port=$(ynh_find_port 7777)
|
||||||
# Open this port
|
|
||||||
yunohost firewall allow --no-upnp TCP $port 2>&1
|
|
||||||
ynh_app_setting_set $app port $port
|
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
|
# CREATE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -73,43 +88,19 @@ ynh_system_user_create $app
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# HANDLE LOG FILES AND LOGROTATE
|
# INSTALL NODEJS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Créer le dossier de log
|
ynh_install_nodejs 4
|
||||||
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
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD SYSTEMD SERVICE
|
# 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 "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
||||||
ynh_replace_string "__ENV_PATH__" "$PATH" "../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
|
ynh_add_systemd_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -117,30 +108,65 @@ ynh_add_systemd_config
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_use_nodejs
|
ynh_use_nodejs
|
||||||
script_dir="$PWD"
|
|
||||||
pushd "$final_path"
|
(cd "$final_path"
|
||||||
chown -R $app: $final_path
|
chown -R $app: "$final_path"
|
||||||
npm install
|
npm install)
|
||||||
popd
|
|
||||||
DATA_PATH="/home/yunohost.app/"$app
|
|
||||||
mkdir -p $DATA_PATH
|
|
||||||
chown -R "$app":"$app" $final_path $DATA_PATH
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# 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
|
# ENABLE SERVICE IN ADMIN PANEL
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Ajoute le service au monitoring de Yunohost.
|
|
||||||
yunohost service add $app --log "/var/log/$app/$app.log"
|
yunohost service add $app --log "/var/log/$app/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START HASTEBIN IN BACKGROUND
|
# START HASTEBIN
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
systemctl start $app
|
systemctl start $app
|
||||||
|
@ -151,17 +177,9 @@ systemctl start $app
|
||||||
|
|
||||||
if [ $is_public -eq 1 ];
|
if [ $is_public -eq 1 ];
|
||||||
then
|
then
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
fi
|
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
|
# RELOAD NGINX
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -16,8 +16,6 @@ source /usr/share/yunohost/helpers
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
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)
|
final_path=$(ynh_app_setting_get $app final_path)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -39,42 +37,43 @@ then
|
||||||
yunohost service remove $app
|
yunohost service remove $app
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove the app directory securely
|
|
||||||
ynh_secure_remove "$final_path"
|
ynh_secure_remove "$final_path"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE NGINX CONFIGURATION
|
# REMOVE NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove the dedicated nginx config
|
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove the app-specific logrotate config
|
|
||||||
ynh_remove_logrotate
|
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
|
# SPECIFIC REMOVE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
# REMOVE HASTE BINARY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_secure_remove "/usr/bin/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE DATADIR DIRECTORY
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_secure_remove "/home/yunohost.app/$app"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE NODEJS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_remove_nodejs
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
|
|
|
@ -31,7 +31,6 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
domain=$(ynh_app_setting_get $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
path_url=$(ynh_app_setting_get $app path)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
final_path=$(ynh_app_setting_get $app final_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
|
# 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"
|
ynh_restore_file "$final_path"
|
||||||
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RECREATE THE DEDICATED USER
|
# RECREATE THE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -65,36 +63,28 @@ ynh_restore_file "$final_path"
|
||||||
ynh_system_user_create $app
|
ynh_system_user_create $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE USER RIGHTS
|
# SPECIFIC RESTORE
|
||||||
|
#=================================================
|
||||||
|
# HANDLE LOG FILES AND RESTORE LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Restore permissions on app files
|
mkdir -p /var/log/$app
|
||||||
chown -R root: $final_path
|
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
|
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
|
# RESTORE SYSTEMD
|
||||||
|
@ -104,17 +94,25 @@ ynh_restore_file "/etc/systemd/system/$app.service"
|
||||||
systemctl enable $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
|
systemctl start $app
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# RESTORE THE LOGROTATE CONFIGURATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
ynh_restore_file "/etc/logrotate.d/$app"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC FINALIZATION
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -34,12 +34,6 @@ elif [ "$is_public" = "No" ]; then
|
||||||
is_public=0
|
is_public=0
|
||||||
fi
|
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 final_path doesn't exist, create it
|
||||||
if [ -z $final_path ]; then
|
if [ -z $final_path ]; then
|
||||||
final_path=/var/www/$app
|
final_path=/var/www/$app
|
||||||
|
@ -67,92 +61,108 @@ ynh_abort_if_errors
|
||||||
path_url=$(ynh_normalize_url_path $path_url)
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL NODEJS
|
# STOP HASTE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_install_nodejs 4
|
systemctl stop $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# STANDARD UPGRADE STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
|
||||||
ynh_setup_source "$final_path"
|
ynh_setup_source "$final_path"
|
||||||
# Set files ownership during installation
|
|
||||||
chown $app: $final_path -R
|
|
||||||
chmod 755 $final_path -R
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Create a dedicated nginx config
|
|
||||||
ynh_add_nginx_config
|
ynh_add_nginx_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# CREATE DEDICATED USER
|
# CREATE DEDICATED USER
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Create a system user
|
|
||||||
ynh_system_user_create $app
|
ynh_system_user_create $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD SYSTEMD SERVICE
|
# SPECIFIC UPGRADE
|
||||||
|
#=================================================
|
||||||
|
# UPGRADE NODEJS
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
|
ynh_install_nodejs 4
|
||||||
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
|
||||||
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
|
||||||
ynh_add_systemd_config
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL HASTEBIN
|
# UPGRADE NPM MODULES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_use_nodejs
|
npm cache clean
|
||||||
script_dir="$PWD"
|
npm update
|
||||||
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"
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Use logrotate to manage app-specific logfile(s)
|
|
||||||
ynh_use_logrotate
|
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
|
# GENERIC FINALIZATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# SECURE FILES AND DIRECTORIES
|
# SECURE FILES AND DIRECTORIES
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Set right permissions for curl installation
|
|
||||||
chown -R root: $final_path
|
chown -R root: $final_path
|
||||||
|
chown -R $app "$final_path/static"
|
||||||
|
chown -R $app "$data_path"
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
# START HASTEBIN
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl start $app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ $is_public -eq 0 ]
|
if [ $is_public -eq 1 ];
|
||||||
then # Remove the public access
|
|
||||||
ynh_app_setting_delete $app skipped_uris
|
|
||||||
fi
|
|
||||||
# Make app public if necessary
|
|
||||||
if [ $is_public -eq 1 ]
|
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway
|
ynh_app_setting_set $app skipped_uris "/"
|
||||||
ynh_app_setting_set $app unprotected_uris "/"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Reference in a new issue