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

Merge pull request #3 from Rafi594/patch-1

Refactoring of the app
This commit is contained in:
frju365 2017-10-15 01:23:14 +02:00 committed by GitHub
commit 00c8d05bcd
12 changed files with 747 additions and 196 deletions

43
check_process Normal file
View file

@ -0,0 +1,43 @@
# 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)
path="/" (PATH)
admin="john" (USER)
language="fr"
is_public=1 (PUBLIC|public=1|private=0)
password="pass"
port="666" (PORT)
; Checks
pkg_linter=1
setup_sub_dir=0
setup_root=1
setup_nourl=0
setup_private=1
setup_public=1
upgrade=1
backup_restore=1
multi_instance=1
incorrect_path=1
port_already_use=0
change_url=0
;;; Levels
Level 1=auto
Level 2=auto
Level 3=auto
# Level 4:
Level 4=0
# Level 5:
Level 5=auto
Level 6=auto
Level 7=auto
Level 8=0
Level 9=0
Level 10=0
;;; Options
Email=
Notification=none

6
conf/app.src Normal file
View file

@ -0,0 +1,6 @@
SOURCE_URL=https://github.com/seejohnrun/haste-server/archive/f19c5d10498e214b8323fff9e5eab77cbb7eebff.tar.gz
SOURCE_SUM=6e67fd09bc7782d23d612c209a2de39212682239018a1bd2618c120f9cc36a47
SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz
SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=

View file

