1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/bozon_ynh.git synced 2024-09-03 18:16:09 +02:00
This commit is contained in:
ewilly 2016-10-11 20:16:36 +02:00
parent 5855b6e1f1
commit 047890be3b
5 changed files with 110 additions and 171 deletions

View file

@ -12,8 +12,8 @@ domain=$(ynh_app_setting_get "$app" domain)
# definie useful vars # definie useful vars
parent_path=/var/www parent_path=/var/www
final_path=$parent_path/$app final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/$app data_path=/home/yunohost.app/"$app"
# backup sources & data # backup sources & data
ynh_backup "$final_path" "www" ynh_backup "$final_path" "www"

View file

@ -6,71 +6,26 @@ set -eu
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
# retrieve arguments # retrieve arguments
if [ $ynh_version = "2.4" ]; then app=bozon
app=$YNH_APP_INSTANCE_NAME domain=$1
domain=$YNH_APP_ARG_DOMAIN path=${2%/}
path=$YNH_APP_ARG_PATH is_public=$3
is_public=$YNH_APP_ARG_IS_PUBLIC language=$4
language=$YNH_APP_ARG_LANGUAGE filesize=$5
filesize=$YNH_APP_ARG_FILESIZE admin=$6
admin=$YNH_APP_ARG_ADMIN password=$7
password=$YNH_APP_ARG_PASSWORD
else
app=bozon
domain=$1
path=$2
is_public=$3
language=$4
filesize=$5
admin=$6
password=$7
fi
# Delete files and db if exit with an error
EXIT_PROPERLY () {
trap '' ERR
echo -e "\e[91m \e[1m" # Shell in light red bold
echo -e "!!\n $app install's script has encountered an error. Installation was cancelled.\n!!"
if [ $ynh_version = "2.2" ]; then
/bin/bash ./remove # Appel le script remove. En 2.2, ce comportement n'est pas automatique.s
fi
exit 1
}
TRAP_ON () { # Activate signal capture
trap EXIT_PROPERLY ERR # Capturing exit signals on error
}
TRAP_OFF () { # Ignoring signal capture until TRAP_ON
# Pour une raison que j'ignore, la fonction TRAP_ON fonctionne très bien.
# Mais pas la fonction TRAP_OFF...
# Utiliser directement `trap '' ERR` dans le code pour l'utiliser, à la place de la fonction.
trap '' ERR # Ignoring exit signals
}
TRAP_ON
# definie useful vars # definie useful vars
parent_path=/var/www parent_path=/var/www
final_path=$parent_path/$app final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/$app data_path=/home/yunohost.app/"$app"
# remove trailing slash
[ "$path" != "/" ] && path=${path%/}
# check domain/path availability # check domain/path availability
sudo yunohost app checkurl $domain$path -a $app sudo yunohost app checkurl "${domain}${path}" -a "$app" || ynh_die "The path ${domain}${path} is not available for app installation."
if [[ ! $? -eq 0 ]]; then
touch /force_stop
fi
# check that admin user is an existing account # check that admin user is an existing account
sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" ynh_user_exists "$admin" || ynh_die "The chosen admin user does not exist."
if [[ ! $? -eq 0 ]]; then
echo "Error : the chosen admin user does not exist"
touch /force_stop
fi
# add required packages # add required packages
ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable to install dependencies" ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable to install dependencies"
@ -79,75 +34,71 @@ ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable t
upstream_version=$(cat ../conf/upstream_version) upstream_version=$(cat ../conf/upstream_version)
# save app settings # save app settings
sudo yunohost app setting $app admin_user -v "$admin" ynh_app_setting_set "$app" admin_user "$admin"
sudo yunohost app setting $app is_public -v "$is_public" ynh_app_setting_set "$app" is_public "$is_public"
sudo yunohost app setting $app domain -v "$domain" ynh_app_setting_set "$app" domain "$domain"
sudo yunohost app setting $app path -v "$path" ynh_app_setting_set "$app" path "$path"
sudo yunohost app setting $app version -v "$upstream_version" ynh_app_setting_set "$app" version "$upstream_version"
sudo yunohost app setting $app filesize -v "$filesize" ynh_app_setting_set "$app" filesize "$filesize"
# download upstream_version version of bozon # download upstream_version version of bozon
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/$upstream_version.zip -P /tmp wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
sudo unzip -oq /tmp/$upstream_version.zip -d /tmp sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
sudo mv /tmp/$upstream_version $parent_path/$app sudo mv /tmp/"$upstream_version" "$parent_path"/"$app"
# copy files to final folder and set permissions # copy files to final folder and set permissions
sudo find $final_path -type f -name ".htaccess" | xargs sudo rm sudo find "$final_path" -type f -name ".htaccess" | xargs sudo rm
sudo chown -R root: $final_path sudo chown -R root: "$final_path"
sudo find $final_path -type f | xargs sudo chmod 644 sudo find "$final_path" -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755 sudo find "$final_path" -type d | xargs sudo chmod 755
# configure config file # configure config file
sudo sed -i "s@languageuage='en';@languageuage='$language';@g" $final_path/config.php sudo sed -i "s@languageuage='en';@languageuage='$language';@g" $final_path/config.php
# create data folders # create data folders
sudo mkdir -p $final_path/private sudo mkdir -p "$final_path"/private
sudo mkdir -p $data_path/uploads sudo mkdir -p "$data_path"/uploads
sudo ln -s $data_path/uploads $final_path/uploads sudo ln -s "$data_path"/uploads "$final_path"/uploads
sudo mkdir -p $data_path/thumbs sudo mkdir -p "$data_path"/thumbs
sudo ln -s $data_path/thumbs $final_path/thumbs sudo ln -s "$data_path"/thumbs "$final_path"/thumbs
sudo chown -R www-data: $final_path/private sudo chown -R www-data: "$final_path"/private
sudo chown -R www-data: $data_path/uploads sudo chown -R www-data: "$data_path"/uploads
sudo chown -R www-data: $data_path/thumbs sudo chown -R www-data: "$data_path"/thumbs
# configure nginx settings # configure nginx settings
## path nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
## file upload size limit sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf"
## copy final
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# copy and set php-fpm configuration # copy and set php-fpm configuration
## path 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_APP@${app}@g" ../conf/php-fpm.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
## file upload size limit sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
postsize=${filesize%?}.1${filesize: -1}
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions ## copy final and set permissions
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sudo cp ../conf/php-fpm.conf "$phpfpm_conf" sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf sudo chown root: "$phpfpm_conf"
sudo chmod 644 $phpfpm_conf sudo chmod 644 "$phpfpm_conf"
# create the superadmin # create the superadmin
## set temporary public access ## set temporary public access
sudo yunohost app setting $app unprotected_uris -v "/" ynh_app_setting_set "$app" unprotected_uris "/"
## start app ## start app
sudo service nginx reload sudo service nginx reload
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
## fill the superadmin creation form ## fill the superadmin creation form
curl_path=$([ "$path" == "/" ] || echo $path) curl_path=$([ "$path" == "/" ] || echo "$path")
curl -k -X POST \ curl -k -X POST \
--data-urlencode creation="1" \ --data-urlencode creation="1" \
--data-urlencode login="$admin" \ --data-urlencode login="$admin" \
--data-urlencode pass="$password" \ --data-urlencode pass="$password" \
--data-urlencode confirm="$password" \ --data-urlencode confirm="$password" \
https://$domain$curl_path/index.php?p=admin > /dev/null 2>&1 https://"$domain""$curl_path"/index.php?p=admin > /dev/null 2>&1
# if app is private, remove url to SSOWat conf from skipped_uris # if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ]; if [ "$is_public" = "No" ];
@ -156,8 +107,13 @@ then
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
# redirect to SSOwat login in # redirect to SSOwat login in
sudo yunohost app setting $app unprotected_uris -d ynh_app_setting_delete "$app" unprotected_uris
sudo yunohost app setting $app unprotected_regex -v "$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 \
"${domainluaregex}${pathluaregex}/index.php%?f=.+$", \
"${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$", \
"${domainluaregex}${pathluaregex}/private/temp/.+%.zip$", \
"${domainluaregex}${pathluaregex}/core/js/.*$", \
"${domainluaregex}${pathluaregex}/templates/.*$"
fi fi
# restart services # restart services

View file

@ -6,33 +6,25 @@ set -eu
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
#retrieve arguments #retrieve arguments
if [ $ynh_version = "2.4" ]; then app=$YNH_APP_INSTANCE_NAME
app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "${app}" domain)
# Source app helpers
. /usr/share/yunohost/helpers
else
app=bozon
fi
domain=$(sudo yunohost app setting $app domain)
if [ -e "/var/www/$app" ]; then if [ -e "/var/www/${app}" ]; then
echo "Delete app" echo "Delete app"
sudo rm -rf /var/www/$app sudo rm -rf /var/www/${app}
fi fi
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then if [ -e "/etc/nginx/conf.d/${domain}.d/${app}.conf" ]; then
echo "Delete Nginx config" echo "Delete Nginx config"
sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo rm -f /etc/nginx/conf.d/${domain}.d/${app}.conf
fi fi
if [ -e "/etc/php5/fpm/pool.d/$app.conf" ]; then if [ -e "/etc/php5/fpm/pool.d/${app}.conf" ]; then
echo "Delete fpm config" echo "Delete fpm config"
sudo rm -f /etc/php5/fpm/pool.d/$app.conf sudo rm -f /etc/php5/fpm/pool.d/${app}.conf
fi fi
if [ -e "/home/yunohost.app/$app" ]; then if [ -e "/home/yunohost.app/${app}" ]; then
echo "Delete datas" echo "Delete datas"
sudo rm -rf /home/yunohost.app/$app sudo rm -rf /home/yunohost.app/${app}
fi fi
# Remove app dependencies # Remove app dependencies
@ -42,5 +34,3 @@ ynh_package_autoremove "${app}-deps" || true
sudo service php5-fpm restart || true sudo service php5-fpm restart || true
sudo service nginx restart || true sudo service nginx restart || true
sudo yunohost app ssowatconf sudo yunohost app ssowatconf
echo -e "\e[0m"

