1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_ynh.git synced 2024-09-03 18:36:10 +02:00
etherpad_ynh/scripts/install
Bachir Soussi Chiadmi 555ed332e3 updated package for yunohost, to be tested
updated manifest
updated install and remove script  variable, multi-instance
updated nginx conf
added readme
2016-07-10 13:11:55 +02:00

91 lines
2.7 KiB
Bash

#!/bin/bash
app=$YNH_APP_INSTANCE_NAME
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_PUBLIC_SITE
port=9001
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Store config on YunoHost instance
ynh_app_setting_set $app domain $domain
ynh_app_setting_set $app domain $path
ynh_app_setting_set $app domain $is_public
# Remove trailing "/" for next commands
path=${path%/}
# Generate random password
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')
# Generate random key
key=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{40\}\).*/\1/p')
# Use 'etherpadlite' as database name and user
# TODO change db for mutli-instance
db_user=$app
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting $app mysqlpwd -v $db_pwd
# Install dependances
if ! ynh_package_is_installed "nodejs-legacy" ; then
sudo apt-get install nodejs-legacy npm -y
fi
# Copy files to the right place
final_path=/var/www/$app
sudo mkdir -p $final_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/settings.json $final_path
#TODO one service per instance ?
sudo cp ../conf/etherpad-lite /etc/init.d/
sudo chmod +x /etc/init.d/etherpad-lite
sudo update-rc.d etherpad-lite defaults
sudo mkdir /var/log/etherpad-lite/
sudo touch /var/log/etherpad-lite/etherpad-lite.log
sudo chown www-data /var/log/etherpad-lite/etherpad-lite.log
sudo npm cache clear
sudo $final_path/bin/installDeps.sh > /dev/null 2>&1
sudo npm install forever -g > /dev/null 2>&1
# Change variables in etherpad configuration
sudo sed -i "s/yunouser/$db_user/g" $final_path/settings.json
sudo sed -i "s/yunopass/$db_pwd/g" $final_path/settings.json
sudo sed -i "s/yunobase/$db_user/g" $final_path/settings.json
sudo sed -i "s/KEY/$key/g" $final_path/settings.json
# Set permissions to etherpad directory
sudo chown -R www-data: $final_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@YNH_EXAMPLE_PATH@$path@g" ../conf/nginx.conf
sed -i "s@YNH_EXAMPLE_PORT@$port@g" ../conf/nginx.conf
sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" ../conf/nginx.conf
if [ "$path" = "" ];
then
sudo cp ../conf/nginx.conf-nosub /etc/nginx/conf.d/$domain.d/$app.conf
else
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
fi
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
if [ "$is_public" = "Yes" ];
then
sudo yunohost app setting etherpadlite unprotected_uris -v "/"
fi
sudo yunohost app ssowatconf
sudo service etherpad-lite start