mirror of
https://github.com/YunoHost-Apps/pluxml_ynh.git
synced 2024-09-03 20:16:02 +02:00
109 lines
3.1 KiB
Bash
109 lines
3.1 KiB
Bash
#!/bin/bash
|
|
|
|
app=pluxml
|
|
|
|
#retrieve arguments
|
|
domain=$1
|
|
path=$2
|
|
admin=$3
|
|
password=$4
|
|
is_public=$5
|
|
default_lang=$6
|
|
|
|
# Remove trailing slash
|
|
[ "$path" != "/" ] && path=${path%/}
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl $domain$path -a $app
|
|
if [[ ! $? -eq 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Check user
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
if [[ ! $? -eq 0 ]]; then
|
|
echo "Wrong user" && exit 1
|
|
fi
|
|
|
|
# Save app settings
|
|
sudo yunohost app setting $app admin -v "$admin"
|
|
sudo yunohost app setting $app is_public -v "$is_public"
|
|
sudo yunohost app setting $app domain -v "$domain"
|
|
sudo yunohost app setting $app path -v "$path"
|
|
|
|
#create path for copying
|
|
src_path=/var/www/$app
|
|
sudo mkdir -p $src_path
|
|
|
|
# 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
|
|
sudo find $src_path -type f -name ".htaccess" | xargs sudo rm
|
|
|
|
#setup permissions
|
|
sudo chown -R root: $src_path
|
|
sudo chown -R www-data: $src_path/data
|
|
sudo chown -R www-data: $src_path/plugins
|
|
sudo find $src_path -type f | xargs sudo chmod 644
|
|
sudo find $src_path -type d | xargs sudo chmod 755
|
|
|
|
#configure nginx settings
|
|
folder_path=${path%/}
|
|
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
|
|
# If path is only / (without subfolder), add trailing slash to alias
|
|
alias_path=$src_path
|
|
nginx_conf="../conf/nginx.conf"
|
|
[ "$path" == '/' ] && alias_path=$alias_path'/'
|
|
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
|
|
|
|
#temporary set public accessible
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
|
|
|
# Reload services
|
|
sudo service nginx reload
|
|
sudo yunohost app ssowatconf
|
|
|
|
#temporary add domain name to /etc/hosts
|
|
sudo sed -i "1 i\127.0.0.1 $domain #pluxml_hosts" /etc/hosts
|
|
|
|
#make request to install app
|
|
#get the html page
|
|
curl_path=$([ "$path" == "/" ] || echo $path)
|
|
curl -kL -o install_page.html https://$domain$curl_path/install.php >/dev/null 2>&1
|
|
|
|
|
|
#get the token for form validation
|
|
token=$(cat install_page.html | grep "input" | grep "token" | tail -1 | cut -d' ' -f3 | cut -d'"' -f2)
|
|
#send http POST values
|
|
curl -k -X POST \
|
|
--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" \
|
|
https://$domain$curl_path/install.php > /dev/null 2>&1
|
|
|
|
sudo rm -f $src_path/install.php
|
|
|
|
#remove domain name from /etc/hosts
|
|
sudo sed -i "/#pluxml_hosts/d" /etc/hosts
|
|
|
|
# If app is private, remove url to SSOWat conf from skipped_uris
|
|
if [ "$is_public" = "No" ]; then
|
|
sudo yunohost app setting $app unprotected_uris -d
|
|
fi
|
|
|
|
#adding admin to the allowed users
|
|
sudo yunohost app addaccess $app -u $admin
|
|
|
|
#allow only allowed users to access admin panel
|
|
sudo yunohost app setting $app protected_uris -v "/core/admin/"
|
|
|
|
# Reload nginx service
|
|
sudo service nginx reload
|