upgrade 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. # Old stuff prior to 2.x
  59. ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net)
  60. if [ "$ip6_net" == "none" ]
  61. then
  62. ip6_net=""
  63. ynh_app_setting_set --app=$app --key=ip6_net --value="$ip6_net"
  64. fi
  65. if [ -f /etc/nginx/conf.d/*.d/$app.conf ]; then
  66. ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf
  67. ynh_systemd_action --service_name=nginx --action=reload
  68. fi
  69. if [ -f /etc/php/*/fpm/pool.d/$app.conf ]; then
  70. ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf
  71. ynh_systemd_action --service_name=php$YNH_DEFAULT_PHP_VERSION-fpm --action=reload
  72. fi
  73. if [ -d /var/www/$app ]; then
  74. ynh_secure_remove /var/www/$app
  75. fi
  76. [ -z "$(ynh_app_setting_get $app domain)" ] || ynh_app_setting_delete $app domain
  77. [ -z "$(ynh_app_setting_get $app path)" ] || ynh_app_setting_delete $app path
  78. [ -z "$(ynh_app_setting_get $app final_path)" ] || ynh_app_setting_delete $app final_path
  79. if [ -e "/etc/sudoers.d/${app}_ynh" ]; then
  80. ynh_secure_remove "/etc/sudoers.d/${app}_ynh"
  81. fi
  82. #=================================================
  83. # CREATE DEDICATED USER
  84. #=================================================
  85. ynh_script_progression --message="Making sure dedicated system user exists..."
  86. # Create a dedicated user (if not existing)
  87. ynh_system_user_create --username=$app
  88. #=================================================
  89. # UPGRADE DEPENDENCIES
  90. #=================================================
  91. ynh_script_progression --message="Upgrading dependencies..."
  92. if [[ $firmware_nonfree -eq 1 ]]; then
  93. check_armbian_nonfree_conflict
  94. ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
  95. else
  96. pkg_dependencies="$pkg_dependencies $free_firmware_packages"
  97. fi
  98. ynh_install_app_dependencies $pkg_dependencies
  99. #=================================================
  100. # SPECIFIC UPGRADE
  101. #=================================================
  102. # COPY CONFIGS
  103. #=================================================
  104. ynh_script_progression --message="Copying configuration..."
  105. mkdir -pm 0755 /etc/dnsmasq.dhcpd/
  106. chown root: /etc/dnsmasq.dhcpd/
  107. install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/
  108. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
  109. install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
  110. # Copy init script
  111. install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
  112. #=================================================
  113. # SETUP SYSTEMD
  114. #=================================================
  115. ynh_script_progression --message="Upgrading systemd configuration..."
  116. # Create a dedicated systemd config
  117. ynh_add_systemd_config --service=$service_name
  118. #=================================================
  119. # GENERIC FINALIZATION
  120. #=================================================
  121. # INTEGRATE SERVICE IN YUNOHOST
  122. #=================================================
  123. ynh_script_progression --message="Integrating service in YunoHost..."
  124. yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
  125. #=================================================
  126. # START SYSTEMD SERVICE
  127. #=================================================
  128. ynh_script_progression --message="Starting the hotspot service..."
  129. hot_reload_usb_wifi_cards
  130. wifi_device=$(iw_devices | awk -F\| '{ print $1 }')
  131. if [[ -z $wifi_device ]]; then
  132. ynh_app_setting_set --app=$app --key=service_enabled --value=0
  133. wifi_device=""
  134. else
  135. ynh_app_setting_set --app=$app --key=service_enabled --value=1
  136. fi
  137. # Start a systemd service if device is present
  138. if [[ $wifi_device == "" ]]; then
  139. echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
  140. else
  141. ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
  142. fi
  143. #=================================================
  144. # END OF SCRIPT
  145. #=================================================
  146. ynh_script_progression --message="Upgrade of $app completed"