2016-03-01 10:47:41 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2016-12-06 03:09:15 +01:00
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
2016-03-01 10:47:41 +01:00
|
|
|
|
# Retrieve arguments
|
2016-12-06 03:09:15 +01:00
|
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
|
|
|
|
path=$YNH_APP_ARG_PATH
|
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
2016-03-01 10:47:41 +01:00
|
|
|
|
|
2016-12-06 15:11:20 +01:00
|
|
|
|
# Correct path
|
|
|
|
|
if [ "${path:0:1}" != "/" ]; then
|
|
|
|
|
path="/$path"
|
|
|
|
|
fi
|
|
|
|
|
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then
|
|
|
|
|
path="${path:0:${#path}-1}"
|
|
|
|
|
fi
|
2016-12-06 03:09:15 +01:00
|
|
|
|
|
2016-03-01 10:47:41 +01:00
|
|
|
|
# Save app settings
|
2016-12-06 15:11:20 +01:00
|
|
|
|
ynh_app_setting_set "$domain" domain "$domain"
|
|
|
|
|
ynh_app_setting_set "$path" path "$path"
|
2016-12-06 03:09:15 +01:00
|
|
|
|
ynh_app_setting_set "$app" is_public "$is_public"
|
2016-03-01 10:47:41 +01:00
|
|
|
|
|
|
|
|
|
# Check domain/path availability
|
2016-12-06 03:09:15 +01:00
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
|
|
|
|
|
|
# Download source
|
2016-12-06 15:11:20 +01:00
|
|
|
|
sudo wget -q https://raw.githubusercontent.com/keeweb/keeweb/gh-pages/index.html
|
|
|
|
|
sudo wget -q https://raw.githubusercontent.com/keeweb/keeweb/gh-pages/manifest.appcache
|
2016-12-06 03:09:15 +01:00
|
|
|
|
sudo sed -i.bak 's/(no-config)/config.json/g' index.html
|
2016-03-01 10:47:41 +01:00
|
|
|
|
|
|
|
|
|
# Copy source files
|
2016-12-06 03:09:15 +01:00
|
|
|
|
src_path=/var/www/$app
|
|
|
|
|
sudo mkdir -p $src_path
|
|
|
|
|
sudo cp -a index.html manifest.appcache ../conf/config.json $src_path
|
2016-03-01 10:47:41 +01:00
|
|
|
|
|
|
|
|
|
# Set permissions to app files
|
2016-12-06 03:09:15 +01:00
|
|
|
|
sudo chown -R root: $src_path
|
2016-03-01 10:47:41 +01:00
|
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
|
sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
2016-12-06 03:09:15 +01:00
|
|
|
|
sed -i "s@YNH_WWW_ALIAS@$src_path/@g" ../conf/nginx.conf
|
2016-03-01 10:47:41 +01:00
|
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
|
|
|
|
|
|
# If app is public, add url to SSOWat conf as skipped_uris
|
2016-12-06 03:09:15 +01:00
|
|
|
|
if [[ $is_public -eq 1 ]]; then
|
|
|
|
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
2016-03-01 10:47:41 +01:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Restart services
|
|
|
|
|
sudo service nginx reload
|