2016-06-14 12:25:46 +02:00
|
|
|
#!/bin/bash
|
2014-11-12 22:22:53 +01:00
|
|
|
|
|
|
|
app=pluxml
|
|
|
|
|
|
|
|
#retrieve arguments
|
|
|
|
domain=$1
|
|
|
|
path=$2
|
|
|
|
admin=$3
|
2014-11-13 21:54:54 +01:00
|
|
|
password=$4
|
|
|
|
is_public=$5
|
2014-11-13 22:06:51 +01:00
|
|
|
default_lang=$6
|
2014-11-12 22:22:53 +01:00
|
|
|
|
2015-08-18 09:29:41 +02:00
|
|
|
# Remove trailing slash
|
|
|
|
[ "$path" != "/" ] && path=${path%/}
|
|
|
|
|
2014-11-12 22:22:53 +01:00
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2014-11-17 14:04:17 +01:00
|
|
|
exit 1
|
2014-11-12 22:22:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check user
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2016-06-14 12:55:55 +02:00
|
|
|
echo "Wrong user" && exit 1
|
2014-11-12 22:22:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Save app settings
|
|
|
|
sudo yunohost app setting $app admin -v "$admin"
|
|
|
|
sudo yunohost app setting $app is_public -v "$is_public"
|
2014-11-12 22:42:09 +01:00
|
|
|
sudo yunohost app setting $app domain -v "$domain"
|
|
|
|
sudo yunohost app setting $app path -v "$path"
|
2014-11-12 22:22:53 +01:00
|
|
|
|
|
|
|
#create path for copying
|
2016-06-15 20:17:31 +02:00
|
|
|
src_path=/var/www/$app
|
|
|
|
sudo mkdir -p $src_path
|
2014-11-12 22:22:53 +01:00
|
|
|
|
2016-06-15 21:10:02 +02:00
|
|
|
# Retrieve sources and install them
|
|
|
|
version=$(cat ../conf/upstream_version)
|
|
|
|
wget -nc --quiet https://github.com/pluxml/PluXml/archive/$version.zip -P /tmp
|
|
|
|
sudo unzip -q /tmp/$version.zip
|
|
|
|
sudo mv PluXml-$version/* $src_path
|
2016-06-15 20:17:31 +02:00
|
|
|
sudo find $src_path -type f -name ".htaccess" | xargs sudo rm
|
2014-11-17 16:05:08 +01:00
|
|
|
|
|
|
|
#setup permissions
|
2016-06-15 20:17:31 +02:00
|
|
|
sudo chown -R root: $src_path
|
2016-06-15 20:54:03 +02:00
|
|
|
sudo chown -R www-data: $src_path/data
|
|
|
|
sudo chown -R www-data: $src_path/plugins
|
2016-06-15 20:17:31 +02:00
|
|
|
sudo find $src_path -type f | xargs sudo chmod 644
|
|
|
|
sudo find $src_path -type d | xargs sudo chmod 755
|
2014-11-12 22:22:53 +01:00
|
|
|
|
|
|
|
#configure nginx settings
|
2015-08-18 09:29:41 +02:00
|
|
|
folder_path=${path%/}
|
2014-11-12 22:22:53 +01:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
2015-08-18 09:29:41 +02:00
|
|
|
# If path is only / (without subfolder), add trailing slash to alias
|
2016-06-15 20:17:31 +02:00
|
|
|
alias_path=$src_path
|
2016-06-15 20:25:51 +02:00
|
|
|
nginx_conf="../conf/nginx.conf"
|
2015-08-18 09:29:41 +02:00
|
|
|
[ "$path" == '/' ] && alias_path=$alias_path'/'
|
2016-06-15 20:25:51 +02:00
|
|
|
sudo sed -i "s@YNH_EXAMPLE_ALIAS@$alias_path@g" $nginx_conf
|
|
|
|
sudo sed -i "s@YNH_EXAMPLE_FOLDER@$folder_path@g" $nginx_conf
|
|
|
|
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2014-11-12 22:22:53 +01:00
|
|
|
|
2014-11-17 16:05:08 +01:00
|
|
|
#temporary set public accessible
|
2014-11-12 22:42:09 +01:00
|
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
2014-11-13 19:34:55 +01:00
|
|
|
|
2016-06-14 12:55:55 +02:00
|
|
|
# Reload services
|
2014-11-13 21:50:18 +01:00
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|
|
|
|
|
2014-11-23 17:30:50 +01:00
|
|
|
#temporary add domain name to /etc/hosts
|
|
|
|
sudo sed -i "1 i\127.0.0.1 $domain #pluxml_hosts" /etc/hosts
|
|
|
|
|
2014-11-13 19:34:55 +01:00
|
|
|
#make request to install app
|
2014-11-12 22:42:09 +01:00
|
|
|
#get the html page
|
2015-08-18 09:29:41 +02:00
|
|
|
curl_path=$([ "$path" == "/" ] || echo $path)
|
|
|
|
curl -kL -o install_page.html https://$domain$curl_path/install.php >/dev/null 2>&1
|
2014-11-23 17:30:50 +01:00
|
|
|
|
|
|
|
|
2014-11-12 22:42:09 +01:00
|
|
|
#get the token for form validation
|
2014-11-17 15:01:27 +01:00
|
|
|
token=$(cat install_page.html | grep "input" | grep "token" | tail -1 | cut -d' ' -f3 | cut -d'"' -f2)
|
2014-11-12 22:42:09 +01:00
|
|
|
#send http POST values
|
2014-11-17 14:42:57 +01:00
|
|
|
curl -k -X POST \
|
2014-11-17 14:39:11 +01:00
|
|
|
--data-urlencode "default_lang=$default_lang" \
|
|
|
|
--data-urlencode "install=Installer" \
|
|
|
|
--data-urlencode "name=$admin" \
|
|
|
|
--data-urlencode "login=$admin" \
|
|
|
|
--data-urlencode "pwd=$password" \
|
|
|
|
--data-urlencode "pwd2=$password" \
|
|
|
|
--data-urlencode "token=$token" \
|
2015-08-18 09:29:41 +02:00
|
|
|
https://$domain$curl_path/install.php > /dev/null 2>&1
|
2014-11-13 19:34:55 +01:00
|
|
|
|
2016-06-15 20:17:31 +02:00
|
|
|
sudo rm -f $src_path/install.php
|
2014-11-17 15:01:27 +01:00
|
|
|
|
2014-11-23 17:30:50 +01:00
|
|
|
#remove domain name from /etc/hosts
|
|
|
|
sudo sed -i "/#pluxml_hosts/d" /etc/hosts
|
|
|
|
|
2014-11-13 19:34:55 +01:00
|
|
|
# If app is private, remove url to SSOWat conf from skipped_uris
|
2016-06-14 12:55:55 +02:00
|
|
|
if [ "$is_public" = "No" ]; then
|
2014-11-17 14:04:17 +01:00
|
|
|
sudo yunohost app setting $app unprotected_uris -d
|
2014-11-12 22:22:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#adding admin to the allowed users
|
2014-11-12 22:26:17 +01:00
|
|
|
sudo yunohost app addaccess $app -u $admin
|
2014-11-12 22:22:53 +01:00
|
|
|
|
2014-11-23 19:42:28 +01:00
|
|
|
#allow only allowed users to access admin panel
|
2016-06-14 12:55:55 +02:00
|
|
|
sudo yunohost app setting $app protected_uris -v "/core/admin/"
|
2014-11-23 19:42:28 +01:00
|
|
|
|
2016-06-14 12:55:55 +02:00
|
|
|
# Reload nginx service
|
2014-11-12 22:22:53 +01:00
|
|
|
sudo service nginx reload
|