upgrade 6.6 KB

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