mirror of
https://github.com/YunoHost-Apps/my_webapp_ynh.git
synced 2024-09-03 19:46:26 +02:00
81 lines
2.3 KiB
Bash
81 lines
2.3 KiB
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
# Get multi-instances specific variables
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
# Source app helpers
|
|
. /usr/share/yunohost/helpers
|
|
|
|
# Retrieve old app settings
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
|
path=$(ynh_app_setting_get "$app" path)
|
|
mysql_db=$(ynh_app_setting_get "$app" mysql_db)
|
|
password=$(ynh_app_setting_get "$app" password)
|
|
user=$(ynh_app_setting_get "$app" user)
|
|
|
|
# Check domain/path availability
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|| exit 1
|
|
|
|
# Check destination directory
|
|
DESTDIR="/var/www/$app"
|
|
[[ -d $DESTDIR ]] && ynh_die \
|
|
"The destination directory '$DESTDIR' already exists.\
|
|
You should safely delete it before restoring this app."
|
|
|
|
# Check configuration files
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
[[ -f $nginx_conf ]] && ynh_die \
|
|
"The NGINX configuration already exists at '${nginx_conf}'.
|
|
You should safely delete it before restoring this app."
|
|
phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf"
|
|
[[ -f $phpfpm_conf ]] && ynh_die \
|
|
"The PHP FPM configuration already exists at '${phpfpm_conf}'.
|
|
You should safely delete it before restoring this app."
|
|
|
|
# Create the user account
|
|
sudo useradd -c "${app} user account" \
|
|
-d "$DESTDIR" -M -g www-data "$user" \
|
|
|| ynh_die "Unable to create user account"
|
|
sudo chpasswd <<< "${user}:${password}"
|
|
|
|
# Harden SSH connection for the user
|
|
echo "##-> ${app}
|
|
# Hardening user connection
|
|
Match User ${user}
|
|
ChrootDirectory %h
|
|
ForceCommand internal-sftp
|
|
AllowTcpForwarding no
|
|
PermitTunnel no
|
|
X11Forwarding no
|
|
##<- ${app}" | sudo tee -a /etc/ssh/sshd_config >/dev/null
|
|
|
|
# Restore the app files
|
|
sudo cp -a ./sources "$DESTDIR"
|
|
sudo chown -hR "${user}:" "$DESTDIR"
|
|
|
|
# Home directory of the user need to be owned by root to allow
|
|
# SFTP connections
|
|
sudo chown root: "$DESTDIR"
|
|
|
|
# Create and restore the database as needed
|
|
if [[ $mysql_db -eq 1 ]]; then
|
|
dbname=$app
|
|
dbuser=$app
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
[[ -f ./dump.sql ]] \
|
|
&& ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql \
|
|
|| echo "No MySQL dump has been found" >&2
|
|
fi
|
|
|
|
# Restore configuration files
|
|
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
|
sudo cp -a ./conf/php-fpm.conf "$phpfpm_conf"
|
|
|
|
# Reload services
|
|
sudo service php5-fpm reload || true
|
|
sudo service nginx reload || true
|
|
sudo service sshd reload
|