1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/baikal_ynh.git synced 2024-09-03 18:16:11 +02:00
baikal_ynh/scripts/install
2016-01-18 13:13:25 +01:00

62 lines
2.4 KiB
Bash

#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
password=$3
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a baikal
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Install PHP dependency
sudo apt-get update
sudo apt-get install -y php5-cli
# Copy files to the right place
final_path=/var/www/baikal
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo chown -R www-data: $final_path
sudo su -c "curl -sS https://getcomposer.org/installer | php -- --install-dir=$final_path" -s /bin/sh www-data
sudo su -c "cd $final_path && php composer.phar install" -s /bin/sh www-data
sudo rm $final_path/composer*
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p')
db_user=baikal
sudo yunohost app initdb $db_user -p $db_pwd -s $(readlink -e ../sources/Core/Resources/Db/MySQL/db.sql)
sudo yunohost app setting baikal mysqlpwd -v $db_pwd
sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.php
sed -i "s@YNH_ADMIN_PASSWORDHASH@$(echo -n admin:BaikalDAV:$password | md5sum | cut -d ' ' -f 1)@g" ../conf/config.php
sudo yunohost app setting baikal password -v "$password"
sed -i "s@YNH_LOCATION@$path@g" ../conf/config.system.php
sed -i "s@YNH_DBNAME@$db_user@g" ../conf/config.system.php
sed -i "s@YNH_DBUSER@$db_user@g" ../conf/config.system.php
sed -i "s@YNH_DBPWD@$db_pwd@g" ../conf/config.system.php
encrypt_key=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{32\}\).*/\1/p')
sudo yunohost app setting baikal encrypt_key -v $encrypt_key
sed -i "s@YNH_ENCRYPTKEY@$encrypt_key@g" ../conf/config.system.php
sudo cp ../conf/config.php $final_path/Specific
sudo cp ../conf/config.system.php $final_path/Specific
sudo chown -R root: $final_path
sudo chown -R www-data: $final_path/Specific
sudo find $final_path -type f | xargs sudo chmod 644
sudo find $final_path -type d | xargs sudo chmod 755
# Change variables in Baikal configuration
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
sed -i "s@ALIASTOCHANGE@$final_path/html@g" ../conf/nginx.conf
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/baikal.conf
sudo chown root: /etc/nginx/conf.d/$domain.d/baikal.conf
sudo chmod 600 /etc/nginx/conf.d/$domain.d/baikal.conf
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
sudo yunohost app setting baikal skipped_uris -v "/"
sudo yunohost app ssowatconf