1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dotclear2_ynh.git synced 2024-09-03 18:26:29 +02:00

fix package_linter, and add helpers

This commit is contained in:
Kayou 2019-02-09 23:46:07 +01:00
parent e2fcefbdfe
commit a17bdd4840
No known key found for this signature in database
GPG key ID: 823A2CBE071D3126
5 changed files with 93 additions and 14 deletions

65
scripts/_common.sh Normal file
View file

@ -0,0 +1,65 @@
# Curl abstraction to help with POST requests to local pages (such as installation forms)
#
# $domain and $path_url should be defined externally (and correspond to the domain.tld and the /path (of the app?))
#
# example: ynh_local_curl "/install.php?installButton" "foo=$var1" "bar=$var2"
#
# usage: ynh_local_curl "page_uri" "key1=value1" "key2=value2" ...
# | arg: page_uri - Path (relative to $path_url) of the page where POST data will be sent
# | arg: key1=value1 - (Optionnal) POST key and corresponding value
# | arg: key2=value2 - (Optionnal) Another POST key and corresponding value
# | arg: ... - (Optionnal) More POST keys and values
ynh_local_curl () {
# Define url of page to curl
path_url=$(ynh_normalize_url_path $path_url)
local local_page=$(ynh_normalize_url_path $1)
local full_path=$path_url$local_page
if [ "${path_url}" == "/" ]; then
full_path=$local_page
fi
local full_page_url=https://localhost$full_path
# Concatenate all other arguments with '&' to prepare POST data
local POST_data=""
local arg=""
for arg in "${@:2}"
do
POST_data="${POST_data}${arg}&"
done
if [ -n "$POST_data" ]
then
# Add --data arg and remove the last character, which is an unecessary '&'
POST_data="--data ${POST_data::-1}"
fi
# Wait untils nginx has fully reloaded (avoid curl fail with http2)
sleep 2
# Curl the URL
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
}
ynh_url_join() {
if [ "$#" -eq 0 ]; then
ynh_die "Illegal number of parameters"
fi
local full_url=""
for var in "$@"
do
if [ "${var:0:1}" != "/" ]; then # If the first character is not a /
var="/$var" # Add / at begin of path variable
fi
if [ "${var:${#var}-1}" == "/" ]; then # If the last character is a /
var="${var:0:${#var}-1}" # Delete the last character
fi
full_url=${full_url}${var}
done
full_url=$(ynh_normalize_url_path $full_url)
echo $full_url
}

View file

@ -6,8 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source ../settings/scripts/_common.sh
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE

View file

@ -6,8 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE
@ -98,16 +98,34 @@ ynh_add_fpm_config
php_config=$final_path/inc/config.php php_config=$final_path/inc/config.php
master_key=$(dd if=/dev/urandom bs=1 count=200 2>/dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') master_key=$(dd if=/dev/urandom bs=1 count=200 2>/dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
firstname=$(sudo yunohost user info $admin | grep firstname: | cut -d' ' -f2 | tr -d '\n') firstname=$(yunohost user info $admin | grep firstname: | cut -d' ' -f2 | tr -d '\n')
lastname=$(sudo yunohost user info $admin | grep lastname: | cut -d' ' -f2 | tr -d '\n') lastname=$(yunohost user info $admin | grep lastname: | cut -d' ' -f2 | tr -d '\n')
email=$(sudo yunohost user info $admin | grep mail: | cut -d' ' -f2 | tr -d '\n') email=$(yunohost user info $admin | grep mail: | cut -d' ' -f2 | tr -d '\n')
timezone=$(cat /etc/timezone | tr -d '\n') timezone=$(cat /etc/timezone | tr -d '\n')
sudo cp $php_config.in $php_config cp $php_config.in $php_config
admin_url=$(ynh_url_join $path_url admin/index.php)
# Config as if we called in admin/install/wizard.php # Config as if we called in admin/install/wizard.php
sudo sed -i -e "s;'DC_DBDRIVER', '';'DC_DBDRIVER', 'mysqli';" -e "s;'DC_DBHOST', '';'DC_DBHOST', 'localhost';" -e "s;'DC_DBUSER', '';'DC_DBUSER', '$app';" -e "s;'DC_DBPASSWORD', '';'DC_DBPASSWORD', '$db_pwd';" -e "s;'DC_DBNAME', '';'DC_DBNAME', '$db_name';" -e "s;'DC_MASTER_KEY', '';'DC_MASTER_KEY', '$master_key';" -e "s;'DC_ADMIN_URL', '';'DC_ADMIN_URL', 'https://$domain$path_url/admin/index.php';" -e "s;'DC_ADMIN_MAILFROM', '';'DC_ADMIN_MAILFROM', '$email';" $php_config ynh_replace_string "'DC_DBDRIVER', ''" "'DC_DBDRIVER', 'mysqli'" $php_config
# Modify Nginx configuration file and copy it to Nginx conf directory ynh_replace_string "'DC_DBHOST', ''" "'DC_DBHOST', 'localhost'" $php_config
ynh_replace_string "'DC_DBUSER', ''" "'DC_DBUSER', '$app'" $php_config
ynh_replace_string "'DC_DBPASSWORD', ''" "'DC_DBPASSWORD', '$db_pwd'" $php_config
ynh_replace_string "'DC_DBNAME', ''" "'DC_DBNAME', '$db_name'" $php_config
ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_config
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
# Config as if we called in admin/install/wizard.php
ynh_replace_string "'DC_DBDRIVER', ''" "'DC_DBDRIVER', 'mysqli'" $php_config
ynh_replace_string "'DC_DBHOST', ''" "'DC_DBHOST', 'localhost'" $php_config
ynh_replace_string "'DC_DBUSER', ''" "'DC_DBUSER', '$app'" $php_config
ynh_replace_string "'DC_DBPASSWORD', ''" "'DC_DBPASSWORD', '$db_pwd'" $php_config
ynh_replace_string "'DC_DBNAME', ''" "'DC_DBNAME', '$db_name'" $php_config
ynh_replace_string "'DC_MASTER_KEY', ''" "'DC_MASTER_KEY', '$master_key'" $php_config
ynh_replace_string "'DC_ADMIN_URL', ''" "'DC_ADMIN_URL', 'https://$domain$admin_url'" $php_config
ynh_replace_string "'DC_ADMIN_MAILFROM', ''" "'DC_ADMIN_MAILFROM', '$email'" $php_config
#================================================= #=================================================
# SETUP APPLICATION WITH CURL # SETUP APPLICATION WITH CURL
@ -128,10 +146,6 @@ systemctl reload nginx
# Installation with curl # Installation with curl
installUrl="/admin/install/index.php" installUrl="/admin/install/index.php"
if [ "$path_url" = "/" ]; then
installUrl="admin/install/index.php" # Fix if app is in the root domain
fi
ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password" ynh_local_curl $installUrl "u_email=$email" "u_firstname=$firstname" "u_name=$lastname" "u_login=$admin" "u_pwd=$password" "u_pwd2=$password"
ynh_app_setting_delete $app skipped_uris ynh_app_setting_delete $app skipped_uris

View file

@ -6,8 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source _common.sh
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS

View file

@ -6,8 +6,8 @@
# IMPORT GENERIC HELPERS # IMPORT GENERIC HELPERS
#================================================= #=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
source ../settings/scripts/_common.sh
#================================================= #=================================================
# MANAGE SCRIPT FAILURE # MANAGE SCRIPT FAILURE