1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/shaarli_ynh.git synced 2024-09-03 20:26:10 +02:00
shaarli_ynh/scripts/install
2017-06-17 12:42:01 +02:00

130 lines
4.8 KiB
Bash

#!/bin/bash
# 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
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
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
privateinstance=$YNH_APP_ARG_PRIVATEINSTANCE
path_url=$YNH_APP_ARG_PATH
# Load common variables and helpers
source ./_common.sh
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THIS ARGS
#=================================================
path_url=$(ynh_normalize_url_path $path_url) # Vérifie et corrige la syntaxe du path.
CHECK_DOMAINPATH # Vérifie la disponibilité du path et du domaine.
CHECK_FINALPATH # Vérifie que le dossier de destination n'est pas déjà utilisé.
# 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
# Check that admin user is an existing account
sudo yunohost user list --json | grep -q "\"username\": \"$admin\""
if [[ ! $? -eq 0 ]]; then
ynh_die "Error : the chosen user does not exist" 1
fi
sudo yunohost app setting $app admin -v $admin
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Install dependencies
sudo apt-get install php5-cli -y -qq
# Copy files to the right place
app_home_path=/home/yunohost.app/$app
final_path=/var/www/$app
sudo mkdir -p $final_path
# Download and extract in /var/www
extract_shaarli
# generate the salt
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')
# generate the hash with the password
password_hash=$(php ../conf/gen_hash.php $password $admin $salt)
# set the proper value for substitution
if [ $privatelinkbydefault = "No" ]; then
privatelinkbydefault_php=false
else
privatelinkbydefault_php=true
fi
# 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
# turn off authentication on the instance
if [ $privateinstance = "Yes" ] ; then
sudo sed -i "/open_shaarli/s/false/true/" ../conf/config.json.php
fi
# 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
# set proper permissions
sudo find $final_path -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755
#sudo chown -R root: $final_path
#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
# 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
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Reload Nginx and regenerate SSOwat conf
if [ $is_public = "Yes" ]; then
sudo yunohost app setting $app unprotected_uris -v "/"
elif [ $privateinstance = "Yes" ] ; then
# Configure SSOWat to prevent access for other users
sudo yunohost app setting $app allowed_users -v "$admin"
fi
sudo service nginx reload
sudo yunohost app ssowatconf