mirror of
https://github.com/YunoHost-Apps/bozon_ynh.git
synced 2024-09-03 18:16:09 +02:00
Update according to new packaging standards & helpers
This commit is contained in:
parent
55fda9d132
commit
8bb48ce8cb
11 changed files with 443 additions and 246 deletions
|
@ -3,11 +3,12 @@
|
|||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
path="/path" (PATH)
|
||||
is_public="Yes" (PUBLIC|public=Yes|private=No)
|
||||
is_public=1 (PUBLIC)
|
||||
language="en"
|
||||
filesize="2G"
|
||||
admin="john" (USER)
|
||||
password="super_secret_password" (PASSWORD)
|
||||
backup_core_only=1
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=1
|
||||
|
|
5
conf/app.src
Normal file
5
conf/app.src
Normal file
|
@ -0,0 +1,5 @@
|
|||
SOURCE_URL=https://github.com/broncowdd/BoZoN/archive/06f2a665f45e3e8f4c4bf71bf4146e8accb27776.zip
|
||||
SOURCE_SUM=d82dddd968a8cb31e21d1fb3e0518f4b88d92ec95948d652c0c378fce4dc8e65
|
||||
SOURCE_FORMAT=zip
|
||||
|
||||
#sha256sum obtain with shasum -a 256 $SOURCE_URL
|
|
@ -1,6 +1,6 @@
|
|||
location YNH_EXAMPLE_PATH {
|
||||
location __PATH__ {
|
||||
# Path to source
|
||||
alias YNH_EXAMPLE_ALIAS/;
|
||||
alias __FINALPATH__/;
|
||||
if ($scheme = http) {
|
||||
rewrite ^ https://$server_name$request_uri? permanent;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ location YNH_EXAMPLE_PATH {
|
|||
add_header X-Permitted-Cross-Domain-Policies none;
|
||||
|
||||
# Set max upload size
|
||||
client_max_body_size YNH_FILE_SIZE;
|
||||
client_max_body_size __FILESIZE__;
|
||||
client_body_timeout 30m;
|
||||
proxy_read_timeout 30m;
|
||||
fastcgi_buffers 64 4K;
|
||||
|
@ -28,7 +28,7 @@ location YNH_EXAMPLE_PATH {
|
|||
location ~ [^/]\.php(/|$) {
|
||||
include fastcgi_params;
|
||||
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-YNH_EXAMPLE_APP.sock;
|
||||
fastcgi_pass unix:/var/run/php5-fpm-__NAME__.sock;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param REMOTE_USER $remote_user;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[YNH_EXAMPLE_APP]
|
||||
[__NAME__]
|
||||
; The address on which to accept FastCGI requests.
|
||||
listen = /var/run/php5-fpm-YNH_EXAMPLE_APP.sock
|
||||
listen = /var/run/php5-fpm-__NAME__.sock
|
||||
|
||||
; Set permissions for unix socket, if one is used.
|
||||
listen.owner = www-data
|
||||
|
@ -8,8 +8,8 @@ listen.group = www-data
|
|||
listen.mode = 0600
|
||||
|
||||
; Unix user/group of processes.
|
||||
user = www-data
|
||||
group = www-data
|
||||
user = __NAME__
|
||||
group = __NAME__
|
||||
|
||||
; Choose how the process manager will control the number of child processes.
|
||||
pm = dynamic
|
||||
|
@ -47,7 +47,7 @@ request_terminate_timeout = 1d
|
|||
request_slowlog_timeout = 5s
|
||||
|
||||
; The log file for slow requests.
|
||||
slowlog = /var/log/nginx/YNH_EXAMPLE_APP.slow.log
|
||||
slowlog = /var/log/nginx/__NAME__.slow.log
|
||||
|
||||
; Set open file descriptor rlimit.
|
||||
rlimit_files = 4096
|
||||
|
@ -56,7 +56,7 @@ rlimit_files = 4096
|
|||
rlimit_core = 0
|
||||
|
||||
; Chdir to this directory at the start.
|
||||
chdir = YNH_EXAMPLE_ALIAS
|
||||
chdir = __FINALPATH__
|
||||
|
||||
; Redirect worker stdout and stderr into main error log.
|
||||
catch_workers_output = yes
|
||||
|
@ -65,7 +65,7 @@ catch_workers_output = yes
|
|||
clear_env = no
|
||||
|
||||
; Additional php.ini defines, specific to this pool of workers.
|
||||
php_value[upload_max_filesize] = YNH_FILE_SIZE
|
||||
php_value[post_max_size] = YNH_POST_SIZE
|
||||
php_value[upload_max_filesize] = __FILESIZE__
|
||||
php_value[post_max_size] = __POSTSIZE__
|
||||
php_value[default_charset] = UTF-8
|
||||
php_value[always_populate_raw_post_data] = -1
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
},
|
||||
"url": "http://bozon.pw",
|
||||
"license": "free",
|
||||
"version": "2.4.18",
|
||||
"maintainer": {
|
||||
"name": "ewilly",
|
||||
"email": "ewilly@neuf.fr"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 2.4"
|
||||
"yunohost": ">= 2.6.3"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
|
@ -43,12 +44,12 @@
|
|||
},
|
||||
{
|
||||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Should this application be public ? (if not, sharing file with unregistered users still work)",
|
||||
"fr": "Est-ce que cette application doit être visible publiquement ? (dans le cas contraire, le partage de fichiers avec des utilisateurs externes fonctionnera tout de même)"
|
||||
},
|
||||
"choices": ["Yes", "No"],
|
||||
"default": "No"
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"name": "language",
|
||||
|
@ -84,6 +85,15 @@
|
|||
"fr": "Choisissez un mot de passe administrateur pour BoZoN"
|
||||
},
|
||||
"example": "super_secret_password"
|
||||
},
|
||||
{
|
||||
"name": "backup_core_only",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "In a case of backup should I only backup the core of the app ? (your uploaded to BoZoN datas as videos, pictures, documents, etc. will not be backuped)",
|
||||
"fr": "En cas de sauvegarde dois-je seulement sauvegarder le coeur de l'application ? (les fichiers trasnférés dans BoZoN tels que les vidéos, images, documents, etc. ne seront pas sauvegardés)"
|
||||
},
|
||||
"default": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
120
scripts/_common.sh
Normal file
120
scripts/_common.sh
Normal file
|
@ -0,0 +1,120 @@
|
|||
#
|
||||
# Common variables & functions
|
||||
#
|
||||
|
||||
# Package dependencies
|
||||
PKG_DEPENDENCIES="php5-curl php5-gd"
|
||||
|
||||
# Check if directory/file already exists (path in argument)
|
||||
myynh_check_path () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ ! -e "$1" ] || ynh_die "$1 already exists"
|
||||
}
|
||||
|
||||
# Create directory only if not already exists (path in argument)
|
||||
myynh_create_dir () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ -d "$1" ] || sudo mkdir -p "$1"
|
||||
}
|
||||
|
||||
# Check if enough disk space available on backup storage
|
||||
myynh_check_disk_space () {
|
||||
file_to_analyse=$1
|
||||
backup_size=$(sudo du --summarize "$1" | cut -f1)
|
||||
free_space=$(sudo df --output=avail "/home/yunohost.backup" | sed 1d)
|
||||
if [ $free_space -le $backup_size ]
|
||||
then
|
||||
WARNING echo "Not enough backup disk space for: $1"
|
||||
WARNING echo "Space available: $(HUMAN_SIZE $free_space)"
|
||||
ynh_die "Space needed: $(HUMAN_SIZE $backup_size)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Create a dedicated nginx config
|
||||
myynh_add_nginx_config () {
|
||||
ynh_backup_if_checksum_is_different "$nginx_conf" 1
|
||||
sudo cp ../conf/nginx.conf "$nginx_conf"
|
||||
# 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" "$nginx_conf"
|
||||
fi
|
||||
if test -n "${final_path:-}"; then
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$nginx_conf"
|
||||
fi
|
||||
if test -n "${app:-}"; then
|
||||
ynh_replace_string "__NAME__" "$app" "$nginx_conf"
|
||||
fi
|
||||
if test -n "${filesize:-}"; then
|
||||
ynh_replace_string "__FILESIZE__" "$filesize" "$nginx_conf"
|
||||
fi
|
||||
ynh_store_file_checksum "$nginx_conf"
|
||||
sudo systemctl reload nginx
|
||||
}
|
||||
|
||||
# Remove the dedicated nginx config
|
||||
myynh_remove_nginx_config () {
|
||||
ynh_secure_remove "$nginx_conf"
|
||||
sudo systemctl reload nginx
|
||||
}
|
||||
|
||||
# Create a dedicated php-fpm config
|
||||
myynh_add_fpm_config () {
|
||||
ynh_backup_if_checksum_is_different "$phpfpm_conf" 1
|
||||
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
|
||||
postsize=${filesize%?}.1${filesize: -1}
|
||||
ynh_replace_string "__FINALPATH__" "$final_path" "$phpfpm_conf"
|
||||
ynh_replace_string "__NAME__" "$app" "$phpfpm_conf"
|
||||
ynh_replace_string "__FILESIZE__" "$filesize" "$phpfpm_conf"
|
||||
ynh_replace_string "__POSTSIZE__" "$postsize" "$phpfpm_conf"
|
||||
sudo chown root: "$phpfpm_conf"
|
||||
ynh_store_file_checksum "$phpfpm_conf"
|
||||
sudo systemctl reload php5-fpm
|
||||
}
|
||||
|
||||
# Remove the dedicated php-fpm config
|
||||
myynh_remove_fpm_config () {
|
||||
ynh_secure_remove "$phpfpm_conf"
|
||||
sudo systemctl restart php5-fpm
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# FUTURE YUNOHOST HELPERS - TO BE REMOVED LATER
|
||||
#=================================================
|
||||
# Restore a previous backup if the upgrade process failed
|
||||
ynh_backup_after_failed_upgrade () {
|
||||
echo "Upgrade failed." >&2
|
||||
app_bck=${app//_/-} # Replace all '_' by '-'
|
||||
# Check if a existing backup can be found before remove and restore the application.
|
||||
if sudo yunohost backup list | grep -q $app_bck-upg$backup_number; then
|
||||
# Remove the application then restore it
|
||||
sudo yunohost app remove $app
|
||||
# Restore the backup if the upgrade failed
|
||||
sudo yunohost backup restore --ignore-system $app_bck-upg$backup_number --apps $app --force
|
||||
ynh_die "The app was restored to the way it was before the failed upgrade."
|
||||
fi
|
||||
}
|
||||
|
||||
# Make a backup in case of failed upgrade
|
||||
ynh_backup_before_upgrade () {
|
||||
backup_number=1
|
||||
old_backup_number=2
|
||||
app_bck=${app//_/-} # Replace all '_' by '-'
|
||||
# Check if a backup already exist with the prefix 1.
|
||||
if sudo yunohost backup list | grep -q $app_bck-upg1; then
|
||||
# Prefix become 2 to preserve the previous backup
|
||||
backup_number=2
|
||||
old_backup_number=1
|
||||
fi
|
||||
# Create another backup
|
||||
sudo yunohost backup create --ignore-system --apps $app --name $app_bck-upg$backup_number
|
||||
if [ "$?" -eq 0 ]; then
|
||||
# If the backup succedded, remove the previous backup
|
||||
if sudo yunohost backup list | grep -q $app_bck-upg$old_backup_number; then
|
||||
# Remove the previous backup only if it exists
|
||||
sudo yunohost backup delete $app_bck-upg$old_backup_number > /dev/null
|
||||
fi
|
||||
else
|
||||
ynh_die "Backup failed, the upgrade process was aborted."
|
||||
fi
|
||||
}
|
|
@ -1,25 +1,44 @@
|
|||
#!/bin/bash
|
||||
# to test the functionnality :
|
||||
# yunohost backup create -n "bozon-test" --ignore-system --apps bozon
|
||||
# yunohost backup delete bozon-test
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
|
||||
# Source YunoHost 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
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# manage script failure
|
||||
ynh_abort_if_errors
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
# definie useful vars
|
||||
parent_path=/var/www
|
||||
final_path="$parent_path"/"$app"
|
||||
data_path=/home/yunohost.app/"$app"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
|
||||
|
||||
# backup sources & data
|
||||
ynh_backup "$final_path" "www"
|
||||
ynh_backup "$data_path" "data"
|
||||
# backup source & conf files
|
||||
if [ -e "$final_path" ]; then
|
||||
myynh_check_disk_space "$final_path"
|
||||
ynh_backup "$final_path" "source"
|
||||
fi
|
||||
[ -e "$nginx_conf" ] && ynh_backup "$nginx_conf" "nginx.conf"
|
||||
[ -e "$phpfpm_conf" ] && ynh_backup "$phpfpm_conf" "php-fpm.conf"
|
||||
|
||||
# backup Nginx and php-fpm
|
||||
mkdir ./conf
|
||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "conf/nginx.conf"
|
||||
ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "conf/php-fpm.conf"
|
||||
# backup data
|
||||
if [ -e "$data_path" ]; then
|
||||
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
|
||||
if [ $backup_core_only -eq 0 ]; then
|
||||
myynh_check_disk_space "$data_path"
|
||||
ynh_backup "$data_path" "data" 1
|
||||
else
|
||||
echo "Data dir will not be saved, because backup_core_only is set to true." >&2
|
||||
fi
|
||||
fi
|
||||
|
|
146
scripts/install
146
scripts/install
|
@ -1,131 +1,113 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
|
||||
# Source YunoHost helpers
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# manage script failure
|
||||
ynh_abort_if_errors
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$YNH_APP_ARG_DOMAIN
|
||||
path=$YNH_APP_ARG_PATH
|
||||
path_url=$YNH_APP_ARG_PATH
|
||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||
language=$YNH_APP_ARG_LANGUAGE
|
||||
filesize=$YNH_APP_ARG_FILESIZE
|
||||
admin=$YNH_APP_ARG_ADMIN
|
||||
password=$YNH_APP_ARG_PASSWORD
|
||||
|
||||
|
||||
# chech if / is present at start and not at end
|
||||
if [ "${path:0:1}" != "/" ] && [ ${#path} -gt 0 ]; then
|
||||
# first char is not / && path not empty => add / at start
|
||||
path="/$path"
|
||||
fi
|
||||
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
|
||||
# last char is / && path is gretter than /
|
||||
path="${path:0:${#path}-1}"
|
||||
fi
|
||||
backup_core_only=$YNH_APP_ARG_BACKUP_CORE_ONLY
|
||||
|
||||
# definie useful vars
|
||||
parent_path=/var/www
|
||||
final_path="$parent_path"/"$app"
|
||||
data_path=/home/yunohost.app/"$app"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
bozon_conf="$final_path/config.php"
|
||||
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
|
||||
|
||||
# check domain/path availability
|
||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die "The path ${domain}${path} is not available for app installation."
|
||||
path_url=$(ynh_normalize_url_path "$path_url")
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||
myynh_check_path "$final_path"
|
||||
|
||||
# check that admin user is an existing account
|
||||
ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist."
|
||||
ynh_user_exists "$admin"
|
||||
|
||||
# add required packages
|
||||
ynh_package_is_installed "php5-curl" || ynh_package_install "php5-curl"
|
||||
ynh_package_is_installed "php5-gd" || ynh_package_install "php5-gd"
|
||||
|
||||
# retrieve upstream_version version of bozon
|
||||
upstream_version=$(cat ../conf/upstream_version)
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
|
||||
# save app settings
|
||||
ynh_app_setting_set "$app" admin_user "$admin"
|
||||
ynh_app_setting_set "$app" is_public "$is_public"
|
||||
ynh_app_setting_set "$app" domain "$domain"
|
||||
ynh_app_setting_set "$app" path "$path"
|
||||
ynh_app_setting_set "$app" path "$path_url"
|
||||
ynh_app_setting_set "$app" is_public $is_public
|
||||
ynh_app_setting_set "$app" filesize "$filesize"
|
||||
ynh_app_setting_set "$app" language "$language"
|
||||
ynh_app_setting_set "$app" admin_user "$admin"
|
||||
ynh_app_setting_set "$app" backup_core_only $backup_core_only
|
||||
|
||||
# download upstream_version version of bozon
|
||||
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
|
||||
sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
|
||||
sudo mv /tmp/BoZoN-"$upstream_version" "$parent_path"/"$app"
|
||||
# create a dedicated system user
|
||||
ynh_system_user_create "$app"
|
||||
|
||||
# copy files to final folder and set permissions
|
||||
sudo find "$final_path" -type f -name ".htaccess" | xargs sudo rm
|
||||
sudo chown -R root: "$final_path"
|
||||
sudo find "$final_path" -type f | xargs sudo chmod 644
|
||||
sudo find "$final_path" -type d | xargs sudo chmod 755
|
||||
# download & unpack bozon
|
||||
TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$TMPDIR"
|
||||
|
||||
# clean & copy files needed to final folder
|
||||
sudo find "$TMPDIR" -type f -name ".htaccess" | xargs sudo rm
|
||||
sudo find "$TMPDIR" -type f -name ".htaccess" | xargs sudo rm
|
||||
if [ -e "$TMPDIR/.gitignore" ]; then
|
||||
for f in $(sudo cat "$TMPDIR/.gitignore") ; do
|
||||
[ -e "$TMPDIR$f" ] && sudo rm -R "$TMPDIR$f"
|
||||
done
|
||||
sudo rm "$TMPDIR/.gitignore"
|
||||
fi
|
||||
sudo mv "$TMPDIR" "$final_path"
|
||||
|
||||
# configure config file
|
||||
sudo sed -i "s@languageuage='en';@languageuage='${language}';@g" "$final_path"/config.php
|
||||
ynh_replace_string "default_language='en'" "default_language='$language'" "$bozon_conf"
|
||||
ynh_store_file_checksum "$bozon_conf"
|
||||
|
||||
# create data folders
|
||||
sudo mkdir -p "$final_path"/private
|
||||
sudo mkdir -p "$data_path"/uploads
|
||||
sudo ln -s "$data_path"/uploads "$final_path"/uploads
|
||||
sudo mkdir -p "$data_path"/thumbs
|
||||
sudo ln -s "$data_path"/thumbs "$final_path"/thumbs
|
||||
sudo chown -R www-data: "$final_path"/private
|
||||
sudo chown -R www-data: "$data_path"/uploads
|
||||
sudo chown -R www-data: "$data_path"/thumbs
|
||||
# create private & data folders
|
||||
myynh_create_dir "$final_path/private"
|
||||
myynh_create_dir "$data_path/uploads"
|
||||
myynh_create_dir "$data_path/thumbs"
|
||||
sudo ln -s "$data_path/uploads" "$final_path/uploads"
|
||||
sudo ln -s "$data_path/thumbs" "$final_path/thumbs"
|
||||
|
||||
# set permissions
|
||||
sudo find "$final_path" -type f | xargs sudo chmod 0640
|
||||
sudo find "$final_path" -type d | xargs sudo chmod 0750
|
||||
sudo find "$data_path" -type d | xargs sudo chmod 0750
|
||||
sudo chown -R "$app": "$final_path/private"
|
||||
sudo chown -R "$app": "$data_path/uploads"
|
||||
sudo chown -R "$app": "$data_path/thumbs"
|
||||
|
||||
# configure nginx settings
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
|
||||
sudo cp ../conf/nginx.conf "$nginx_conf"
|
||||
myynh_add_nginx_config
|
||||
|
||||
# copy and set php-fpm configuration
|
||||
postsize=${filesize%?}.1${filesize: -1}
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf
|
||||
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
|
||||
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
|
||||
sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
|
||||
## copy final and set permissions
|
||||
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
|
||||
sudo chown root: "$phpfpm_conf"
|
||||
sudo chmod 644 "$phpfpm_conf"
|
||||
myynh_add_fpm_config
|
||||
|
||||
# restart services
|
||||
sudo service php5-fpm restart || true
|
||||
sudo service nginx reload || true
|
||||
|
||||
# set temporary public access
|
||||
# set temporary public access for curl call
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
sudo yunohost app ssowatconf
|
||||
|
||||
# add alias line in hosts file
|
||||
echo "127.0.0.1 $domain # $app" | sudo tee -a /etc/hosts
|
||||
|
||||
# fill the superadmin creation form
|
||||
curl_path=$([ "$path" == "/" ] || echo "$path")
|
||||
curl -k https://"$domain""$curl_path"/ > /dev/null 2>&1
|
||||
sleep 1 && curl -kX POST \
|
||||
# fill the superadmin creation form (helper ynh_local_curl doesn't work due to --data vs --data-urlencode ?)
|
||||
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 https://localhost"$path_url"/ > /dev/null 2>&1
|
||||
sleep 1
|
||||
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST \
|
||||
--data-urlencode creation="1" \
|
||||
--data-urlencode login="$admin" \
|
||||
--data-urlencode pass="$password" \
|
||||
--data-urlencode confirm="$password" \
|
||||
https://"$domain""$curl_path"/index.php?p=login > /dev/null 2>&1
|
||||
|
||||
# remove alias line from hosts file
|
||||
sudo sed -i "/# $app/d" /etc/hosts
|
||||
https://localhost"$path_url"/index.php?p=login > /dev/null 2>&1
|
||||
|
||||
# if app is private, remove url to SSOWat conf from skipped_uris
|
||||
if [ "$is_public" = "No" ];
|
||||
if [ $is_public -eq 0 ]
|
||||
then
|
||||
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
|
||||
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
pathluaregex=$([ "$path" == "/" ] || echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
pathluaregex=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
|
||||
ynh_app_setting_set "$app" protected_regex "$regexList"
|
||||
sudo yunohost app ssowatconf
|
||||
|
|
|
@ -1,33 +1,50 @@
|
|||
#!/bin/bash
|
||||
# to test the functionnality :
|
||||
# yunohost app remove bozon
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -u
|
||||
|
||||
# Source YunoHost 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
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#retrieve arguments
|
||||
# manage script failure
|
||||
set -u
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "${app}" domain)
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
|
||||
if [ -e "/var/www/${app}" ]; then
|
||||
echo "Delete app"
|
||||
sudo rm -rf /var/www/${app}
|
||||
fi
|
||||
if [ -e "/etc/nginx/conf.d/${domain}.d/${app}.conf" ]; then
|
||||
echo "Delete Nginx config"
|
||||
sudo rm -f /etc/nginx/conf.d/${domain}.d/${app}.conf
|
||||
fi
|
||||
if [ -e "/etc/php5/fpm/pool.d/${app}.conf" ]; then
|
||||
echo "Delete fpm config"
|
||||
sudo rm -f /etc/php5/fpm/pool.d/${app}.conf
|
||||
fi
|
||||
if [ -e "/home/yunohost.app/${app}" ]; then
|
||||
echo "Delete datas"
|
||||
sudo rm -rf /home/yunohost.app/${app}
|
||||
# definie useful vars
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
|
||||
|
||||
# create a full backup (core+datas) if app installed
|
||||
if [ $(sudo yunohost app list -i -f "$app" | wc -l) -gt 1 ]; then
|
||||
ynh_app_setting_set "$app" backup_core_only 0
|
||||
app_bck=${app//_/-}
|
||||
sudo yunohost backup create --ignore-system --apps "$app" --name "${app_bck}_$(date '+%Y%m%d-%H%M%S')"
|
||||
echo "BoZon fully backuped." >&2
|
||||
fi
|
||||
|
||||
# Restart services
|
||||
sudo service php5-fpm restart || true
|
||||
sudo service nginx reload || true
|
||||
sudo yunohost app ssowatconf
|
||||
# remove metapackage and its dependencies
|
||||
ynh_remove_app_dependencies
|
||||
|
||||
# remove the app directory securely
|
||||
ynh_secure_remove "$final_path"
|
||||
|
||||
# remove the dedicated nginx config
|
||||
myynh_remove_nginx_config
|
||||
|
||||
# remove the dedicated php-fpm config
|
||||
myynh_remove_fpm_config
|
||||
|
||||
# remove a directory securely
|
||||
ynh_secure_remove "$data_path"
|
||||
|
||||
# delete a system user
|
||||
ynh_system_user_delete "$app"
|
||||
|
|
101
scripts/restore
101
scripts/restore
|
@ -1,64 +1,67 @@
|
|||
#!/bin/bash
|
||||
# to test the functionnality :
|
||||
# yunohost backup create -n "bozon-test" --ignore-system --apps bozon
|
||||
# yunohost app remove bozon
|
||||
# yunohost backup restore "bozon-test"
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
|
||||
# Source YunoHost helpers
|
||||
if [ ! -e _common.sh ]; then
|
||||
# Fetch helpers file if not in current directory
|
||||
sudo cp ../settings/scripts/_common.sh ./_common.sh
|
||||
sudo chmod a+rx _common.sh
|
||||
fi
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
#retrieve arguments
|
||||
# manage script failure
|
||||
ynh_abort_if_errors
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
|
||||
|
||||
# definie useful vars
|
||||
parent_path=/var/www
|
||||
final_path="$parent_path"/"$app"
|
||||
data_path=/home/yunohost.app/"$app"
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/$app}.conf"
|
||||
|
||||
# check domain/path availability with app helper
|
||||
sudo yunohost app checkurl $domain$path -a $app \
|
||||
|| ynh_die "The path ${domain}${path} is not available for app installation."
|
||||
|
||||
# check directories availability
|
||||
[[ -d $final_path ]] && ynh_die \
|
||||
"The path '${final_path}' already exists.
|
||||
You should safely delete it before restoring this app."
|
||||
[[ -d $data_path ]] && ynh_die \
|
||||
"The path '${data_path}' already exists.
|
||||
You should safely delete it before restoring this app."
|
||||
|
||||
# check configuration files
|
||||
[[ -f $nginx_conf ]] && ynh_die \
|
||||
"The NGINX configuration already exists at '${nginx_conf}'.
|
||||
You should safely delete it before restoring this app."
|
||||
[[ -f $phpfpm_conf ]] && ynh_die \
|
||||
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
||||
You should safely delete it before restoring this app."
|
||||
# check domain/path availability
|
||||
ynh_webpath_available "$domain" "$path_url"
|
||||
ynh_webpath_register "$app" "$domain" "$path_url"
|
||||
myynh_check_path "$final_path"
|
||||
|
||||
# add required packages
|
||||
ynh_package_is_installed "php5-curl" || ynh_package_install "php5-curl"
|
||||
ynh_package_is_installed "php5-gd" || ynh_package_install "php5-gd"
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
|
||||
# restore sources & data
|
||||
sudo cp -a ./www "$final_path"
|
||||
sudo mkdir -p "$data_path"
|
||||
sudo cp -a ./data/. "$data_path"
|
||||
# create a dedicated system user
|
||||
ynh_system_user_create "$app"
|
||||
|
||||
# restore permissions
|
||||
sudo chown -R root: "$final_path"
|
||||
sudo find "$final_path" -type f | xargs sudo chmod 644
|
||||
sudo find "$final_path" -type d | xargs sudo chmod 755
|
||||
sudo chown -R www-data: "$final_path"/private
|
||||
sudo chown -R www-data: "$data_path"/uploads
|
||||
sudo chown -R www-data: "$data_path"/thumbs
|
||||
# restore sconf files
|
||||
ynh_restore_file "$nginx_conf"
|
||||
ynh_restore_file "$phpfpm_conf"
|
||||
|
||||
# restore Nginx & php-fpm
|
||||
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
||||
sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf"
|
||||
# restore source & their permissions
|
||||
ynh_restore_file "$final_path"
|
||||
sudo chown -R "$app": "$final_path"
|
||||
sudo chmod 755 "$final_path"
|
||||
|
||||
# Restart services
|
||||
sudo service php5-fpm restart || true
|
||||
sudo service nginx restart || true
|
||||
# restore data & their permissions only if there is no data
|
||||
if [ ! -d "$data_path" ]; then
|
||||
if [ $backup_core_only -eq 0 ]; then
|
||||
ynh_restore_file "$data_path"
|
||||
sudo chown -R "$app": "$data_path"
|
||||
else
|
||||
myynh_create_dir "$data_path/uploads"
|
||||
sudo chown -R "$app": "$data_path/uploads"
|
||||
myynh_create_dir "$data_path/thumbs"
|
||||
sudo chown -R "$app": "$data_path/thumbs"
|
||||
fi
|
||||
else
|
||||
echo "$data_path already exists and will not be overwritten" >&2
|
||||
fi
|
||||
|
||||
# restart services
|
||||
sudo systemctl reload php5-fpm
|
||||
sudo systemctl reload nginx
|
||||
|
|
142
scripts/upgrade
142
scripts/upgrade
|
@ -1,66 +1,106 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Exit on command errors and treat unset variables as an error
|
||||
set -eu
|
||||
|
||||
# Source YunoHost helpers
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# manage script failure
|
||||
ynh_abort_if_errors
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get "$app" domain)
|
||||
path=$(ynh_app_setting_get "$app" path)
|
||||
path_url=$(ynh_app_setting_get "$app" path)
|
||||
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||
filesize=$(ynh_app_setting_get "$app" filesize)
|
||||
language=$(ynh_app_setting_get "$app" language)
|
||||
admin_user=$(ynh_app_setting_get "$app" admin_user)
|
||||
backup_core_only=$(ynh_app_setting_get "$app" backup_core_only)
|
||||
|
||||
# definie useful vars
|
||||
parent_path=/var/www
|
||||
data_path=/home/yunohost.app/"$app"
|
||||
final_path=$parent_path/"$app"
|
||||
if [ -z "$filesize" ]
|
||||
then # in old script filesize was not saved as an setting
|
||||
filesize=$(cat /etc/nginx/conf.d/"$domain".d/"$app".conf | grep -Po 'client_max_body_size \K.*(?=;)')
|
||||
final_path="/var/www/$app"
|
||||
data_path="/home/yunohost.app/$app"
|
||||
bozon_conf="$final_path/config.php"
|
||||
nginx_conf="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/$app.conf"
|
||||
|
||||
# use prior backup and restore on error only if backup feature exists on installed instance
|
||||
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
|
||||
ynh_backup_before_upgrade # Backup the current version of the app
|
||||
ynh_clean_setup () {
|
||||
ynh_backup_after_failed_upgrade
|
||||
}
|
||||
fi
|
||||
|
||||
# retrieve & save real/right value if argument was not saved as a app setting in a previous realease
|
||||
if [ -z "$filesize" ]; then # in old script filesize was not saved as a setting
|
||||
filesize=$(cat "$nginx_conf" | grep -Po "client_max_body_size \K.*?(?=;)")
|
||||
ynh_app_setting_set "$app" filesize "$filesize"
|
||||
fi
|
||||
|
||||
# download upstream_version version of bozon
|
||||
upstream_version=$(cat ../conf/upstream_version)
|
||||
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
|
||||
sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
|
||||
sudo rsync -avz --exclude="config.php" --exclude=".htaccess" /tmp/BoZoN-"$upstream_version"/* "$final_path"
|
||||
|
||||
# configure nginx settings
|
||||
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||
sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
|
||||
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
|
||||
sudo cp ../conf/nginx.conf "$nginx_conf"
|
||||
|
||||
# copy and set php-fpm configuration
|
||||
postsize=${filesize%?}.1${filesize: -1}
|
||||
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
||||
sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/php-fpm.conf
|
||||
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
|
||||
sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
|
||||
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
|
||||
## copy final and set permissions
|
||||
sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
|
||||
sudo chown root: "$phpfpm_conf"
|
||||
sudo chmod 644 "$phpfpm_conf"
|
||||
|
||||
# if app is private, remove url to SSOWat conf from skipped_uris
|
||||
if [ "$is_public" = "No" ];
|
||||
then
|
||||
ynh_app_setting_delete "$app" unprotected_uris
|
||||
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
|
||||
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
regexList="${domainluaregex}${pathluaregex}/index.php%?f=.+$","${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$","${domainluaregex}${pathluaregex}/private/temp/.+%.zip$","${domainluaregex}${pathluaregex}/core/js/.*$","${domainluaregex}${pathluaregex}/templates/.*$"
|
||||
ynh_app_setting_set "$app" unprotected_regex "$regexList"
|
||||
sudo yunohost app ssowatconf
|
||||
if [ -z "$language" ]; then # in old script language was not saved as a setting
|
||||
language=$(cat "$bozon_conf" | grep -Po "default_language='\K.*?(?=')")
|
||||
ynh_app_setting_set "$app" language "$language"
|
||||
fi
|
||||
if [ "$is_public" = "Yes" ]; then # in old script is_public was not a boolean
|
||||
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 [ -z "$backup_core_only" ]; then # in old script backup_core_only was not a setting
|
||||
ynh_app_setting_set "$app" backup_core_only 1
|
||||
fi
|
||||
|
||||
# Restart services
|
||||
sudo service php5-fpm restart || true
|
||||
sudo service nginx reload || true
|
||||
# add required packages
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
|
||||
# create a dedicated system user
|
||||
ynh_system_user_create "$app"
|
||||
|
||||
# download & unpack bozon
|
||||
TMPDIR=$(mktemp -d)
|
||||
ynh_setup_source "$TMPDIR"
|
||||
|
||||
# clean & copy files needed to final folder
|
||||
sudo find "$TMPDIR" -type f -name ".htaccess" | xargs sudo rm
|
||||
if [ -e "$TMPDIR/.gitignore" ]; then
|
||||
for f in $(sudo cat "$TMPDIR/.gitignore") ; do
|
||||
[ -e "$TMPDIR$f" ] && sudo rm -R "$TMPDIR$f"
|
||||
done
|
||||
sudo rm "$TMPDIR/.gitignore"
|
||||
fi
|
||||
[ -e "$TMPDIR/config.php" ] && sudo rm "$TMPDIR/config.php"
|
||||
sudo cp -a "$TMPDIR/." "$final_path"
|
||||
sudo rm -R "$TMPDIR"
|
||||
|
||||
# set permissions
|
||||
sudo find "$final_path" -type f | xargs sudo chmod 0640
|
||||
sudo find "$final_path" -type d | xargs sudo chmod 0750
|
||||
sudo find "$data_path" -type f | xargs sudo chmod 0640
|
||||
sudo find "$data_path" -type d | xargs sudo chmod 0750
|
||||
sudo chown -R "$app": "$final_path/private"
|
||||
sudo chown -R "$app": "$data_path/uploads"
|
||||
sudo chown -R "$app": "$data_path/thumbs"
|
||||
|
||||
# configure nginx settings
|
||||
myynh_add_nginx_config
|
||||
|
||||
# copy and set php-fpm configuration
|
||||
myynh_add_fpm_config
|
||||
|
||||
# if app is private, remove url to SSOWat conf from skipped_uris
|
||||
if [ $is_public -eq 0 ]
|
||||
then
|
||||
ynh_app_setting_delete "$app" unprotected_regex # in old script unprotected_regex was used in place of protected_regex
|
||||
# escape magic chars in vars (lua magic chars are ().%+-*?[^$ according to https://www.lua.org/pil/20.2.html)
|
||||
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
pathluaregex=$([ "$path_url" == "/" ] || echo "$path_url" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
|
||||
regexList="${domainluaregex}${pathluaregex}/index%.php$","${domainluaregex}${pathluaregex}/index%.php%?p=.*$"
|
||||
ynh_app_setting_set "$app" protected_regex "$regexList"
|
||||
else
|
||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||
fi
|
||||
sudo yunohost app ssowatconf
|
||||
|
||||
# Purge php sessions stored in /var/lib/php5/sessions
|
||||
[ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean
|
||||
|
|
Loading…
Reference in a new issue