#!/bin/bash # 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 # Source YunoHost helpers source /usr/share/yunohost/helpers # Remove trailing slash [ "$path" != "/" ] && path=${path%/} # Check domain/path availability sudo yunohost app checkurl "${domain}${path}" -a "$app" \ || ynh_die "Path not available: ${domain}${path}" # Check the admin exists in YunoHost users ynh_user_exists $admin # Save app settings ynh_app_setting_set "$app" admin "$admin" ynh_app_setting_set "$app" is_public "$is_public" # 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 -oq /tmp/$version.zip -d /tmp sudo mv /tmp/PluXml-$version/* $src_path # Set permissions sudo chown -R root: $src_path 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 {} + # 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 ynh_app_setting_set "$app" unprotected_uris "/" # 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 ynh_app_setting_delete "$app" unprotected_uris fi # Add admin to the allowed users sudo yunohost app addaccess $app -u $admin # Allow only allowed users to access admin panel ynh_app_setting_set "$app" protected_uris "/core/admin/" # Reload nginx service sudo service nginx reload