2013-12-19 03:02:51 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-02-26 17:11:40 +01:00
|
|
|
# causes the shell to exit if any subcommand or pipeline returns a non-zero status
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# This is a multi-instance app, meaning it can be installed several times independently
|
|
|
|
# The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
|
|
# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
|
|
# The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
|
|
# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
|
|
# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
|
|
# - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
|
|
# The app instance name is probably what you are interested the most, since this is
|
|
|
|
# guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
|
|
# db names, ...
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2013-12-19 03:02:51 +01:00
|
|
|
# Retrieve arguments
|
2017-02-26 17:11:40 +01:00
|
|
|
domain=$YNH_APP_ARG_DOMAIN
|
2017-06-17 12:42:01 +02:00
|
|
|
path=$YNH_APP_ARG_PATH
|
2017-02-26 17:11:40 +01:00
|
|
|
admin=$YNH_APP_ARG_ADMIN
|
|
|
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
|
|
|
title=$YNH_APP_ARG_TITLE
|
|
|
|
privatelinkbydefault=$YNH_APP_ARG_PRIVATELINKBYDEFAULT
|
|
|
|
password=$YNH_APP_ARG_PASSWORD
|
2017-03-05 09:12:23 +01:00
|
|
|
privateinstance=$YNH_APP_ARG_PRIVATEINSTANCE
|
2017-06-17 12:42:01 +02:00
|
|
|
path_url=$YNH_APP_ARG_PATH
|
2017-02-26 17:11:40 +01:00
|
|
|
|
2017-02-19 23:17:19 +01:00
|
|
|
# Load common variables and helpers
|
|
|
|
source ./_common.sh
|
|
|
|
|
2017-06-17 12:13:14 +02:00
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
|
|
|
|
#=================================================
|
|
|
|
|
2017-06-17 14:57:23 +02:00
|
|
|
path=$(ynh_normalize_url_path $path) # Vérifie et corrige la syntaxe du path.
|
2017-06-17 13:23:43 +02:00
|
|
|
|
2017-06-17 12:13:14 +02:00
|
|
|
|
2017-03-05 09:12:23 +01:00
|
|
|
# Check that the options are compatible
|
|
|
|
if [ $is_public = "Yes" ]; then
|
|
|
|
if [ $privateinstance = "Yes" ] ; then
|
|
|
|
ynh_die "Incompatible options: the instance cannot be both public and private" 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-05-29 12:48:44 +02:00
|
|
|
# Check that admin user is an existing account
|
|
|
|
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
|
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2017-03-05 09:12:23 +01:00
|
|
|
ynh_die "Error : the chosen user does not exist" 1
|
2014-05-29 12:48:44 +02:00
|
|
|
fi
|
2017-02-26 17:11:40 +01:00
|
|
|
sudo yunohost app setting $app admin -v $admin
|
2013-12-19 03:02:51 +01:00
|
|
|
|
|
|
|
# Check domain/path availability
|
2017-02-26 17:11:40 +01:00
|
|
|
sudo yunohost app checkurl $domain$path -a $app
|
2013-12-19 03:02:51 +01:00
|
|
|
if [[ ! $? -eq 0 ]]; then
|
2017-02-19 23:17:19 +01:00
|
|
|
exit 1
|
2013-12-19 03:02:51 +01:00
|
|
|
fi
|
|
|
|
|
2013-12-29 17:52:50 +01:00
|
|
|
# Install dependencies
|
2013-12-29 20:00:34 +01:00
|
|
|
sudo apt-get install php5-cli -y -qq
|
2013-12-29 17:52:50 +01:00
|
|
|
|
2013-12-19 03:02:51 +01:00
|
|
|
# Copy files to the right place
|
2017-02-26 17:11:40 +01:00
|
|
|
app_home_path=/home/yunohost.app/$app
|
|
|
|
final_path=/var/www/$app
|
2017-02-19 23:17:19 +01:00
|
|
|
|
2013-12-19 03:02:51 +01:00
|
|
|
sudo mkdir -p $final_path
|
2017-02-19 23:17:19 +01:00
|
|
|
# Download and extract in /var/www
|
|
|
|
extract_shaarli
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2017-02-26 17:11:40 +01:00
|
|
|
# generate the salt
|
2013-12-19 03:02:51 +01:00
|
|
|
salt=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
|
2017-02-26 17:11:40 +01:00
|
|
|
|
|
|
|
# generate the hash with the password
|
|
|
|
password_hash=$(php ../conf/gen_hash.php $password $admin $salt)
|
|
|
|
|
|
|
|
# set the proper value for substitution
|
2013-12-19 18:07:55 +01:00
|
|
|
if [ $privatelinkbydefault = "No" ]; then
|
2017-02-19 23:17:19 +01:00
|
|
|
privatelinkbydefault_php=false
|
2013-12-19 18:07:55 +01:00
|
|
|
else
|
2017-02-19 23:17:19 +01:00
|
|
|
privatelinkbydefault_php=true
|
2013-12-19 18:07:55 +01:00
|
|
|
fi
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2017-02-26 17:11:40 +01:00
|
|
|
# Prepare the configuration file
|
|
|
|
sudo sed -i "s@YNH_SALT@$salt@g" ../conf/config.json.php
|
|
|
|
sudo sed -i "s@YNH_ADMIN@$admin@g" ../conf/config.json.php
|
|
|
|
sudo sed -i "s@YNH_HASH@$password_hash@g" ../conf/config.json.php
|
|
|
|
sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.json.php
|
|
|
|
sudo sed -i "s@YNH_TITLE@$title@g" ../conf/config.json.php
|
|
|
|
sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault_php@g" ../conf/config.json.php
|
2017-03-05 09:12:23 +01:00
|
|
|
# turn off authentication on the instance
|
|
|
|
if [ $privateinstance = "Yes" ] ; then
|
|
|
|
sudo sed -i "/open_shaarli/s/false/true/" ../conf/config.json.php
|
|
|
|
fi
|
2017-02-26 17:11:40 +01:00
|
|
|
|
|
|
|
# Populate the data directory of the shaarli instance
|
|
|
|
sudo cp ../conf/config.json.php $final_path/data
|
|
|
|
sudo cp ../conf/datastore.php $final_path/data
|
|
|
|
sudo cp ../conf/ipbans.php $final_path/data
|
|
|
|
sudo cp ../conf/lastupdatecheck.txt $final_path/data
|
|
|
|
sudo cp ../conf/log.txt $final_path/data
|
|
|
|
sudo cp ../conf/updates.txt $final_path/data
|
2013-12-19 03:02:51 +01:00
|
|
|
|
2017-02-27 16:52:17 +01:00
|
|
|
# set proper permissions
|
2013-12-19 03:02:51 +01:00
|
|
|
sudo find $final_path -type f | xargs sudo chmod 644
|
|
|
|
sudo find $final_path -type d | xargs sudo chmod 755
|
2017-02-27 17:06:29 +01:00
|
|
|
#sudo chown -R root: $final_path
|
2017-02-27 16:52:17 +01:00
|
|
|
|
|
|
|
#set proper ownership of the files in /data
|
|
|
|
sudo chown www-data:www-data $final_path/data/config.json.php
|
|
|
|
sudo chown www-data:www-data $final_path/data/datastore.php
|
|
|
|
sudo chown www-data:www-data $final_path/data/ipbans.php
|
|
|
|
sudo chown www-data:www-data $final_path/data/lastupdatecheck.txt
|
|
|
|
sudo chown www-data:www-data $final_path/data/log.txt
|
|
|
|
sudo chown www-data:www-data $final_path/data/updates.txt
|
2013-12-19 03:02:51 +01:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
|
|
|
sudo sed -i "s@YNH_WWW_PATH@$path@g" ../conf/nginx.conf
|
|
|
|
sudo sed -i "s@YNH_ALIAS@$final_path@g" ../conf/nginx.conf
|
2017-02-26 17:11:40 +01:00
|
|
|
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
2013-12-19 03:02:51 +01:00
|
|
|
|
|
|
|
# Reload Nginx and regenerate SSOwat conf
|
2013-12-19 18:13:14 +01:00
|
|
|
if [ $is_public = "Yes" ]; then
|
2017-02-26 17:11:40 +01:00
|
|
|
sudo yunohost app setting $app unprotected_uris -v "/"
|
2017-03-05 09:12:23 +01:00
|
|
|
elif [ $privateinstance = "Yes" ] ; then
|
|
|
|
# Configure SSOWat to prevent access for other users
|
|
|
|
sudo yunohost app setting $app allowed_users -v "$admin"
|
2013-12-19 03:02:51 +01:00
|
|
|
fi
|
|
|
|
sudo service nginx reload
|
|
|
|
sudo yunohost app ssowatconf
|