1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dolibarr_ynh.git synced 2024-09-03 18:35:53 +02:00

Improve curl

This commit is contained in:
scith 2017-05-18 20:42:22 +02:00
parent a58021a7e8
commit 14185aabdc
3 changed files with 74 additions and 8 deletions

30
scripts/_extrahelpers Normal file
View file

@ -0,0 +1,30 @@
# 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
full_page_url=https://localhost$path$1
# Concatenate all other arguments with '&' to prepare POST data
POST_data=""
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
# Curl the URL
curl --silent --show-error -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 $POST_data "$full_page_url"
}

View file

@ -6,6 +6,7 @@ version=$(cat ../sources/version)
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_extrahelpers
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
@ -42,6 +43,7 @@ version=$(cat ../sources/version)
sudo wget -q https://github.com/Dolibarr/dolibarr/archive/${version}.zip -O dolibarr-${version}.zip
sudo unzip -qq dolibarr-${version}.zip
sudo cp -a dolibarr-${version}/. $src_path
# Create necessary files
sudo touch $src_path/htdocs/conf/conf.php
sudo mkdir -p $src_path/documents
@ -99,11 +101,31 @@ version=$(cat ../sources/version)
password=$(ynh_string_random 8)
# Install with CURL
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/fileconf.php" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/step1.php" --data "testpost=ok&action=set&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/step2.php" --data "testpost=ok&action=set&dolibarr_main_db_character_set=latin1&dolibarr_main_db_collation=latin1_swedish_ci&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/step4.php" --data "testpost=ok&action=set&selectlang=fr_FR" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/step5.php" --data "testpost=ok&action=set&selectlang=fr_FR&pass=$password&pass_verif=$password" > /dev/null 2>&1
ynh_local_curl "/install/fileconf.php"
ynh_local_curl "/install/step1.php" \
"testpost=ok" \
"action=set" \
"selectlang=fr_FR"
ynh_local_curl "/install/step2.php" \
"testpost=ok" \
"action=set" \
"dolibarr_main_db_character_set=latin1" \
"dolibarr_main_db_collation=latin1_swedish_ci" \
"selectlang=fr_FR"
ynh_local_curl "/install/step4.php" \
"testpost=ok" \
"action=set" \
"selectlang=fr_FR"
ynh_local_curl "/install/step5.php" \
"testpost=ok" \
"action=set" \
"selectlang=fr_FR" \
"pass=$password" \
"pass_verif=$password"
# Populate the LDAP parameters
mysql -u ${dbuser} -p${dbpass} ${dbname} < ../conf/ldap.sql

View file

@ -8,6 +8,7 @@ version=$(cat ../sources/version)
# Source YunoHost helpers
source /usr/share/yunohost/helpers
source ./_extrahelpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
@ -54,9 +55,22 @@ version=$(cat ../sources/version)
[[ -f $lock ]] && sudo rm $lock
# Upgrade with CURL
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 "https://$domain$path/install/upgrade.php?action=upgrade&versionfrom=$old_version&versionto=$version" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/upgrade2.php?versionfrom=$old_version&versionto=$version" --data "testpost=ok&action=upgrade" > /dev/null 2>&1
curl -kL -H "Host: $domain" --resolve $domain:443:127.0.0.1 -X POST "https://$domain$path/install/step5.php?versionfrom=$old_version&versionto=$version" --data "testpost=ok&action=upgrade" > /dev/null 2>&1
ynh_local_curl "/install/upgrade.php" \
"action=upgrade" \
"versionfrom=$old_version" \
"versionto=$version"
ynh_local_curl "/install/upgrade2.php" \
"versionfrom=$old_version" \
"versionto=$version" \
"testpost=ok" \
"action=upgrade"
ynh_local_curl "/install/step5.php" \
"versionfrom=$old_version" \
"versionto=$version" \
"testpost=ok" \
"action=upgrade"
# Recreate the lock
sudo touch $lock