upgrade 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/bin/bash
  2. #=================================================
  3. # GENERIC START
  4. #=================================================
  5. # IMPORT GENERIC HELPERS
  6. #=================================================
  7. source _common.sh
  8. source /usr/share/yunohost/helpers
  9. #=================================================
  10. # LOAD SETTINGS
  11. #=================================================
  12. ynh_script_progression --message="Loading installation settings..."
  13. app=$YNH_APP_INSTANCE_NAME
  14. domain=$(ynh_app_setting_get --app=$app --key=domain)
  15. path_url=$(ynh_app_setting_get --app=$app --key=path)
  16. final_path=$(ynh_app_setting_get --app=$app --key=final_path)
  17. firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
  18. service_name=$(ynh_app_setting_get --app=$app --key=service_name)
  19. phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
  20. #=================================================
  21. # CHECK VERSION
  22. #=================================================
  23. ynh_script_progression --message="Checking version..."
  24. upgrade_type=$(ynh_check_app_version_changed)
  25. #=================================================
  26. # ENSURE DOWNWARD COMPATIBILITY
  27. #=================================================
  28. ynh_script_progression --message="Ensuring downward compatibility..."
  29. if [ -z $phpversion ]; then
  30. phpversion=$YNH_PHP_VERSION
  31. ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
  32. fi
  33. # If final_path doesn't exist, create it
  34. if [ -z "$final_path" ]; then
  35. final_path=/var/www/$app
  36. ynh_app_setting_set --app=$app --key=final_path --value=$final_path
  37. fi
  38. if [ -d /var/www/wifiadmin/ ]; then
  39. mv /var/www/wifiadmin $final_path
  40. mv /etc/php/7.0/fpm/pool.d/wifiadmin.conf /etc/php/$phpversion/fpm/pool.d/$app.conf
  41. ynh_replace_string --match_string="wifiadmin" --replace_string="$app" --target_file=/etc/php/$phpversion/fpm/pool.d/$app.conf
  42. ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
  43. fi
  44. if [ $firmware_nonfree = "yes" ]; then
  45. firmware_nonfree=1
  46. ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
  47. elif [ $firmware_nonfree = "no" ]; then
  48. firmware_nonfree=0
  49. ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
  50. fi
  51. if [ -z $service_name ]; then
  52. service_name="ynh-hotspot"
  53. ynh_app_setting_set --app=$app --key=service_name --value=$service_name
  54. fi
  55. #=================================================
  56. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  57. #=================================================
  58. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
  59. # Backup the current version of the app
  60. ynh_backup_before_upgrade
  61. ynh_clean_setup () {
  62. # restore it if the upgrade fails
  63. ynh_restore_upgradebackup
  64. }
  65. # Exit if an error occurs during the execution of the script
  66. ynh_abort_if_errors
  67. #=================================================
  68. # STANDARD UPGRADE STEPS
  69. #=================================================
  70. # STOP SYSTEMD SERVICE
  71. #=================================================
  72. ynh_script_progression --message="Stopping a systemd service..."
  73. ynh_systemd_action --service_name=$service_name --action="stop" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
  74. #=================================================
  75. # DOWNLOAD, CHECK AND UNPACK SOURCE
  76. #=================================================
  77. if [ "$upgrade_type" == "UPGRADE_APP" ]
  78. then
  79. ynh_script_progression --message="Upgrading source files..."
  80. # Download, check integrity, uncompress and patch the source from app.src
  81. cp -a ../sources/* ${final_path}/
  82. fi
  83. #=================================================
  84. # NGINX CONFIGURATION
  85. #=================================================
  86. ynh_script_progression --message="Upgrading nginx web server configuration..."
  87. # Create a dedicated nginx config
  88. ynh_add_nginx_config
  89. #=================================================
  90. # UPGRADE DEPENDENCIES
  91. #=================================================
  92. ynh_script_progression --message="Upgrading dependencies..."
  93. if [[ $firmware_nonfree -eq 1 ]]; then
  94. check_armbian_nonfree_conflict
  95. ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
  96. else
  97. pkg_dependencies="$pkg_dependencies $free_firmware_packages"
  98. fi
  99. ynh_install_app_dependencies "$pkg_dependencies"
  100. #=================================================
  101. # CREATE DEDICATED USER
  102. #=================================================
  103. ynh_script_progression --message="Making sure dedicated system user exists..."
  104. # Create a dedicated user (if not existing)
  105. ynh_system_user_create --username=$app
  106. #=================================================
  107. # PHP-FPM CONFIGURATION
  108. #=================================================
  109. ynh_script_progression --message="Upgrading php-fpm configuration..."
  110. # Create a dedicated php-fpm config
  111. ynh_add_fpm_config
  112. #=================================================
  113. # SPECIFIC UPGRADE
  114. #=================================================
  115. # COPY CONFIGS
  116. #=================================================
  117. ynh_script_progression --message="Copying configuration..."
  118. mkdir -pm 0755 /etc/dnsmasq.dhcpd/
  119. chown root: /etc/dnsmasq.dhcpd/
  120. install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/
  121. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
  122. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
  123. # Copy init script
  124. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  125. ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${phpversion}" --target_file="/usr/local/bin/$service_name"
  126. #=================================================
  127. # MODIFY A CONFIG FILE
  128. #=================================================
  129. ynh_script_progression --message="Modifying a config file..."
  130. ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
  131. #=================================================
  132. # SETUP SYSTEMD
  133. #=================================================
  134. ynh_script_progression --message="Upgrading systemd configuration..."
  135. # Create a dedicated systemd config
  136. ynh_add_systemd_config --service=$service_name
  137. #=================================================
  138. # GENERIC FINALIZATION
  139. #=================================================
  140. # SECURE FILES AND DIRECTORIES
  141. #=================================================
  142. ynh_script_progression --message="Securing files and directories..."
  143. # Set permissions on app files
  144. chown -R $app: ${final_path}/
  145. chmod -R 0644 ${final_path}/*
  146. find ${final_path}/ -type d -exec chmod +x {} \;
  147. #=================================================
  148. # INTEGRATE SERVICE IN YUNOHOST
  149. #=================================================
  150. ynh_script_progression --message="Integrating service in YunoHost..."
  151. yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
  152. #=================================================
  153. # START SYSTEMD SERVICE
  154. #=================================================
  155. ynh_script_progression --message="Starting a systemd service..."
  156. hot_reload_usb_wifi_cards
  157. wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
  158. if [[ -z $wifi_device ]]; then
  159. ynh_app_setting_set --app=$app --key=service_enabled --value=0
  160. wifi_device=none
  161. else
  162. ynh_app_setting_set --app=$app --key=service_enabled --value=1
  163. fi
  164. # Start a systemd service if device is present
  165. if [[ $wifi_device == none ]]; then
  166. echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
  167. else
  168. ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
  169. fi
  170. #=================================================
  171. # RELOAD NGINX
  172. #=================================================
  173. ynh_script_progression --message="Reloading nginx web server..."
  174. ynh_systemd_action --service_name=nginx --action=reload
  175. #=================================================
  176. # END OF SCRIPT
  177. #=================================================
  178. ynh_script_progression --message="Upgrade of $app completed"