upgrade 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
  15. service_name=$(ynh_app_setting_get --app=$app --key=service_name)
  16. #=================================================
  17. # CHECK VERSION
  18. #=================================================
  19. ynh_script_progression --message="Checking version..."
  20. upgrade_type=$(ynh_check_app_version_changed)
  21. #=================================================
  22. # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
  23. #=================================================
  24. ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
  25. # Backup the current version of the app
  26. ynh_backup_before_upgrade
  27. ynh_clean_setup () {
  28. # Restore it if the upgrade fails
  29. ynh_restore_upgradebackup
  30. }
  31. # Exit if an error occurs during the execution of the script
  32. ynh_abort_if_errors
  33. #=================================================
  34. # STANDARD UPGRADE STEPS
  35. #=================================================
  36. # STOP SYSTEMD SERVICE
  37. #=================================================
  38. ynh_script_progression --message="Stopping the hotspot service ... (this may take some time)"
  39. ynh_systemd_action --service_name=$service_name --action="stop" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
  40. #=================================================
  41. # ENSURE DOWNWARD COMPATIBILITY
  42. #=================================================
  43. ynh_script_progression --message="Ensuring downward compatibility..."
  44. if [ -d /var/www/wifiadmin/ ]; then
  45. ynh_secure_remove /var/www/wifiadmin/
  46. fi
  47. if [ $firmware_nonfree = "yes" ]; then
  48. firmware_nonfree=1
  49. ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
  50. elif [ $firmware_nonfree = "no" ]; then
  51. firmware_nonfree=0
  52. ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
  53. fi
  54. if [ -z $service_name ]; then
  55. service_name="ynh-hotspot"
  56. ynh_app_setting_set --app=$app --key=service_name --value=$service_name
  57. fi
  58. dns=$(ynh_app_setting_get $app dns)
  59. if [[ -n "${dns}" ]]; then
  60. ip6_dns=""
  61. ip4_dns=""
  62. for ip in $(echo "${dns}" | tr ',' ' '); do
  63. if [[ "$ip" == *":"* ]]; then
  64. ip6_dns+="[$ip],"
  65. else
  66. ip4_dns+="$ip,"
  67. fi
  68. done
  69. # Remove trailing ,
  70. ip6_dns="${ip6_dns%%,}"
  71. ip4_dns="${ip4_dns%%,}"
  72. if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then
  73. ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}"
  74. if
  75. if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then
  76. ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}"
  77. if
  78. ynh_app_setting_delete $app dns
  79. fi
  80. # Old stuff prior to 2.x
  81. ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
  82. if [ "$ip6_net" == "none" ]
  83. then
  84. ip6_net=""
  85. ynh_app_setting_set --app=$app --key=ip6_net --value="$ip6_net"
  86. fi
  87. if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
  88. ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
  89. ynh_systemd_action --service_name=nginx --action=reload
  90. fi
  91. for php_path in $(ls /etc/php/*/fpm/pool.d/$app.conf 2> /dev/null); do
  92. ynh_secure_remove $php_path
  93. done
  94. if [ -d /var/www/$app ]; then
  95. ynh_secure_remove /var/www/$app
  96. fi
  97. [ -z "$(ynh_app_setting_get $app domain)" ] || ynh_app_setting_delete $app domain
  98. [ -z "$(ynh_app_setting_get $app path)" ] || ynh_app_setting_delete $app path
  99. [ -z "$(ynh_app_setting_get $app final_path)" ] || ynh_app_setting_delete $app final_path
  100. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  101. ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
  102. fi
  103. #=================================================
  104. # CREATE DEDICATED USER
  105. #=================================================
  106. ynh_script_progression --message="Making sure dedicated system user exists..."
  107. # Create a dedicated user (if not existing)
  108. ynh_system_user_create --username=$app
  109. #=================================================
  110. # UPGRADE DEPENDENCIES
  111. #=================================================
  112. ynh_script_progression --message="Upgrading dependencies..."
  113. if [[ $firmware_nonfree -eq 1 ]]; then
  114. check_armbian_nonfree_conflict
  115. ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
  116. else
  117. pkg_dependencies="$pkg_dependencies $free_firmware_packages"
  118. fi
  119. ynh_install_app_dependencies $pkg_dependencies
  120. #=================================================
  121. # SPECIFIC UPGRADE
  122. #=================================================
  123. # COPY CONFIGS
  124. #=================================================
  125. ynh_script_progression --message="Copying configuration..."
  126. mkdir -pm 0755 /etc/dnsmasq.dhcpd/
  127. chown root: /etc/dnsmasq.dhcpd/
  128. install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/
  129. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
  130. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
  131. # Copy init script
  132. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  133. # Copy openvpn scripts
  134. mkdir -pm 0755 /etc/openvpn/scripts
  135. mkdir -pm 0755 /etc/openvpn/scripts/route-up.d
  136. mkdir -pm 0755 /etc/openvpn/scripts/route-down.d
  137. install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-up.d/90-hotspot
  138. install -o root -g root -m 0755 ../conf/openvpn_90-hotspot /etc/openvpn/scripts/route-down.d/90-hotspot
  139. #=================================================
  140. # SETUP SYSTEMD
  141. #=================================================
  142. ynh_script_progression --message="Upgrading systemd configuration..."
  143. # Create a dedicated systemd config
  144. ynh_add_systemd_config --service=$service_name
  145. #=================================================
  146. # GENERIC FINALIZATION
  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 the hotspot service..."
  156. hot_reload_usb_wifi_cards
  157. wifi_device=$(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=""
  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 == "" ]]; 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. # END OF SCRIPT
  172. #=================================================
  173. ynh_script_progression --message="Upgrade of $app completed"