Browse Source

Merge branch 'update-scripts-to-the-new-standard' of github.com:kay0u/hotspot_ynh into update-scripts-to-the-new-standard

Kayou 6 years ago
parent
commit
06b7a47139
3 changed files with 127 additions and 22 deletions
  1. 2 2
      check_process
  2. 2 0
      scripts/install
  3. 123 20
      scripts/upgrade

+ 2 - 2
check_process

@@ -13,12 +13,12 @@
 		setup_private=1
 		setup_public=1
 		upgrade=1
-		upgrade=1	from_commit=CommitHash
+		upgrade=1	from_commit=16b705afde210215c99e328f3417302dad89c63e
 		backup_restore=1
 		multi_instance=0
 		incorrect_path=1
 		port_already_use=0
-		change_url=1
+		change_url=0
 ;;; Levels
 	Level 1=auto
 	Level 2=auto

+ 2 - 0
scripts/install

@@ -214,6 +214,7 @@ ynh_app_setting_set $app ip4_dns1 80.67.169.12
 ynh_app_setting_set $app ip4_nat_prefix 10.0.242
 ynh_app_setting_set $app vpnclient no
 ynh_app_setting_set $app service_name $service_name
+ynh_app_setting_set $app packages $packages
 
 if [[ -z $wifi_device ]]; then
   ynh_app_setting_set $app service_enabled 0
@@ -284,6 +285,7 @@ systemctl stop hostapd
 #=================================================
 ynh_print_info "Reloading nginx web server..."
 
+systemctl restart php7.0-fpm
 systemctl reload nginx
 
 # Remove IPv6 address set if there is a VPN installed

+ 123 - 20
scripts/upgrade

@@ -1,7 +1,7 @@
 #!/bin/bash
 
 #=================================================
-# GENERIC STARTING
+# GENERIC START
 #=================================================
 # IMPORT GENERIC HELPERS
 #=================================================
@@ -10,25 +10,52 @@ source _common.sh
 source /usr/share/yunohost/helpers
 
 #=================================================
-# MANAGE SCRIPT FAILURE
-#=================================================
-
-# Exit if an error occurs during the execution of the script
-ynh_abort_if_errors
-
-#=================================================
 # LOAD SETTINGS
 #=================================================
+ynh_print_info "Loading installation settings..."
 
 app=$YNH_APP_INSTANCE_NAME
 
 domain=$(ynh_app_setting_get $app domain)
 path_url=$(ynh_app_setting_get $app path)
-wifi_ssid=$(ynh_app_setting_get $app wifi_ssid)
-wifi_passphrase=$(ynh_app_setting_get $app wifi_passphrase)
-firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
 final_path=$(ynh_app_setting_get $app final_path)
-multissid=$(ynh_app_setting_get $app multissid)
+firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
+packages=$(ynh_app_setting_get $app packages)
+
+#=================================================
+# ENSURE DOWNWARD COMPATIBILITY
+#=================================================
+ynh_print_info "Ensuring downward compatibility..."
+
+# If final_path doesn't exist, create it
+if [ -z $final_path ]; then
+	final_path=/var/www/$app
+	ynh_app_setting_set $app final_path $final_path
+fi
+
+if [ -z $packages ]; then
+  if [[ $firmware_nonfree -eq 1 ]]; then
+    packages=$nonfree_packages
+  else
+    packages=$free_packages
+  fi
+
+  ynh_app_setting_set $app packages $packages
+fi
+
+#=================================================
+# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
+#=================================================
+ynh_print_info "Backing up the app before upgrading (may take a while)..."
+
+# Backup the current version of the app
+ynh_backup_before_upgrade
+ynh_clean_setup () {
+	# restore it if the upgrade fails
+	ynh_restore_upgradebackup
+}
+# Exit if an error occurs during the execution of the script
+ynh_abort_if_errors
 
 #=================================================
 # CHECK THE PATH
@@ -38,18 +65,94 @@ multissid=$(ynh_app_setting_get $app multissid)
 path_url=$(ynh_normalize_url_path $path_url)
 
 #=================================================
+# STANDARD UPGRADE STEPS
+#=================================================
+# DOWNLOAD, CHECK AND UNPACK SOURCE
+#=================================================
+ynh_print_info "Upgrading source files..."
+
+# Download, check integrity, uncompress and patch the source from app.src
+cp -a ../sources/* ${final_path}/
+
+chown -R www-data: ${final_path}/
+chmod -R 0644 ${final_path}/*
+find ${final_path}/ -type d -exec chmod +x {} \;
+
+#=================================================
+# NGINX CONFIGURATION
+#=================================================
+ynh_print_info "Upgrading nginx web server configuration..."
+
+# Create a dedicated nginx config
+ynh_add_nginx_config
+
+#=================================================
+# UPGRADE DEPENDENCIES
+#=================================================
+ynh_print_info "Upgrading dependencies..."
+
+ynh_install_app_dependencies "$pkg_dependencies" "$packages"
+
+#=================================================
+# CREATE DEDICATED USER
+#=================================================
+ynh_print_info "Making sure dedicated system user exists..."
+
+# Create a dedicated user (if not existing)
+ynh_system_user_create $app
+
+#=================================================
+# PHP-FPM CONFIGURATION
+#=================================================
+ynh_print_info "Upgrading php-fpm configuration..."
+
+# Create a dedicated php-fpm config
+ynh_add_fpm_config
+
+#=================================================
 # SPECIFIC UPGRADE
 #=================================================
+# FIX CONFIGS
+#=================================================
 
-source ./prerequisites
+### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it.
+ynh_backup_if_checksum_is_different "$final_path/config.php"
+ynh_replace_string "__PATH__" "${path_url}" "$final_path/config.php"
+# Recalculate and store the checksum of the file for the next upgrade.
+ynh_store_file_checksum "$final_path/config.php"
 
-# Changes
+#=================================================
+# SETUP SYSTEMD
+#=================================================
+ynh_print_info "Upgrading systemd configuration..."
 
-if [[ -z $(ynh_app_setting_get $app ip6_firewall) ]]; then
-  ip6_firewall=$(printf '1|%.0s' $(seq "${multissid}"))
-  ip6_firewall=$(echo "${ip6_firewall%?}")
+# Create a dedicated systemd config
+ynh_add_systemd_config
 
-  ynh_app_setting_set "${app}" ip6_firewall "${ip6_firewall}"
-fi
+#=================================================
+# GENERIC FINALIZATION
+#=================================================
+# SECURE FILES AND DIRECTORIES
+#=================================================
+
+# Set permissions on app files
+chown -R www-data: $final_path
+
+#=================================================
+# SETUP SSOWAT
+#=================================================
+ynh_print_info "Upgrading SSOwat configuration..."
+
+#=================================================
+# RELOAD NGINX
+#=================================================
+ynh_print_info "Reloading nginx web server..."
+
+systemctl restart php7.0-fpm
+systemctl reload nginx
+
+#=================================================
+# END OF SCRIPT
+#=================================================
 
-ynh_systemctl start ynh-hotspot
+ynh_print_info "Upgrade of $app completed"