View file

@ -12,8 +12,8 @@ domain=$(ynh_app_setting_get "$app" domain)
# definie useful vars # definie useful vars
parent_path=/var/www parent_path=/var/www
final_path=$parent_path/$app final_path="$parent_path"/"$app"
data_path=/home/yunohost.app/$app data_path=/home/yunohost.app/"$app"
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
@ -46,12 +46,12 @@ sudo mkdir -p "$data_path"
sudo cp -a ./data/. "$data_path" sudo cp -a ./data/. "$data_path"
# restore permissions # restore permissions
sudo chown -R root: $final_path sudo chown -R root: "$final_path"
sudo find $final_path -type f | xargs sudo chmod 644 sudo find "$final_path" -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755 sudo find "$final_path" -type d | xargs sudo chmod 755
sudo chown -R www-data: $final_path/private sudo chown -R www-data: "$final_path"/private
sudo chown -R www-data: $data_path/uploads sudo chown -R www-data: "$data_path"/uploads
sudo chown -R www-data: $data_path/thumbs sudo chown -R www-data: "$data_path"/thumbs
# restore Nginx & php-fpm # restore Nginx & php-fpm
sudo cp -a ./conf/nginx.conf "$nginx_conf" sudo cp -a ./conf/nginx.conf "$nginx_conf"

