1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pluxml_ynh.git synced 2024-09-03 20:16:02 +02:00
pluxml_ynh/scripts/install

105 lines
3.1 KiB
Text
Raw Normal View History

2016-06-14 12:25:46 +02:00
#!/bin/bash
2014-11-12 22:22:53 +01:00
# Exit on command errors and treat unset variables as an error
set -eu
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
admin=$YNH_APP_ARG_ADMIN
password=$YNH_APP_ARG_PASSWORD
is_public=$YNH_APP_ARG_IS_PUBLIC
default_lang=$YNH_APP_ARG_DEFAULT_LANG
2014-11-12 22:22:53 +01:00
2016-06-15 23:39:38 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# 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" \
|| ynh_die "Path not available: ${domain}${path}"
2014-11-12 22:22:53 +01:00
# Check the admin exists in YunoHost users
ynh_user_exists $admin
2014-11-12 22:22:53 +01:00
# Save app settings
ynh_app_setting_set "$app" admin "$admin"
ynh_app_setting_set "$app" is_public "$is_public"
2014-11-12 22:22:53 +01:00
# Create path for copying
src_path=/var/www/$app
sudo mkdir -p $src_path
2014-11-12 22:22:53 +01: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 -oq /tmp/$version.zip -d /tmp
sudo mv /tmp/PluXml-$version/* $src_path
2014-11-17 16:05:08 +01:00
# Set permissions
sudo chown -R root: $src_path
2016-06-15 22:03:26 +02:00
sudo chown -R www-data: $src_path/{data,plugins}
sudo find $src_path -type f -exec chmod 644 {} +
sudo find $src_path -type d -exec chmod 755 {} +
2014-11-12 22:22:53 +01:00
# Configure nginx settings
folder_path=${path%/}
2014-11-12 22:22:53 +01:00
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
2014-11-12 22:22:53 +01:00
# Temporary set public accessible
ynh_app_setting_set "$app" unprotected_uris "/"
2014-11-13 19:34:55 +01:00
# Reload services
2014-11-13 21:50:18 +01:00
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
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)
# Send http POST values
2014-11-17 14:42:57 +01:00
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
2014-11-13 19:34:55 +01:00
sudo rm -f $src_path/install.php
2014-11-17 15:01:27 +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
if [ "$is_public" == "No" ]; then
ynh_app_setting_set "$app" unprotected_uris -d
2014-11-12 22:22:53 +01:00
fi
# Add 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
# Allow only allowed users to access admin panel
ynh_app_setting_set "$app" protected_uris "/core/admin/"
# Reload nginx service
2014-11-12 22:22:53 +01:00
sudo service nginx reload