ubautoupgrade.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/sh
  2. #
  3. # WARNING!
  4. # backup manually whole directory billing at first time before running this updater
  5. # something like cp -R billing /safe/path/billing_helpp
  6. #
  7. ######################## CONFIG SECTION ########################
  8. #dialog
  9. DIALOG="/usr/bin/dialog"
  10. #fetch software
  11. FETCH="/usr/bin/fetch"
  12. #tar binary
  13. TAR="/usr/bin/tar"
  14. # path to your apache data dir
  15. APACHE_DATA_PATH="/usr/local/www/apache24/data/"
  16. # billing path
  17. UBILLING_PATH="billing/"
  18. #kill default admin account after update?
  19. DEFADM_KILL="NO"
  20. #use DN online detection?
  21. DN_ONLINE_LINKING="YES"
  22. #update log file
  23. LOG_FILE="/var/log/ubillingupdate.log"
  24. #temp directory path
  25. TEMP_PATH="/tmp/"
  26. #restore point dir
  27. RESTORE_POINT="/${TEMP_PATH}ub_restore"
  28. #defaults
  29. UBILLING_RELEASE_URL="http://ubilling.net.ua/"
  30. UBILLING_RELEASE_NAME="ub.tgz"
  31. ######################## INTERFACE SECTION ####################
  32. if [ $# -ne 1 ]
  33. then
  34. #interactive mode
  35. $DIALOG --title "Ubilling update" --msgbox "This wizard help you to update your Ubilling installation to the the latest stable or current development release" 10 40
  36. clear
  37. $DIALOG --menu "Choose a Ubilling release branch to which you want to update." 11 65 6 \
  38. STABLE "Ubilling latest stable release (recommended)"\
  39. MIRROR "Ubilling latest stable release mirror"\
  40. CURRENT "Ubilling current development snapshot"\
  41. 2> /tmp/auprelease
  42. clear
  43. BRANCH=`cat /tmp/auprelease`
  44. rm -fr /tmp/auprelease
  45. #last chance to exit
  46. $DIALOG --title "Check settings" --yesno "Are all of these settings correct? \n \n Ubilling release: ${BRANCH}\n Kill default admin: ${DEFADM_KILL} \n Installation full path: ${APACHE_DATA_PATH}${UBILLING_PATH}\n" 9 70
  47. AGREE=$?
  48. clear
  49. else
  50. #getting branch from CLI 1st param in batch mode
  51. BRANCH=$1
  52. AGREE="0"
  53. fi
  54. case $BRANCH in
  55. STABLE)
  56. UBILLING_RELEASE_URL="http://ubilling.net.ua/"
  57. UBILLING_RELEASE_NAME="ub.tgz"
  58. ;;
  59. CURRENT)
  60. UBILLING_RELEASE_URL="http://snaps.ubilling.net.ua/"
  61. UBILLING_RELEASE_NAME="ub_current.tgz"
  62. ;;
  63. MIRROR)
  64. UBILLING_RELEASE_URL="http://mirror.ubilling.net.ua/"
  65. UBILLING_RELEASE_NAME="ub.tgz"
  66. ;;
  67. esac
  68. ######################## END OF CONFIG ########################
  69. #checking billing directory availability
  70. if [ -d ${APACHE_DATA_PATH}${UBILLING_PATH} ]
  71. then
  72. case $AGREE in
  73. 0)
  74. echo "=== Start Ubilling auto update ==="
  75. cd ${APACHE_DATA_PATH}${UBILLING_PATH}
  76. echo "=== Downloading new release ==="
  77. $FETCH ${UBILLING_RELEASE_URL}${UBILLING_RELEASE_NAME}
  78. if [ -f ${UBILLING_RELEASE_NAME} ];
  79. then
  80. echo "=== Creating restore point ==="
  81. mkdir ${RESTORE_POINT} 2> /dev/null
  82. rm -fr ${RESTORE_POINT}/*
  83. rm -rf ${TEMP_PATH}onusig_bak
  84. rm -rf ${TEMP_PATH}photostorage_bak
  85. rm -rf ${TEMP_PATH}sql_bak
  86. rm -fr ${TEMP_PATH}us_htaccess
  87. echo "=== Move new release to safe place ==="
  88. cp -R ${UBILLING_RELEASE_NAME} ${RESTORE_POINT}/
  89. echo "=== Backup current data ==="
  90. mkdir ${RESTORE_POINT}/config
  91. mkdir ${RESTORE_POINT}/content
  92. mkdir ${RESTORE_POINT}/multinet
  93. mkdir ${RESTORE_POINT}/userstats
  94. mkdir ${RESTORE_POINT}/userstats/config
  95. # backup of actual configs and administrators
  96. mv ./content/documents/onusig ${TEMP_PATH}onusig_bak
  97. mv ./content/documents/photostorage ${TEMP_PATH}photostorage_bak
  98. mv ./content/backups/sql ${TEMP_PATH}sql_bak
  99. cp ./userstats/.htaccess ${TEMP_PATH}us_htaccess 2> /dev/null
  100. cp .htaccess ${RESTORE_POINT}/ 2> /dev/null
  101. cp favicon.ico ${RESTORE_POINT}/ 2> /dev/null
  102. cp remote_nas.conf ${RESTORE_POINT}/
  103. cp -R ./multinet ${RESTORE_POINT}/
  104. cp ./config/alter.ini ${RESTORE_POINT}/config/
  105. cp ./config/billing.ini ${RESTORE_POINT}/config/
  106. cp ./config/mysql.ini ${RESTORE_POINT}/config/
  107. cp ./config/ymaps.ini ${RESTORE_POINT}/config/
  108. cp ./config/config.ini ${RESTORE_POINT}/config/
  109. cp -R ./config/dhcp ${RESTORE_POINT}/config/
  110. cp -R ./content/users ${RESTORE_POINT}/content/
  111. cp -R ./content/reports ${RESTORE_POINT}/content/
  112. cp -R ./content/documents ${RESTORE_POINT}/content/
  113. cp ./config/printcheck.tpl ${RESTORE_POINT}/config/
  114. cp ./userstats/config/mysql.ini ${RESTORE_POINT}/userstats/config/
  115. cp ./userstats/config/userstats.ini ${RESTORE_POINT}/userstats/config/
  116. cp ./userstats/config/tariffmatrix.ini ${RESTORE_POINT}/userstats/config/
  117. echo "=== Billing directory cleanup ==="
  118. rm -fr ${APACHE_DATA_PATH}${UBILLING_PATH}/*
  119. echo "=== Unpacking new release ==="
  120. cp -R ${RESTORE_POINT}/${UBILLING_RELEASE_NAME} ${APACHE_DATA_PATH}${UBILLING_PATH}/
  121. echo `date` >> ${LOG_FILE}
  122. echo "====================" >> ${LOG_FILE}
  123. $TAR zxvf ${UBILLING_RELEASE_NAME} 2>> ${LOG_FILE}
  124. rm -fr ${UBILLING_RELEASE_NAME}
  125. echo "=== Restoring configs ==="
  126. cp -R ${RESTORE_POINT}/* ./
  127. rm -rf ./content/documents/onusig
  128. mv ${TEMP_PATH}onusig_bak ./content/documents/onusig
  129. rm -rf ./content/documents/photostorage
  130. mv ${TEMP_PATH}photostorage_bak ./content/documents/photostorage
  131. rm -rf ./content/backups/sql
  132. mv ${TEMP_PATH}sql_bak ./content/backups/sql
  133. cp -R ${TEMP_PATH}us_htaccess ./userstats/.htaccess 2> /dev/null
  134. rm -fr ${UBILLING_RELEASE_NAME}
  135. echo "deny from all" > ${RESTORE_POINT}/.htaccess
  136. #kill default admin
  137. case $DEFADM_KILL in
  138. NO)
  139. echo "=== Default admin account skipped ===";;
  140. YES)
  141. rm -fr ./content/users/admin
  142. echo "=== Default admin account removed ===";;
  143. esac
  144. echo "=== Setting FS permissions ==="
  145. chmod -R 777 content/ config/ multinet/ exports/ remote_nas.conf
  146. chmod -R 777 userstats/config/
  147. case $DN_ONLINE_LINKING in
  148. NO)
  149. echo "=== No DN online ==";;
  150. YES)
  151. mkdir ${APACHE_DATA_PATH}${UBILLING_PATH}/content/dn
  152. chmod 777 /etc/stargazer/dn ${APACHE_DATA_PATH}${UBILLING_PATH}/content/dn
  153. echo "=== Linking True Online ===";;
  154. esac
  155. # Setting up autoupdate script
  156. if [ -f ./docs/presets/FreeBSD/ubautoupgrade.sh ];
  157. then
  158. echo "=== Updating autoupdater ==="
  159. cp -R ./docs/presets/FreeBSD/ubautoupgrade.sh /bin/
  160. chmod a+x /bin/ubautoupgrade.sh
  161. else
  162. echo "Looks like this Ubilling release does not containing automatic upgrade preset"
  163. fi
  164. echo "=== Executing post-install API callback ==="
  165. /bin/ubapi "autoupdatehook" 2>> ${LOG_FILE}
  166. echo "=== Deleting restore poing ==="
  167. rm -fr ${RESTORE_POINT}
  168. rm -rf ${TEMP_PATH}onusig_bak
  169. rm -rf ${TEMP_PATH}photostorage_bak
  170. rm -rf ${TEMP_PATH}sql_bak
  171. NEW_RELEASE=`cat RELEASE`
  172. echo "SUCCESS: Ubilling update successfully completed. Now your installation release is: ${NEW_RELEASE}"
  173. #release file not dowloaded
  174. else
  175. echo "ERROR: No new Ubilling release file found, update aborted"
  176. fi
  177. ;;
  178. 1)
  179. echo "Update has been canceled"
  180. exit
  181. ;;
  182. esac
  183. else
  184. echo "ERROR: Update has been aborted: wrong Ubilling directory"
  185. fi