UBinstaller.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. #!/bin/sh
  2. #
  3. # Per aspera ad astra
  4. #
  5. DIALOG=${DIALOG=dialog}
  6. FETCH="/usr/bin/fetch"
  7. APACHE_VERSION="apache24"
  8. APACHE_DATA_PATH="/usr/local/www/apache24/data/"
  9. APACHE_CONFIG_DIR="/usr/local/etc/apache24/"
  10. APACHE_INIT_SCRIPT="/usr/local/etc/rc.d/apache24"
  11. APACHE_CONFIG_PRESET_NAME="httpd24f8.conf"
  12. APACHE_CONFIG_NAME="httpd.conf"
  13. PHP_CONFIG_PRESET="php8.ini"
  14. #some remote paths here
  15. DL_PACKAGES_URL="http://ubilling.net.ua/packages/"
  16. DL_PACKAGES_EXT=".tar.gz"
  17. DL_UB_URL="http://ubilling.net.ua/"
  18. DL_UB_NAME="ub.tgz"
  19. DL_STG_URL="http://ubilling.net.ua/stg/"
  20. DL_STG_NAME="stg-2.409.tar.gz"
  21. DL_STG_RELEASE="stg-2.409"
  22. set PATH=/usr/local/bin:/usr/local/sbin:$PATH
  23. # config interface section
  24. clear
  25. $DIALOG --title "Ubilling installation" --msgbox "This wizard helps you to install Stargazer and Ubilling of the latest stable versions to CLEAN (!) FreeBSD distribution" 10 50
  26. clear
  27. #new or migration installation
  28. clear
  29. $DIALOG --menu "Type of Ubilling installation" 10 75 8 \
  30. NEW "This is new Ubilling installation"\
  31. MIG "Migrating existing Ubilling setup from another server"\
  32. 2> /tmp/insttype
  33. clear
  34. $DIALOG --menu "Choose FreeBSD version and architecture" 16 50 8 \
  35. 141_6K "FreeBSD 14.1 amd64"\
  36. 140_6K "FreeBSD 14.0 amd64"\
  37. 134_6K "FreeBSD 13.4 amd64"\
  38. 133_6K "FreeBSD 13.3 amd64"\
  39. 132_6E "FreeBSD 13.2 amd64"\
  40. 2> /tmp/ubarch
  41. clear
  42. #configuring stargazer release
  43. clear
  44. $DIALOG --menu "Choose Stargazer release" 16 50 8 \
  45. 409REL "Stargazer 2.409-release (stable)"\
  46. 409RC5 "Stargazer 2.409-rc5 (legacy)"\
  47. 409RC2 "Stargazer 2.409-rc2 (legacy)"\
  48. 2> /tmp/stgver
  49. clear
  50. #configuring LAN interface
  51. ALL_IFACES=`grep rnet /var/run/dmesg.boot | cut -f 1 -d ":" | tr "\n" " "`
  52. INTIF_DIALOG_START="$DIALOG --menu \"Select LAN interface that interracts with your INTERNAL network\" 15 65 6 \\"
  53. INTIF_DIALOG="${INTIF_DIALOG_START}"
  54. for EACH_IFACE in $ALL_IFACES
  55. do
  56. LIIFACE_MAC=`grep rnet /var/run/dmesg.boot | grep ${EACH_IFACE} | cut -f 4 -d " "`
  57. LIIFACE_IP=`ifconfig ${EACH_IFACE} | grep "inet " | cut -f 2 -d ' ' | tr -d ' '`
  58. INTIF_DIALOG="${INTIF_DIALOG}${EACH_IFACE} \\ \"${LIIFACE_IP} - ${LIIFACE_MAC}\" "
  59. done
  60. INTIF_DIALOG="${INTIF_DIALOG} 2> /tmp/ubiface"
  61. sh -c "${INTIF_DIALOG}"
  62. clear
  63. #configuring internal network
  64. TMP_LAN_IFACE=`cat /tmp/ubiface`
  65. TMP_NET_DATA=`netstat -rn -f inet | grep ${TMP_LAN_IFACE} | grep "/" | cut -f 1 -d " "`
  66. TMP_LAN_NETW=`echo ${TMP_NET_DATA} | cut -f 1 -d "/"`
  67. TMP_LAN_CIDR=`echo ${TMP_NET_DATA} | cut -f 2 -d "/"`
  68. echo ${TMP_LAN_NETW} > /tmp/ubnetw
  69. echo ${TMP_LAN_CIDR} > /tmp/ubcidr
  70. #NAT etc presets setup
  71. clear
  72. $DIALOG --title "Setup NAS" --yesno "Do you want to install firewall/nat/shaper presets for setup all-in-one Billing+NAS server" 10 40
  73. NAS_KERNEL=$?
  74. clear
  75. case $NAS_KERNEL in
  76. 0)
  77. #if setup NAS kernel with preconfigured firewall
  78. #configuring WAN interface
  79. ALL_IFACES=`grep rnet /var/run/dmesg.boot | cut -f 1 -d ":" | tr "\n" " "`
  80. EXTIF_DIALOG_START="$DIALOG --menu \"Select WAN interface for NAT that interracts with Internet\" 15 65 6 \\"
  81. EXTIF_DIALOG="${EXTIF_DIALOG_START}"
  82. for EACH_IFACE in $ALL_IFACES
  83. do
  84. LIIFACE_MAC=`grep rnet /var/run/dmesg.boot | grep ${EACH_IFACE} | cut -f 4 -d " "`
  85. LIIFACE_IP=`ifconfig ${EACH_IFACE} | grep "inet " | cut -f 2 -d ' ' | tr -d ' '`
  86. EXTIF_DIALOG="${EXTIF_DIALOG}${EACH_IFACE} \\ \"${LIIFACE_IP} - ${LIIFACE_MAC}\" "
  87. done
  88. EXTIF_DIALOG="${EXTIF_DIALOG} 2> /tmp/ubextif"
  89. sh -c "${EXTIF_DIALOG}"
  90. clear
  91. EXT_IF=`cat /tmp/ubextif`
  92. ;;
  93. 1)
  94. EXT_IF="none"
  95. ;;
  96. esac
  97. #some passwords generation or manual input
  98. PASSW_MODE=`cat /tmp/insttype`
  99. case $PASSW_MODE in
  100. NEW)
  101. #generating mysql password
  102. GEN_MYS_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  103. echo "mys"${GEN_MYS_PASS} > /tmp/ubmypass
  104. #getting stargazer admin password
  105. GEN_STG_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  106. echo "stg"${GEN_STG_PASS} > /tmp/ubstgpass
  107. #getting rscriptd encryption password
  108. GEN_RSD_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  109. echo "rsd"${GEN_RSD_PASS} > /tmp/ubrsd
  110. ;;
  111. MIG)
  112. #request previous MySQL/Stargazer/rscriptd passwords
  113. clear
  114. $DIALOG --title "MySQL root password" --inputbox "Enter your previous installation MySQL root password" 8 60 2> /tmp/ubmypass
  115. clear
  116. $DIALOG --title "Stargazer password" --inputbox "Enter your previous installation Stargazer password" 8 60 2> /tmp/ubstgpass
  117. clear
  118. $DIALOG --title "rscriptd password" --inputbox "Enter your previous installation rscriptd password" 8 60 2> /tmp/ubrsd
  119. clear
  120. $DIALOG --title "Ubilling serial" --inputbox "Enter your previous installation Ubilling serial number" 8 60 2> /tmp/ubsrl
  121. ;;
  122. esac
  123. LAN_IFACE=`cat /tmp/ubiface`
  124. MYSQL_PASSWD=`cat /tmp/ubmypass`
  125. LAN_NETW=`cat /tmp/ubnetw`
  126. LAN_CIDR=`cat /tmp/ubcidr`
  127. STG_PASS=`cat /tmp/ubstgpass`
  128. RSD_PASS=`cat /tmp/ubrsd`
  129. ARCH=`cat /tmp/ubarch`
  130. STG_VER=`cat /tmp/stgver`
  131. case $PASSW_MODE in
  132. NEW)
  133. UBSERIAL="auto"
  134. ;;
  135. MIG)
  136. UBSERIAL=`cat /tmp/ubsrl`
  137. ;;
  138. esac
  139. # cleaning temp files
  140. rm -fr /tmp/ubiface
  141. rm -fr /tmp/ubmypass
  142. rm -fr /tmp/ubnetw
  143. rm -fr /tmp/ubcidr
  144. rm -fr /tmp/ubstgpass
  145. rm -fr /tmp/ubrsd
  146. rm -fr /tmp/ubextif
  147. rm -fr /tmp/ubarch
  148. rm -fr /tmp/stgver
  149. rm -fr /tmp/insttype
  150. rm -fr /tmp/ubsrl
  151. #last chance to exit
  152. $DIALOG --title "Check settings" --yesno "Are all of these settings correct? \n \n LAN interface: ${LAN_IFACE} \n LAN network: ${LAN_NETW}/${LAN_CIDR} \n WAN interface: ${EXT_IF} \n MySQL password: ${MYSQL_PASSWD} \n Stargazer password: ${STG_PASS} \n Rscripd password: ${RSD_PASS} \n System: ${ARCH} \n Stargazer: ${STG_VER}\n Ubilling serial: ${UBSERIAL}\n" 18 60
  153. AGREE=$?
  154. clear
  155. case $AGREE in
  156. 0)
  157. echo "Everything is okay! Installation is starting."
  158. # preparing for installation
  159. mkdir /usr/local/ubinstaller/
  160. cp -R ./* /usr/local/ubinstaller/
  161. cd /usr/local/ubinstaller/
  162. #######################################
  163. # Platform specific issues handling #
  164. #######################################
  165. #FreeBSD 10+ need to use CC and CXX env with clang
  166. export CC=/usr/bin/clang
  167. export CXX=/usr/bin/clang++
  168. #FreeBSD 13.3/14.0 requires specific CXXFLAGS env
  169. export CXXFLAGS=-std=c++11
  170. case $ARCH in
  171. 140_6K)
  172. #14.0K contains PHP 8.3 binaries
  173. APACHE_CONFIG_PRESET_NAME="httpd24f8.conf"
  174. PHP_CONFIG_PRESET="php8.ini"
  175. # FreeBSD 14.0 requires custom clang flags
  176. # or gcc13 build
  177. # export CC=/usr/local/bin/gcc13
  178. # export CXX=/usr/local/bin/g++13
  179. # export LD=/usr/local/bin/g++13
  180. # export CXXFLAGS=-std=c++11
  181. ;;
  182. esac
  183. #botstrapping pkg ng
  184. pkg info
  185. #=======================================================
  186. #Selecting stargazer release to install
  187. case $STG_VER in
  188. 409RC5)
  189. DL_STG_NAME="stg-2.409-rc5.tar.gz"
  190. DL_STG_RELEASE="stg-2.409-rc5"
  191. ;;
  192. 409RC2)
  193. DL_STG_NAME="stg-2.409-rc2.tar.gz"
  194. DL_STG_RELEASE="stg-2.409-rc2"
  195. ;;
  196. 409REL)
  197. DL_STG_NAME="stg-2.409.tar.gz"
  198. DL_STG_RELEASE="stg-2.409"
  199. ;;
  200. esac
  201. #check is FreeBSD installation clean
  202. PKG_COUNT=`/usr/sbin/pkg info | /usr/bin/wc -l`
  203. if [ $PKG_COUNT -ge 2 ]
  204. then
  205. echo "UBinstaller supports setup only for clean FreeBSD distribution. Installation is aborted."
  206. exit
  207. fi
  208. # install prebuilded binary packages
  209. $DIALOG --infobox "Software installation is in progress. This takes a while." 4 60
  210. cd packages
  211. $FETCH ${DL_PACKAGES_URL}${ARCH}${DL_PACKAGES_EXT}
  212. #check is binary packages download has beed completed
  213. if [ -f ${ARCH}${DL_PACKAGES_EXT} ];
  214. then
  215. echo "Binary packages download has been completed."
  216. else
  217. echo "=== Error: binary packages are not available. Installation is aborted. ==="
  218. exit
  219. fi
  220. tar zxvf ${ARCH}${DL_PACKAGES_EXT} 2>> /var/log/ubinstaller.log
  221. cd ${ARCH}
  222. ls -1 | xargs -n 1 pkg add >> /var/log/ubinstaller.log
  223. #back to installation directory
  224. cd /usr/local/ubinstaller/
  225. #installing stargazer
  226. $DIALOG --infobox "Stargazer download is in progress." 4 60
  227. cd ./distfiles/
  228. $FETCH ${DL_STG_URL}${DL_STG_NAME}
  229. #check is stargazer sources download complete
  230. if [ -f ${DL_STG_NAME} ];
  231. then
  232. echo "Stargazer distro download has been completed."
  233. else
  234. echo "=== Error: stargazer sources are not available. Installation is aborted. ==="
  235. exit
  236. fi
  237. $DIALOG --infobox "Compiling Stargazer." 4 60
  238. tar zxvf ${DL_STG_NAME} 2>> /var/log/ubinstaller.log
  239. $DIALOG --infobox "Compiling Stargazer.." 4 60
  240. cd ${DL_STG_RELEASE}/projects/stargazer/
  241. ./build >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  242. /usr/local/bin/gmake install >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  243. $DIALOG --infobox "Compiling Stargazer..." 4 60
  244. #and configurators
  245. cd ../sgconf
  246. ./build >> /var/log/ubinstaller.log
  247. /usr/local/bin/gmake >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  248. /usr/local/bin/gmake install >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  249. $DIALOG --infobox "Compiling Stargazer...." 4 60
  250. cd ../sgconf_xml/
  251. ./build >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  252. /usr/local/bin/gmake >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  253. $DIALOG --infobox "Compiling Stargazer....." 4 60
  254. /usr/local/bin/gmake install >> /var/log/ubinstaller.log 2>> /var/log/ubinstaller.log
  255. $DIALOG --infobox "Stargazer installed." 4 60
  256. # adding needed boot options
  257. cat /usr/local/ubinstaller/configs/rc.preconf >> /etc/rc.conf
  258. perl -e "s/LAN_IFACE/${LAN_IFACE}/g" -pi /etc/rc.conf
  259. # copying prepared configs
  260. cd /usr/local/ubinstaller/configs/
  261. cp -R ${APACHE_CONFIG_PRESET_NAME} ${APACHE_CONFIG_DIR}${APACHE_CONFIG_NAME}
  262. cp -R ${PHP_CONFIG_PRESET} /usr/local/etc/php.ini
  263. cp -R stargazer.conf /etc/stargazer/
  264. cp -R bandwidthd.conf /usr/local/bandwidthd/etc/
  265. #setting up default web awesomeness
  266. cp -R inside.html ${APACHE_DATA_PATH}/index.html
  267. # database specific issues handling
  268. case $ARCH in
  269. 133_6K)
  270. # MySQL 8.0 requires custom config
  271. cp -R 80_my.cnf /usr/local/etc/mysql/my.cnf
  272. echo "MySQL 8.0 config replaced"
  273. ;;
  274. 134_6K)
  275. # MySQL 8.0 requires custom config
  276. cp -R 80_my.cnf /usr/local/etc/mysql/my.cnf
  277. echo "MySQL 8.0 config replaced"
  278. ;;
  279. 140_6K)
  280. # MySQL 8.0 requires custom config
  281. cp -R 80_my.cnf /usr/local/etc/mysql/my.cnf
  282. echo "MySQL 8.0 config replaced"
  283. ;;
  284. 141_6K)
  285. # MySQL 8.0 requires custom config
  286. cp -R 80_my.cnf /usr/local/etc/mysql/my.cnf
  287. echo "MySQL 8.0 config replaced"
  288. ;;
  289. esac
  290. # start services
  291. ${APACHE_INIT_SCRIPT} start
  292. /usr/local/etc/rc.d/mysql-server start
  293. #Setting MySQL root password
  294. mysqladmin -u root password ${MYSQL_PASSWD}
  295. ######################
  296. # unpacking Ubilling
  297. ######################
  298. $DIALOG --infobox "Ubilling download, unpacking and installation is in progress." 4 60
  299. cd /usr/local/ubinstaller/distfiles/
  300. $FETCH ${DL_UB_URL}${DL_UB_NAME}
  301. #check is ubilling distro download complete
  302. if [ -f ${DL_UB_NAME} ];
  303. then
  304. echo "Ubilling download has been completed."
  305. else
  306. echo "=== Error: Ubilling release is not available. Installation is aborted. ==="
  307. exit
  308. fi
  309. mkdir ${APACHE_DATA_PATH}billing/
  310. cp ${DL_UB_NAME} ${APACHE_DATA_PATH}billing/
  311. cd ${APACHE_DATA_PATH}billing/
  312. tar zxvf ${DL_UB_NAME} 2>> /var/log/ubinstaller.log
  313. chmod -R 777 content/ config/ multinet/ exports/ remote_nas.conf
  314. chmod -R 777 userstats/config/
  315. # updating passwords and login in mysql.ini
  316. perl -e "s/mylogin/root/g" -pi ./config/mysql.ini
  317. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./config/mysql.ini
  318. #userstats
  319. perl -e "s/mylogin/root/g" -pi ./userstats/config/mysql.ini
  320. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./userstats/config/mysql.ini
  321. #alter
  322. perl -e "s/rl0/${LAN_IFACE}/g" -pi ./config/alter.ini
  323. # and in stargazer.conf
  324. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi /etc/stargazer/stargazer.conf
  325. # change rscriptd password
  326. perl -e "s/secretpassword/${RSD_PASS}/g" -pi /etc/stargazer/stargazer.conf
  327. # change default mukrotik presets password
  328. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./docs/presets/MikroTik/config.ini
  329. # OpenPayz may be?
  330. perl -e "s/mylogin/root/g" -pi ./docs/openpayz/config/mysql.ini
  331. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./docs/openpayz/config/mysql.ini
  332. # creating stargazer database
  333. $DIALOG --infobox "Creating initial Stargazer DB" 4 60
  334. cat docs/dumps/stargazer.sql | /usr/local/bin/mysql -u root --password=${MYSQL_PASSWD}
  335. # starting stargazer
  336. $DIALOG --infobox "Starting Stargazer" 4 60
  337. /usr/sbin/stargazer
  338. #changing stargazer admin default password
  339. /usr/sbin/sgconf_xml -s localhost -p 5555 -a admin -w 123456 -r " <ChgAdmin Login=\"admin\" password=\"${STG_PASS}\" /> "
  340. $DIALOG --infobox "Stargazer default password changed." 4 60
  341. #stopping stargazer
  342. $DIALOG --infobox "Stopping Stargazer." 4 60
  343. killall stargazer
  344. # restoring clean ubilling SQL dump
  345. $DIALOG --infobox "Restoring Ubilling database" 4 60
  346. cat docs/dumps/ubilling.sql | /usr/local/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  347. $DIALOG --infobox "Installing OpenPayz database preset" 4 60
  348. cat docs/dumps/openpayz.sql | /usr/local/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  349. # apply hotfix for stargazer 2.408 and change passwords in configs
  350. cat /usr/local/ubinstaller/configs/admin_rights_hotfix.sql | /usr/local/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  351. perl -e "s/123456/${STG_PASS}/g" -pi ./config/billing.ini
  352. perl -e "s/123456/${STG_PASS}/g" -pi ./userstats/config/userstats.ini
  353. perl -e "s/123456/${STG_PASS}/g" -pi ./docs/openpayz/config/openpayz.ini
  354. #preconfiguring dhcpd logging
  355. cat /usr/local/ubinstaller/configs/syslog.preconf >> /etc/syslog.conf
  356. touch /var/log/dhcpd.log
  357. /usr/local/etc/rc.d/isc-dhcpd restart > /dev/null 2> /dev/null
  358. /etc/rc.d/syslogd restart > /dev/null
  359. perl -e "s/NMLEASES = \/var\/log\/messages/NMLEASES = \/var\/log\/dhcpd.log/g" -pi ./config/alter.ini
  360. $DIALOG --infobox "dhcpd logging configured." 4 60
  361. #first install flag setup for the future
  362. touch ./exports/FIRST_INSTALL
  363. chmod 777 ./exports/FIRST_INSTALL
  364. # unpacking ubapi preset
  365. cp -R /usr/local/ubinstaller/configs/ubapi /bin/
  366. chmod a+x /bin/ubapi
  367. $DIALOG --infobox "remote API wrapper installed" 4 60
  368. # unpacking start scripts templates
  369. cp -f docs/presets/FreeBSD/etc/stargazer/* /etc/stargazer/
  370. chmod a+x /etc/stargazer/*
  371. echo "default user initialization scripts installed."
  372. # changing mysql and interface parameters
  373. perl -e "s/mylogin/root/g" -pi /etc/stargazer/config
  374. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi /etc/stargazer/config
  375. perl -e "s/rl0/${LAN_IFACE}/g" -pi /etc/stargazer/OnConnect
  376. perl -e "s/em0/${LAN_IFACE}/g" -pi /usr/local/bandwidthd/etc/bandwidthd.conf
  377. perl -e "s/NETW/${LAN_NETW}\/${LAN_CIDR}/g" -pi /usr/local/bandwidthd/etc/bandwidthd.conf
  378. #editing sudoers
  379. echo "User_Alias BILLING = www" >> /usr/local/etc/sudoers
  380. echo "BILLING ALL = NOPASSWD: ALL" >> /usr/local/etc/sudoers
  381. #symlink magic
  382. mkdir /etc/stargazer/dn
  383. chmod -R 777 /etc/stargazer/dn
  384. ln -fs ${APACHE_DATA_PATH}billing/multinet /usr/local/etc/multinet
  385. ln -fs ${APACHE_DATA_PATH}billing/remote_nas.conf /etc/stargazer/remote_nas.conf
  386. mkdir ${APACHE_DATA_PATH}billing/content/dn
  387. chmod 777 ${APACHE_DATA_PATH}billing/content/dn
  388. ln -fs /usr/local/bandwidthd/htdocs ${APACHE_DATA_PATH}band
  389. #creating rc.script
  390. cp -R /usr/local/ubinstaller/configs/rc.billing /usr/local/etc/rc.d/billing
  391. chmod a+x /usr/local/etc/rc.d/billing
  392. $DIALOG --infobox "Ubilling rc script installed." 4 60
  393. #ugly hack for starting stargazer without NAS-es
  394. echo "127.0.0.1/32 127.0.0.1" > /etc/stargazer/remote_nas.conf
  395. #kernel options setup
  396. case $NAS_KERNEL in
  397. 0)
  398. cat /usr/local/ubinstaller/configs/loader.preconf >> /boot/loader.conf
  399. cp -R /usr/local/ubinstaller/configs/firewall.conf /etc/
  400. chmod a+x /etc/firewall.conf
  401. cat /usr/local/ubinstaller/configs/rc-fw.preconf >> /etc/rc.conf
  402. cat /usr/local/ubinstaller/configs/sysctl.preconf >> /etc/sysctl.conf
  403. #update settings in firewall sample
  404. perl -e "s/USERS_NET/${LAN_NETW}/g" -pi /etc/firewall.conf
  405. perl -e "s/CIDR/${LAN_CIDR}/g" -pi /etc/firewall.conf
  406. perl -e "s/EXT_IF/${EXT_IF}/g" -pi /etc/firewall.conf
  407. perl -e "s/INT_IF/${LAN_IFACE}/g" -pi /etc/firewall.conf;;
  408. 1)
  409. echo "no NAS setup required";;
  410. esac
  411. #disabling mysql>=5.6 strict trans tables in various config locations
  412. if [ -f /usr/local/my.cnf ];
  413. then
  414. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/my.cnf
  415. echo "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/my.cnf done"
  416. else
  417. echo "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/my.cnf"
  418. fi
  419. if [ -f /usr/local/etc/my.cnf ];
  420. then
  421. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/etc/my.cnf
  422. echo "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/etc/my.cnf done"
  423. else
  424. echo "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/etc/my.cnf"
  425. fi
  426. if [ -f /usr/local/etc/mysql/my.cnf ];
  427. then
  428. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/etc/mysql/my.cnf
  429. echo "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/etc/mysql/my.cnf done"
  430. else
  431. echo "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/etc/mysql/my.cnf"
  432. fi
  433. #Multigen/FreeRADIUS3 preconfiguration
  434. cd ${APACHE_DATA_PATH}billing
  435. cp -R ./docs/multigen/raddb3/* /usr/local/etc/raddb/
  436. RADVER=`radiusd -v | grep "radiusd: FreeRADIUS Version" | awk '{print $4}' | tr -d ,`
  437. sed -i.bak "s/\/usr\/local\/lib\/freeradius-3.0.16/\/usr\/local\/lib\/freeradius-${RADVER}/" /usr/local/etc/raddb/radiusd.conf
  438. cat ./docs/multigen/dump.sql | /usr/local/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  439. cat ./docs/multigen/radius3_fix.sql | /usr/local/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  440. perl -e "s/yourmysqlpassword/${MYSQL_PASSWD}/g" -pi /usr/local/etc/raddb/sql.conf
  441. #adding current hostname to fix resolve issues
  442. CURR_HOSTNAME=`hostname`
  443. echo "127.0.0.1 ${CURR_HOSTNAME} ${CURR_HOSTNAME}.localdomain" >> /etc/hosts
  444. #starting stargazer
  445. $DIALOG --infobox "Starting Stargazer" 4 60
  446. /usr/sbin/stargazer
  447. #initial crontab configuration
  448. cd ${APACHE_DATA_PATH}billing
  449. if [ -f ./docs/crontab/crontab.preconf ];
  450. then
  451. #generating new Ubilling serial or using predefined
  452. case $PASSW_MODE in
  453. NEW)
  454. /usr/local/bin/curl -o /dev/null "http://127.0.0.1/billing/?module=remoteapi&action=identify&param=save"
  455. NEW_UBSERIAL=`cat ./exports/ubserial`
  456. $DIALOG --infobox "New Ubilling serial generated: ${NEW_UBSERIAL}" 4 60
  457. ;;
  458. MIG)
  459. NEW_UBSERIAL=${UBSERIAL}
  460. $DIALOG --infobox "Using Ubilling serial: ${NEW_UBSERIAL}" 4 60
  461. ;;
  462. esac
  463. #loading default crontab preset
  464. crontab ./docs/crontab/crontab.preconf
  465. $DIALOG --infobox "Installing default crontab preset" 4 60
  466. #updating serial in ubapi wrapper
  467. perl -e "s/UB000000000000000000000000000000000/${NEW_UBSERIAL}/g" -pi /bin/ubapi
  468. $DIALOG --infobox "New serial installed into ubapi wrapper" 4 60
  469. else
  470. echo "Looks like this Ubilling release is not supporting automatic crontab configuration"
  471. fi
  472. #installing default htaccess file with compression and client-side cachig optimizations
  473. cd ${APACHE_DATA_PATH}billing
  474. if [ -f ./docs/webspeed/speed_hta ];
  475. then
  476. cp -R ./docs/webspeed/speed_hta ${APACHE_DATA_PATH}billing/.htaccess
  477. else
  478. echo "Looks like this Ubilling release does not containing default htaccess preset"
  479. fi
  480. #stopping stargazer again to prevent data corruption and force server rebooting
  481. $DIALOG --infobox "Stopping stargazer" 4 60
  482. killall stargazer
  483. # Setting up autoupdate script
  484. if [ -f ./docs/presets/FreeBSD/ubautoupgrade.sh ];
  485. then
  486. cp -R ./docs/presets/FreeBSD/ubautoupgrade.sh /bin/
  487. chmod a+x /bin/ubautoupgrade.sh
  488. else
  489. echo "Looks like this Ubilling release does not containing automatic upgrade preset"
  490. fi
  491. $DIALOG --title "Ubilling installation has been completed" --msgbox "Now you can access your web-interface by address http://server_ip/billing/ with login and password: admin/demo. Please reboot your server to check correct startup of all services" 15 50
  492. ;;
  493. 1)
  494. echo "Installation has been aborted"
  495. exit
  496. ;;
  497. esac
  498. # I am the chosen one, keep till the rising sun