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

Some fixes

This commit is contained in:
anmol26s 2018-06-05 02:27:21 +05:30
parent 9779acbee9
commit 11fa2d211c
6 changed files with 145 additions and 157 deletions

View file

@ -1,5 +1,8 @@
# 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)
@ -14,7 +17,7 @@
setup_public=0
upgrade=1
backup_restore=1
multi_instance=0
multi_instance=1
incorrect_path=1
port_already_use=0
change_url=0
@ -32,5 +35,5 @@
Level 9=0
Level 10=0
;;; Options
Email=anmol@datamol.in
Email=anmol@datamol.org
Notification=none

View file

@ -5,16 +5,23 @@
"en": "An URL shortening service",
"fr": "Un service de raccourcisseur d'url"
},
"version": "1.0",
"url": "https://github.com/YOURLS/YOURLS",
"license": "free",
"developer": {
"maintainer": {
"name": "Anmol Sharma",
"email": "anmol@datamol.in"
"email": "anmol@datamol.org",
"url": ""
},
"requirements": {
"yunohost": ">> 2.5.6"
},
"multi_instance": "false",
"yunohost": ">= 2.7.2"
},
"previous_maintainers": {
"name": "courgette",
"email": "courgette@farcie.fr",
"url": "http://thomaslebeau.fr"
},
"multi_instance": "true",
"services": [
"nginx",
"php5-fpm",

View file

@ -1,112 +1,13 @@
#!/bin/bash
# =============================================================================
# YUNOHOST 2.7 FORTHCOMING HELPERS
# =============================================================================
# Create a dedicated nginx config
# ============= FUTURE YUNOHOST HELPER =============
# Delete a file checksum from the app settings
#
# usage: ynh_add_nginx_config
ynh_add_nginx_config () {
finalnginxconf="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalnginxconf" 1
sudo cp ../conf/nginx.conf "$finalnginxconf"
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${path_url:-}"; then
ynh_replace_string "__PATH__" "$path_url" "$finalnginxconf"
fi
if test -n "${domain:-}"; then
ynh_replace_string "__DOMAIN__" "$domain" "$finalnginxconf"
fi
if test -n "${port:-}"; then
ynh_replace_string "__PORT__" "$port" "$finalnginxconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__NAME__" "$app" "$finalnginxconf"
fi
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalnginxconf"
fi
ynh_store_checksum_config "$finalnginxconf"
sudo systemctl reload nginx
}
# Remove the dedicated nginx config
# $app should be defined when calling this helper
#
# usage: ynh_remove_nginx_config
ynh_remove_nginx_config () {
ynh_secure_remove "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo systemctl reload nginx
}
# Create a dedicated php-fpm config
#
# usage: ynh_add_fpm_config
ynh_add_fpm_config () {
finalphpconf="/etc/php5/fpm/pool.d/$app.conf"
ynh_backup_if_checksum_is_different "$finalphpconf" 1
sudo cp ../conf/php-fpm.conf "$finalphpconf"
ynh_replace_string "__NAMETOCHANGE__" "$app" "$finalphpconf"
ynh_replace_string "__FINALPATH__" "$final_path" "$finalphpconf"
ynh_replace_string "__USER__" "$app" "$finalphpconf"
sudo chown root: "$finalphpconf"
ynh_store_file_checksum "$finalphpconf"
if [ -e "../conf/php-fpm.ini" ]
then
finalphpini="/etc/php5/fpm/conf.d/20-$app.ini"
ynh_compare_checksum_config "$finalphpini" 1
sudo cp ../conf/php-fpm.ini "$finalphpini"
sudo chown root: "$finalphpini"
ynh_store_checksum_config "$finalphpini"
fi
sudo systemctl reload php5-fpm
}
# Remove the dedicated php-fpm config
#
# usage: ynh_remove_fpm_config
ynh_remove_fpm_config () {
ynh_secure_remove "/etc/php5/fpm/pool.d/$app.conf"
ynh_secure_remove "/etc/php5/fpm/conf.d/20-$app.ini" 2>&1
sudo systemctl reload php5-fpm
}
# Create a dedicated systemd config
#
# usage: ynh_add_systemd_config
ynh_add_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
ynh_compare_checksum_config "$finalsystemdconf" 1
sudo cp ../conf/systemd.service "$finalsystemdconf"
# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if test -n "${final_path:-}"; then
ynh_replace_string "__FINALPATH__" "$final_path" "$finalsystemdconf"
fi
if test -n "${app:-}"; then
ynh_replace_string "__APP__" "$app" "$finalsystemdconf"
fi
ynh_store_checksum_config "$finalsystemdconf"
sudo chown root: "$finalsystemdconf"
sudo systemctl enable $app
sudo systemctl daemon-reload
}
# Remove the dedicated systemd config
#
# usage: ynh_remove_systemd_config
ynh_remove_systemd_config () {
finalsystemdconf="/etc/systemd/system/$app.service"
if [ -e "$finalsystemdconf" ]; then
sudo systemctl stop $app
sudo systemctl disable $app
ynh_secure_remove "$finalsystemdconf"
fi
# usage: ynh_remove_file_checksum file
# | arg: file - The file for which the checksum will be deleted
ynh_delete_file_checksum () {
local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
ynh_app_setting_delete $app $checksum_setting_name
}

View file

@ -2,25 +2,26 @@
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
set -eu
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
if [ ! -e _common.sh ]; then
# Get the _common.sh file if it's not in the current directory
sudo cp ../settings/scripts/_common.sh ./_common.sh
sudo chmod a+rx _common.sh
cp ../settings/scripts/_common.sh ./_common.sh
chmod a+rx _common.sh
fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
@ -30,7 +31,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)
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
#=================================================
# STANDARD BACKUP STEPS
@ -38,14 +38,24 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup "$final_path" "$final_path"
ynh_backup "$final_path"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# BACKUP THE PHP-FPM CONFIGURATION
#=================================================
ynh_backup "/etc/php5/fpm/pool.d/$app.conf"
ynh_backup "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# BACKUP THE MYSQL DATABASE