View file

@ -6,68 +6,56 @@ set -eu
# Source YunoHost helpers # Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
ynh_version=$(sudo yunohost -v | grep "moulinette:" | cut -d' ' -f2 | cut -d'.' -f1,2)
# retrieve arguments # retrieve arguments
if [ $ynh_version = "2.4" ]; then app=$YNH_APP_INSTANCE_NAME
app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain)
else path=$(ynh_app_setting_get "$app" path)
app=bozon is_public=$(ynh_app_setting_get "$app" is_public)
fi filesize=$(ynh_app_setting_get "$app" filesize)
path=$(sudo yunohost app setting $app path)
upstream_version=$(sudo yunohost app setting $app version)
is_public=$(sudo yunohost app setting $app is_public)
filesize=$(sudo yunohost app setting $app filesize)
domain=$(sudo yunohost app setting $app domain)
if [ "${#filesize}" -eq 0 ]
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.*(?=;)')
sudo yunohost app setting $app filesize -v "$filesize"
fi
# definie useful vars # definie useful vars
parent_path=/var/www parent_path=/var/www
data_path=/home/yunohost.app/$app data_path=/home/yunohost.app/"$app"
final_path=$parent_path/$app final_path=$parent_path/"$app"
if [ ${filesize} -eq 0 ]
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.*(?=;)')
ynh_app_setting_set "$app" filesize "$filesize"
fi
# add required packages # add required packages
ynh_package_install_from_equivs ../conf/${app}-deps.control || ynh_die "Unable to install dependencies" ynh_package_install_from_equivs ../conf/"$app"-deps.control || ynh_die "Unable to install dependencies"
# retrieve upstream_version version of bozon # retrieve upstream_version version of bozon
upstream_version=$(cat ../conf/upstream_version) upstream_version=$(cat ../conf/upstream_version)
# save app settings # save app settings
sudo yunohost app setting $app version -v "$upstream_version" ynh_app_setting_set "$app" version "$upstream_version"
# download upstream_version version of bozon # download upstream_version version of bozon
wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/$upstream_version.zip -P /tmp wget -nc --quiet https://github.com/broncowdd/BoZoN/archive/"$upstream_version".zip -P /tmp
sudo unzip -oq /tmp/$upstream_version.zip -d /tmp sudo unzip -oq /tmp/"$upstream_version".zip -d /tmp
sudo rsync -avz --exclude="config.php" --exclude=".htaccess" /tmp/$upstream_version/* $final_path sudo rsync -avz --exclude="config.php" --exclude=".htaccess" /tmp/"$upstream_version"/* "$final_path"
# configure nginx settings # configure nginx settings
## path nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
folder_path=${path%/} sed -i "s@YNH_EXAMPLE_PATH@${path}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$final_path@g" ../conf/nginx.conf sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf
sudo sed -i "s@YNH_EXAMPLE_APP@${app}@g" ../conf/nginx.conf sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
## file upload size limit sudo cp ../conf/nginx.conf "$nginx_conf"
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/nginx.conf
## copy final
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# copy and set php-fpm configuration # copy and set php-fpm configuration
## path 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_APP@${app}@g" ../conf/php-fpm.conf
sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf sed -i "s@YNH_EXAMPLE_ALIAS@${final_path}@g" ../conf/php-fpm.conf
## file upload size limit sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
sudo sed -i "s@YNH_FILE_SIZE@${filesize}@g" ../conf/php-fpm.conf
postsize=${filesize%?}.1${filesize: -1}
sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf sudo sed -i "s@YNH_POST_SIZE@${postsize}@g" ../conf/php-fpm.conf
## copy final and set permissions ## copy final and set permissions
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
sudo cp ../conf/php-fpm.conf "$phpfpm_conf" sudo cp ../conf/php-fpm.conf "$phpfpm_conf"
sudo chown root: $phpfpm_conf sudo chown root: "$phpfpm_conf"
sudo chmod 644 $phpfpm_conf sudo chmod 644 "$phpfpm_conf"
# if app is private, remove url to SSOWat conf from skipped_uris # if app is private, remove url to SSOWat conf from skipped_uris
if [ "$is_public" = "No" ]; if [ "$is_public" = "No" ];
@ -76,8 +64,13 @@ then
domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') domainluaregex=$(echo "$domain" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g') pathluaregex=$(echo "$path" | sed -e 's/[]().%+*?[^$[]/\%&/g' | sed -e 's/\-/\%&/g')
# redirect to SSOwat login in # redirect to SSOwat login in
sudo yunohost app setting $app unprotected_uris -d ynh_app_setting_delete "$app" unprotected_uris
sudo yunohost app setting $app unprotected_regex -v "$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 \
"${domainluaregex}${pathluaregex}/index.php%?f=.+$", \
"${domainluaregex}${pathluaregex}/index.php%?zipfolder=.+$", \
"${domainluaregex}${pathluaregex}/private/temp/.+%.zip$", \
"${domainluaregex}${pathluaregex}/core/js/.*$", \
"${domainluaregex}${pathluaregex}/templates/.*$"
fi fi
# Restart services # Restart services