@ -1,7 +1,7 @@
{ {
"host": "127.0.0.1", "host": "127.0.0.1",
"port": 7777, "port": __PORT__,
"keyLength": 10, "keyLength": 10,
@ -13,11 +13,11 @@
"logging": [ "logging": [
{ {
"level": "info", "level": "verbose",
"type": "Console", "type": "Console",
"colorize": true "colorize": true
} }
], ],
"keyGenerator": { "keyGenerator": {
"type": "phonetic" "type": "phonetic"
@ -35,7 +35,7 @@
"storage": { "storage": {
"type": "file", "type": "file",
"file": "YNH_DATA_PATH" "file": "YNH_DATA_PATH"
}, },
"documents": { "documents": {
"about": "./about.md" "about": "./about.md"

View file

@ -1,5 +1,5 @@
location / { location / {
proxy_pass http://localhost:7777/; 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; fastcgi_param REMOTE_USER $remote_user;

View file

@ -5,12 +5,13 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
User=haste User=__APP__
Group=haste Group=__APP__
WorkingDirectory=/opt/haste ExecStartPre=__NODEJS__
ExecStart=/usr/bin/npm start WorkingDirectory=__FINALPATH__
Environment="PATH=__ENV_PATH__"
ExecStart=/opt/node_n/n/versions/node/4/bin/npm start
Restart=always Restart=always
Environment=USER=haste HOME=/opt/haste
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -7,14 +7,14 @@
"fr": "Haste is an open-source pastebin software written in node.js" "fr": "Haste is an open-source pastebin software written in node.js"
}, },
"url": "https://github.com/seejohnrun/haste-server", "url": "https://github.com/seejohnrun/haste-server",
"license": "free", "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" "url": "https://github.com/YunoHost-Apps/haste_ynh"
}, },
"requirements": { "requirements": {
"yunohost": ">> 2.4.0" "yunohost": ">= 2.7.2"
}, },
"multi_instance": false, "multi_instance": false,
"services": [ "services": [

View file

@ -1,107 +1,160 @@
# #!/bin/bash
# Common variables # 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
# ynh_install_nodejs installe la version de nodejs demandée en argument, avec n
# ynh_use_nodejs active une version de nodejs dans le script courant
# 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app
# - nodejs_path: Le chemin absolu de cette version de node
# Utilisé pour des appels directs à node.
# - nodejs_version: Simplement le numéro de version de nodejs pour cette application
# - nodejs_use_version: Un alias pour charger une version de node dans le shell courant.
# Utilisé pour démarrer un service ou un script qui utilise node ou npm
# Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire.
APPNAME="haste" n_install_dir="/opt/node_n"
app=${YNH_APP_INSTANCE_NAME:-haste} 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"
# Haste version ynh_use_nodejs () {
VERSION="master" nodejs_version=$(ynh_app_setting_get $app nodejs_version)
# set globals variables load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir""
DESTDIR="/opt/"${app}
DATA_PATH="/home/yunohost.app/"$app
# Remote URL to fetch Haste tarball nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
HASTE_URL="https://github.com/seejohnrun/haste-server/archive/"${VERSION}".zip"
# Source YunoHost helpers # "Load" a version of node
source /usr/share/yunohost/helpers eval $load_n_path; $nodejs_use_version
# # Get the absolute path of this version of node
# Common helpers nodejs_path="$(n bin $nodejs_version)"
#
check_or_install_npm() { # Make an alias for node use
if ! dpkg -s npm | grep "installed" > /dev/null 2>&1 \ ynh_node_exec="eval $load_n_path; n use $nodejs_version"
|| ! dpkg -s nodejs-legacy | grep "installed" > /dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y npm nodejs-legacy
fi
} }
pre_inst_haste() { ynh_install_nodejs () {
# retrieve, extract, copy haste, add user if necessary # Use n, https://github.com/tj/n to manage the nodejs versions
local TMPDIR=$(mktemp -d) nodejs_version="$1"
local HASTE_SOURCE=$1 local n_install_script="https://git.io/n-install"
haste_tarball="/tmp/haste.zip" # Create $n_install_dir
rm -f "$haste_tarball" mkdir -p "$n_install_dir"
if [ "$HASTE_SOURCE" = "backup" ]
then
# Restore the app and data files
sudo cp -a ./www "$DESTDIR"
sudo cp -a ./data/. "$DATA_PATH"
# Restore directories and permissions
sudo chown -R "$app":"$app" "$DESTDIR" "$DATA_PATH"
else
wget -q -O "$haste_tarball" "$HASTE_URL" \
|| ynh_die "Unable to download haste"
unzip -q "$haste_tarball" -d "$TMPDIR" \
|| ynh_die "Unable to extract haste"
sudo rsync -a "$TMPDIR"/haste-server-master/* "$DESTDIR"
fi
rm -rf "$haste_tarball" "$TMPDIR"
# Add user if not exist # Load n path in PATH
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet CLEAR_PATH="$n_install_dir/bin:$PATH"
id -u "$app" &>/dev/null || sudo adduser "$app" \ # Remove /usr/local/bin in PATH in case of node has already setup.
--ingroup "$app" --system --quiet --shell /bin/bash PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Configure init script # Move an existing node binary, to avoid to block n.
sudo cp ../conf/"$app".service /etc/systemd/system/ test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
sudo systemctl daemon-reload test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
sudo systemctl enable "$app".service
}
# Download, extract and install Haste to the given directory # If n is not previously setup, install it
# usage: install_haste DESTDIR n --version > /dev/null 2>&1 || \
install_haste() { ( echo "Installation of N - Node.js version management" >&2; \
local DOMAIN=$1 curl -sL $n_install_script | N_PREFIX=$N_PREFIX bash -s -- -y - 2>&1 )
local YNH_PATH=$2
local IS_PUBLIC=$3
check_or_install_npm # Modify the default N_PREFIX in n script
pre_inst_haste none ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"
# install haste # Restore /usr/local/bin in PATH
current_dir=$(pwd) PATH=$CLEAR_PATH
cd "$DESTDIR"
sudo npm install
cd $current_dir
sudo mkdir -p $DATA_PATH # And replace the old node binary.
sudo chown -R "$app":"$app" $DESTDIR $DATA_PATH test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node
test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm
# Configure haste with config.js file # Install the requested version of nodejs
sudo cp ../conf/config.js "$DESTDIR"/config.js n $nodejs_version
sudo sed -i "s@YNH_DATA_PATH@$DATA_PATH@g" "$DESTDIR"/config.js
# Modify Nginx configuration file and copy it to Nginx conf directory # Find the last "real" version for this major version of node.
sed -i "s@PATHTOCHANGE@${YNH_PATH%/}@g" ../conf/nginx.conf real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1)
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/"$app".conf real_nodejs_version=$(basename $real_nodejs_version)
# If app is public, add url to SSOWat conf as skipped_uris # Create a symbolic link for this major version. If the file doesn't already exist
if [[ $IS_PUBLIC -eq 1 ]]; then if [ ! -e "$node_version_path/$nodejs_version" ]
# unprotected_uris allows SSO credentials to be passed anyway. then
ynh_app_setting_set "$app" unprotected_uris "/" ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version
fi fi
# Reload services # Store the ID of this app and the version of node requested for it
sudo systemctl reload nginx.service echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version"
# install haste cli client # Store nodejs_version into the config of this app
sed -i "s@YNH_HASTE_URL@${DOMAIN}${path%/}@g" ../conf/haste.sh ynh_app_setting_set $app nodejs_version $nodejs_version
sudo cp ../conf/haste.sh /usr/bin/"$app"
sudo chmod +x /usr/bin/"$app" # Build the update script and set the cronjob
ynh_cron_upgrade_node
ynh_use_nodejs
}
ynh_remove_nodejs () {
ynh_use_nodejs
# Remove the line for this app
sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version"
# If none another app uses this version of nodejs, remove it.
if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
then
n rm $nodejs_version
fi
# If none another app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]
then
ynh_secure_remove "$n_install_dir"
ynh_secure_remove "/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
fi
}
ynh_cron_upgrade_node () {
# Build the update script
cat > "$n_install_dir/node_update.sh" << EOF
#!/bin/bash
version_path="$node_version_path"
n_install_dir="$n_install_dir"
# Log the date
date
# List all real installed version of node
all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")"
# Keep only the major version number of each line
all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//')
# Remove double entries
all_real_version=\$(echo "\$all_real_version" | sort --unique)
# Read each major version
while read version
do
echo "Update of the version \$version"
sudo \$n_install_dir/bin/n \$version
# Find the last "real" version for this major version of node.
real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1)
real_nodejs_version=\$(basename \$real_nodejs_version)
# Update the symbolic link for this version
sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version
done <<< "\$(echo "\$all_real_version")"
EOF
chmod +x "$n_install_dir/node_update.sh"
# Build the cronjob
cat > "/etc/cron.daily/node_update" << EOF
#!/bin/bash
$n_install_dir/node_update.sh >> $n_install_dir/node_update.log
EOF
chmod +x "/etc/cron.daily/node_update"
} }

View file

@ -1,22 +1,61 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables and functions if [ ! -e _common.sh ]; then
source ./_common.sh # Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
domain=$(ynh_app_setting_get "$app" domain) #=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Copy the app source and data files # Exit if an error occurs during the execution of the script
ynh_backup "$DESTDIR" "www" ynh_abort_if_errors
ynh_backup "$DATA_PATH" "data"
# Copy the conf files #=================================================
mkdir ./conf # LOAD SETTINGS
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf" #=================================================
ynh_backup "/etc/systemd/system/${app}.service" "conf/systemd.service"
ynh_backup "/usr/bin/${app}" "conf/haste.sh" 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
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP LOGROTATE
#=================================================
ynh_backup "/etc/logrotate.d/$app"
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup "/etc/systemd/system/$app.service"
# Copy NGINX configuration
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf"

View file

@ -1,33 +1,160 @@
#!/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_url=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_IS_PUBLIC is_public=$YNH_APP_ARG_IS_PUBLIC
# Check domain/path availability app=$YNH_APP_INSTANCE_NAME
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
if ! [ "$path" = "/" ] #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
final_path=/var/www/$app
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 is_public "$is_public"
ynh_app_setting_set $app path_url "$path_url"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
# 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
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 4
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
# 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
#=================================================
# 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_add_systemd_config
#=================================================
# 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
#=================================================
# Configure haste with config.js file
#=================================================
ynh_replace_string "YNH_DATA_PATH" "$DATA_PATH" "$final_path/config.js"
#=================================================
# 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
#=================================================
systemctl start $app
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 1 ];
then then
ynh_die "Path must be /" ynh_app_setting_set "$app" unprotected_uris "/"
fi fi
# Save app settings #=================================================
ynh_app_setting_set "$app" is_public "$is_public" # RELOAD NGINX
#=================================================
# Install the app systemctl reload nginx
install_haste $domain $path $is_public
# Start Haste
sudo systemctl start "$app".service
# Add Haste to YunoHost's monitored services
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log

View file

@ -1,33 +1,86 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables and functions source _common.sh
source ./_common.sh source /usr/share/yunohost/helpers
# Retrieve app settings #=================================================
domain=$(ynh_app_setting_get "$app" domain) # LOAD SETTINGS
#=================================================
# Stop haste app=$YNH_APP_INSTANCE_NAME
sudo systemctl stop "$app".service
# Remove sources domain=$(ynh_app_setting_get $app domain)
sudo rm -rf "/opt/"${app} 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)
# Remove nginx configuration file #=================================================
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" # STANDARD REMOVE
#=================================================
# STOP AND REMOVE SERVICE
#=================================================
# Remove haste user and data # Remove the dedicated systemd config
sudo userdel -r "$app" ynh_remove_systemd_config
# Remove init script #=================================================
sudo systemctl disable "$app".service # REMOVE SERVICE FROM ADMIN PANEL
sudo rm -f /etc/systemd/system/"$app".service #=================================================
sudo systemctl daemon-reload
# Remove monitor if yunohost service status | grep -q $app
sudo yunohost service remove "$app" then
echo "Remove $app service"
yunohost service remove $app
fi
# Reload nginx service
sudo systemctl reload nginx.service #=================================================
# 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
#=================================================
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
#=================================================
# Delete a system user
ynh_system_user_delete $app

View file

@ -1,39 +1,124 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables and functions if [ ! -e _common.sh ]; then
source ./_common.sh # Get the _common.sh file if it's not in the current directory
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
# Retrieve old app settings #=================================================
domain=$(ynh_app_setting_get "$app" domain) # MANAGE SCRIPT FAILURE
path=$(ynh_app_setting_get "$app" path) #=================================================
is_public=$(ynh_app_setting_get "$app" is_public)
# Check domain/path availability # Exit if an error occurs during the execution of the script
sudo yunohost app checkurl "${domain}${path}" -a "$app" \ ynh_abort_if_errors
|| ynh_die "Path not available: ${domain}${path}"
# Check destination directory #=================================================
[[ -d $DESTDIR ]] && ynh_die \ # LOAD SETTINGS
"The destination directory '$DESTDIR' already exists.\ #=================================================
You should safely delete it before restoring this app."
# Check configuration files app=$YNH_APP_INSTANCE_NAME
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
[[ -f $nginx_conf ]] && ynh_die \
"The NGINX configuration already exists at '${nginx_conf}'.
You should safely delete it before restoring this app."
pre_inst_haste backup 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)
# Restore NGINX configuration #=================================================
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf" # CHECK IF THE APP CAN BE RESTORED
#=================================================
# Restart webserver and app ynh_webpath_available $domain $path_url \
sudo systemctl reload nginx.service || ynh_die "Path not available: ${domain}${path_url}"
sudo systemctl start "$app".service test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Add Haste to YunoHost's monitored services #=================================================
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log # STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R root: $final_path
#=================================================
# SPECIFIC RESTORATION
#=================================================
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
#=================================================
yunohost service add $app --log "/var/log/$app/APP.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# START HASTEBIN IN BACKGROUND
#=================================================
systemctl start $app
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx

View file

@ -1,18 +1,162 @@
#!/bin/bash #!/bin/bash
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Load common variables and functions source _common.sh
source ./_common.sh source /usr/share/yunohost/helpers
# Retrieve arguments #=================================================
domain=$(ynh_app_setting_get "$app" domain) # LOAD SETTINGS
path=$(ynh_app_setting_get "$app" path) #=================================================
is_public=$(ynh_app_setting_get "$app" is_public)
# Install the app app=$YNH_APP_INSTANCE_NAME
install_haste $domain $path $is_public
# Start Haste domain=$(ynh_app_setting_get $app domain)
sudo systemctl restart "$app".service path_url=$(ynh_app_setting_get $app path_url)
is_public=$(ynh_app_setting_get $app is_public)
final_path=$(ynh_app_setting_get $app final_path)
port=$(ynh_app_setting_get $app port)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
# Fix is_public as a boolean value
if [ "$is_public" = "Yes" ]; then
ynh_app_setting_set $app is_public 1
is_public=1
elif [ "$is_public" = "No" ]; then
ynh_app_setting_set $app is_public 0
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
ynh_app_setting_set $app final_path $final_path
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK THE PATH
#=================================================
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 4
#=================================================
# 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
#=================================================
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
#=================================================
# 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
# 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
#=================================================
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set right permissions for curl installation
chown -R root: $final_path
#=================================================
# 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 ]
then
# unprotected_uris allows SSO credentials to be passed anyway
ynh_app_setting_set $app unprotected_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx