1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/osjs_ynh.git synced 2024-09-03 19:56:11 +02:00

[fix] upgrade

This commit is contained in:
frju365 2017-08-06 23:42:32 +02:00 committed by GitHub
parent f0feceb482
commit 6175b71353

View file

@ -2,58 +2,131 @@
# Exit on command errors and treat unset variables as an error # Exit on command errors and treat unset variables as an error
set -eu set -eu
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source .fonctions source _common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# Récupère les infos de l'application. #=================================================
# LOAD SETTINGS
#=================================================
# Set app specific variables
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Check destination directory
DESTDIR="/var/www/$app"
[[ ! -d $DESTDIR ]] && ynh_die \
"The destination directory '$DESTDIR' does not exist.\
The app is not correctly installed, you should remove it first."
# Retrieve arguments # Retrieve arguments
domain=$(ynh_app_setting_get "$app" domain) domain=$(ynh_app_setting_get "$app" domain)
path=/ path_url=$(ynh_normalize_url_path "$(ynh_app_setting_get "$app" path_url)")
final_path=$(ynh_app_setting_get "$app" final_path)
is_public=$(ynh_app_setting_get "$app" is_public) is_public=$(ynh_app_setting_get "$app" is_public)
port=$(ynh_app_setting_get "$app" port)
# Install the app #=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Use prior backup and restore on error only if backup feature
# exists on installed instance
if [ -f "/etc/yunohost/apps/$app/scripts/backup" ] ; then
ynh_backup_before_upgrade # Backup the current version of the app
ynh_clean_setup () {
ynh_backup_after_failed_upgrade
}
ynh_abort_if_errors # Stop script if an error is detected
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs 6.2.0
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app
#=================================================
# SPECIFIC SETUP
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
# Setup logrotate
ynh_use_logrotate /var/log/${app}/*.log --non-append
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
# Copy files to the right place
final_path=/var/www/$app final_path=/var/www/$app
extract_source ynh_app_setting_set $app final_path $final_path
ynh_setup_source $final_path
# Files owned by root, www-data can just read # Set files ownership during installation
sudo chown www-data:www-data $final_path -R sudo chown $app: $final_path -R
sudo chmod 755 $final_path -R sudo chmod 755 $final_path -R
# Modify Nginx configuration file and copy it to Nginx conf directory #=================================================
sed -i "s@__PORT__@$port@g" ../conf/nginx.conf # Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@__PORT__@$port@g" ../conf/os.js.service #=================================================
sed -i "s@__FINALPATH__@$final_path@g" ../conf/os.js.service
nginxconf=/etc/nginx/conf.d/$domain.d/$app.conf ynh_nginx_config
sudo cp ../conf/nginx.conf $nginxconf
sudo chown root: $nginxconf #=================================================
sudo chmod 600 $nginxconf # ADD SYSTEMD SERVICE
pushd $final_path #=================================================
sudo npm install --production
sudo node osjs build ynh_replace_string "__NODE__" "$nodejs_path" "../conf/systemd.service"
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_systemd_config
#=================================================
# INSTALL CRYPTPAD
#=================================================
script_dir="$PWD"
pushd "$final_path"
sudo chown -R $app: $final_path
sudo_path npm install --production >> $install_log 2>&1
sudo_path node osjs build
popd popd
sudo yunohost firewall allow Both 85
pre_inst_os.js
sudo service $app start
sudo systemctl start "$app".service
#=================================================
# ENABLE SERVICE IN ADMIN PANEL
#=================================================
# Ajoute le service au monitoring de Yunohost.
sudo yunohost service add $app --log "/var/log/$app/$app.log"
ynh_app_setting_set "$app" is_public "$is_public" #=================================================
if [ "$is_public" = 0 ]; # START CRYPTPAD IN BACKGROUND
#=================================================
sudo systemctl start $app
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 1 ];
then then
ynh_app_setting_set "$app" unprotected_uris "/" ynh_app_setting_set "$app" unprotected_uris "/"
fi fi
sudo service nginx reload #=================================================
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log # RELOAD NGINX
sudo yunohost app ssowatconf #=================================================
sudo systemctl restart php5-fpm
# Start OS.js sudo systemctl reload nginx
sudo systemctl restart "$app".service