View file

@ -2,13 +2,6 @@
#=================================================
# GENERIC START
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit on command errors and treat access to unset variables as an error
set -eu
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
@ -21,6 +14,13 @@ fi
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
@ -36,7 +36,7 @@ db_name=$(ynh_app_setting_get $app db_name)
# CHECK IF THE APP CAN BE RESTORED
#=================================================
sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
@ -54,8 +54,6 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
ynh_restore_file "$final_path"
sudo chown -R www-data: $final_path
#=================================================
# RESTORE THE MYSQL DATABASE
@ -65,6 +63,27 @@ db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# 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
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file "/etc/php5/fpm/pool.d/$app.conf"
ynh_restore_file "/etc/php5/fpm/conf.d/20-$app.ini"
#=================================================
# GENERIC FINALIZATION
@ -73,5 +92,11 @@ ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
sudo yunohost app setting $app unprotected_uris -v "/"
sudo systemctl reload php5-fpm
sudo systemctl reload nginx
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
systemctl reload php5-fpm
systemctl reload nginx

View file

@ -28,6 +28,25 @@ if [ -z $db_name ]; then # If db_name doesn't exist, create it
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
#=================================================
@ -40,43 +59,66 @@ path_url=$(ynh_normalize_url_path $path_url)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
sudo mv ${final_path} ${final_path}.old
# Download, check integrity, uncompress and patch the source from app.src
# Create a temporary directory
tmpdir="$(mktemp -d)"
# Backup the app files in the temp dir
sudo cp -a "$final_path/index.php" "$tmpdir"
sudo cp -a "$final_path/user/plugins/yunohost_auth" "$tmpdir/user/plugins"
sudo cp -a "$final_path/.htaccess" "$tmpdir"
sudo cp -a "$final_path/user/config.php" "$tmpdir/user"
# Remove the app directory securely
ynh_secure_remove "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
sudo cp -a ${final_path}.old/index.php ${final_path}
sudo cp -a ${final_path}.old/user/plugins/yunohost_auth ${final_path}/user/plugins
sudo cp -a ${final_path}.old/.htaccess ${final_path}
sudo cp -a ${final_path}.old/user/config.php ${final_path}/user
sudo chown -R www-data: $final_path
# delete temp directory
sudo rm -Rf ${final_path}.old
# Copy the app files from tmp to final_path
sudo cp -a "$tmpdir/index.php" "$final_path"
sudo cp -a "$tmpdir/user/plugins/yunohost_auth" "$final_path/user/plugins"
sudo cp -a "$tmpdir/.htaccess" "$final_path"
sudo cp -a "$tmpdir/user/config.php" "$final_path/user"
#remove tmp dir
sudo rm -Rf "$tmpdir"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@LOCATIONTOCHANGE@$path_url@g" ../conf/nginx.conf*
sed -i "s@PATHTOCHANGE@${path_url%/}@g" ../conf/nginx.conf*
sed -i "s@DOMAINTOCHANGE@$domain@g" ../conf/nginx.conf*
sed -i "s@ALIASTOCHANGE@$final_path@g" ../conf/nginx.conf*
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf
sudo chmod 600 $nginxconf
ynh_add_nginx_config
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
# PHP-FPM CONFIGURATION
#=================================================
# Create a dedicated php-fpm config
ynh_add_fpm_config
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/user/config.php"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/user/config.php"
# Set right permissions for curl installation
chown -R $app: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_set $app unprotected_uris "/"
#=================================================
# RELOAD NGINX
#=================================================