2017-04-09 11:05:39 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Exit on command errors and treat unset variables as an error
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# See comments in install script
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
# Source YunoHost helpers
|
|
|
|
. /usr/share/yunohost/helpers
|
2018-12-21 17:12:23 +01:00
|
|
|
source ../settings/scripts/common.sh
|
2017-04-09 11:05:39 +02:00
|
|
|
|
|
|
|
# Retrieve old app settings
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
|
|
admin=$(ynh_app_setting_get "$app" admin)
|
|
|
|
email=$(ynh_app_setting_get "$app" email)
|
|
|
|
isp_name=$(ynh_app_setting_get "$app" isp_name)
|
|
|
|
isp_site=$(ynh_app_setting_get "$app" isp_site)
|
|
|
|
secret=$(ynh_app_setting_get "$app" secret)
|
2018-12-20 23:05:20 +01:00
|
|
|
db_pwd=$(ynh_app_setting_get "$app" psqlpassword)
|
2017-04-09 11:05:39 +02:00
|
|
|
|
|
|
|
# Check domain/path availability
|
|
|
|
sudo yunohost app checkurl $domain$path -a $app \
|
|
|
|
|| ynh_die "Path not available: ${domain}${path}"
|
|
|
|
|
|
|
|
|
|
|
|
final_path=/opt/$app
|
|
|
|
if [ -d $final_path ]; then
|
|
|
|
ynh_die "There is already a directory: $final_path "
|
|
|
|
fi
|
|
|
|
|
|
|
|
conf=/etc/nginx/conf.d/$domain.d/$app.conf
|
|
|
|
if [ -f $conf ]; then
|
|
|
|
ynh_die "There is already a nginx conf file at this path: $conf "
|
|
|
|
fi
|
|
|
|
|
|
|
|
gunicorn_path=/etc/systemd/system/$app.service
|
|
|
|
if [ -f $gunicorn_path ]; then
|
|
|
|
ynh_die "There is already a gunicorn service file at this path: $gunicorn_path "
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Dependences
|
2018-12-21 17:12:23 +01:00
|
|
|
install_dependencies
|
2017-04-09 11:05:39 +02:00
|
|
|
|
|
|
|
# Restore sources & data
|
|
|
|
sudo cp -a ./sources $final_path
|
|
|
|
|
2018-12-20 19:58:44 +01:00
|
|
|
# Create user
|
|
|
|
useradd $app -d $final_path || echo "User already exists"
|
2017-04-09 11:05:39 +02:00
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
sudo chown -R www-data:www-data $final_path
|
|
|
|
|
|
|
|
# Restore conf files
|
|
|
|
sudo cp -a ./nginx.conf $conf
|
|
|
|
sudo cp -a ./gunicorn.service $gunicorn_path
|
|
|
|
sudo chown root: $gunicorn_path
|
|
|
|
sudo chmod 644 $gunicorn_path
|
|
|
|
|
|
|
|
# Set Administrator
|
|
|
|
if ynh_user_exists $admin; then
|
|
|
|
sudo yunohost app addaccess $app -u $admin
|
|
|
|
fi
|
|
|
|
|
2018-12-20 23:05:20 +01:00
|
|
|
# Restore database
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
db_name=$app
|
|
|
|
db_user=$app
|
|
|
|
ynh_psql_create_db $db_name $db_user $db_pwd
|
|
|
|
ynh_psql_execute_file_as_root "${YNH_CWD}/dump.sql" "$db_name"
|
|
|
|
|
2017-04-09 11:05:39 +02:00
|
|
|
# Log folder
|
|
|
|
sudo mkdir -p /var/log/$app
|
|
|
|
sudo chown -R $app /var/log/$app
|
|
|
|
sudo chgrp -R www-data /var/log/$app
|
|
|
|
|
|
|
|
# Reload Nginx
|
|
|
|
sudo service nginx reload
|
2018-12-20 19:58:44 +01:00
|
|
|
systemctl daemon-reload
|
2017-04-09 11:05:39 +02:00
|
|
|
sudo systemctl start $app
|
|
|
|
sudo systemctl enable $app
|
|
|
|
sudo yunohost service add $app -l /var/log/gunicorn/$app.log
|
|
|
|
|
|
|
|
ynh_app_setting_set "$app" skipped_uris "/"
|
|
|
|
sudo yunohost app ssowatconf
|