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

101 lines
2.8 KiB
Text
Raw Normal View History

2014-01-07 21:50:21 +01:00
#!/bin/bash
app=$YNH_APP_INSTANCE_NAME
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2014-01-07 21:50:21 +01:00
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
is_public=$YNH_APP_ARG_PUBLIC_SITE
port=9001
2014-01-07 21:50:21 +01:00
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a $app
2014-01-07 21:50:21 +01:00
if [[ ! $? -eq 0 ]]; then
exit 1
2014-01-07 21:50:21 +01:00
fi
# Store config on YunoHost instance
ynh_app_setting_set "$app" domain "$domain"
ynh_app_setting_set "$app" path "$path"
ynh_app_setting_set "$app" is_public "$is_public"
# Remove trailing "/" for next commands
path=${path%/}
2014-01-07 22:15:39 +01:00
# 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')
key=$(ynh_string_random 12)
2014-01-07 22:15:39 +01:00
# Generate MySQL password and create database
dbuser=$app
dbname=$app
dbpass=$(ynh_string_random 12)
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_app_setting_set "$app" dbpass "$dbpass"
ynh_app_setting_set "$app" dbuser "$dbuser"
ynh_app_setting_set "$app" dbname "$dbname"
2014-01-07 22:15:39 +01:00
2014-01-07 21:50:21 +01:00
# Install dependances
if ! ynh_package_is_installed "nodejs-legacy" ; then
sudo apt-get install nodejs-legacy npm -y
fi
2014-01-07 21:50:21 +01:00
# create app dir and compy sources
final_path=/var/www/$app
2014-01-07 21:50:21 +01:00
sudo mkdir -p $final_path
2014-01-10 15:14:59 +01:00
sudo cp -a ../sources/* $final_path
2014-01-10 14:15:01 +01:00
sudo cp ../conf/settings.json $final_path
# Change variables in etherpad configuration
sudo sed -i "s/yunouser/$dbuser/g" $final_path/settings.json
sudo sed -i "s/yunopass/$dbpass/g" $final_path/settings.json
sudo sed -i "s/yunobase/$dbname/g" $final_path/settings.json
2014-01-10 15:52:12 +01:00
sudo sed -i "s/KEY/$key/g" $final_path/settings.json
2014-01-07 21:50:21 +01:00
sudo npm cache clear
sudo $final_path/bin/installDeps.sh > /dev/null 2>&1
sudo npm install forever -g > /dev/null 2>&1
# Set permissions to etherpad directory
2014-01-07 21:50:21 +01:00
sudo chown -R www-data: $final_path
# service
sudo cp ../conf/etherpad-lite /etc/init.d/$app
sudo sed -i "s/APPTOCHANGE/$app/g" /etc/init.d/$app
sudo chmod +x /etc/init.d/$app
sudo update-rc.d $app defaults
# logs
sudo mkdir /var/log/$app
sudo touch /var/log/$app/$app.log
sudo chown www-data /var/log/$app/$app.log
# nginx
2016-07-11 00:15:42 +02:00
nginx_conf_path=/etc/nginx/conf.d/$domain.d/$app.conf
if [ "$path" = "" ];
2014-01-10 15:37:13 +01:00
then
sudo cp ../conf/nginx.conf-nosub $nginx_conf_path
else
sudo cp ../conf/nginx.conf $nginx_conf_path
# Modify Nginx configuration file and copy it to Nginx conf directory
sudo sed -i "s@YNH_EXAMPLE_PATH@$path@g" $nginx_conf_path
sudo sed -i "s@YNH_EXAMPLE_PORT@$port@g" $nginx_conf_path
sudo sed -i "s@YNH_EXEMPLE_DOMAIN@$domain@g" $nginx_conf_path
2014-01-10 15:37:13 +01:00
fi
2014-01-07 21:50:21 +01:00
# Reload Nginx and regenerate SSOwat conf
sudo service nginx reload
# If app is public, add url to SSOWat conf as skipped_uris
if [[ $is_public -eq 1 ]]; then
# unprotected_uris allows SSO credentials to be passed anyway.
ynh_app_setting_set "$app" unprotected_uris "/"
2014-01-07 21:50:21 +01:00
fi
2014-01-07 21:50:21 +01:00
sudo yunohost app ssowatconf
2014-01-10 15:16:36 +01:00
sudo service etherpad-lite start