Debianstaller.sh 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. #!/usr/bin/bash
  2. #some predefined paths and URLs here
  3. DIALOG="dialog"
  4. FETCH="/usr/bin/wget"
  5. TARGET_SYSTEM="Debian 12 Bookworm"
  6. APACHE_VERSION="apache24"
  7. APACHE_DATA_PATH="/var/www/html/"
  8. APACHE_CONFIG_DIR="/etc/apache2/"
  9. APACHE_INIT_SCRIPT="/usr/sbin/service apache2"
  10. APACHE_CONFIG_PRESET_NAME="debi12_apache2.conf"
  11. APACHE_CONFIG_NAME="apache2.conf"
  12. #some remote paths here
  13. DL_PACKAGES_URL="http://ubilling.net.ua/packages/"
  14. DL_PACKAGES_EXT=".tar.gz"
  15. DL_UB_URL="http://ubilling.net.ua/"
  16. DL_UB_NAME="ub.tgz"
  17. DL_STG_URL="http://ubilling.net.ua/stg/"
  18. DL_STG_NAME="stg-2.409-rc5.tar.gz"
  19. DL_STG_RELEASE="stg-2.409-rc5"
  20. #initial repos update
  21. echo "Preparing to installation.."
  22. apt update >> /var/log/debianstaller.log 2>&1
  23. apt -y upgrade >> /var/log/debianstaller.log 2>&1
  24. #installation of basic software required for installer
  25. echo "Installing basic software required for Debianstaller.."
  26. apt install -y dialog >> /var/log/debianstaller.log 2>&1
  27. apt install -y net-tools >> /var/log/debianstaller.log 2>&1
  28. apt install -y gnupg2 >> /var/log/debianstaller.log 2>&1
  29. clear
  30. $DIALOG --title "Ubilling installation" --msgbox "This wizard helps you to install Stargazer and Ubilling to your server with ${TARGET_SYSTEM}. This installer is experimental(!) and not recommended for real usage at this moment." 10 50
  31. clear
  32. #new or migration installation
  33. clear
  34. $DIALOG --menu "Type of Ubilling installation" 10 75 8 \
  35. NEW "This is new Ubilling installation"\
  36. MIG "Migrating existing Ubilling setup from another server"\
  37. 2> /tmp/insttype
  38. clear
  39. #configuring stargazer release
  40. clear
  41. $DIALOG --menu "Choose Stargazer release" 16 50 8 \
  42. 409REL "Stargazer 2.409-release (stable)"\
  43. 409RC5 "Stargazer 2.409-rc5 (legacy)"\
  44. 409RC2 "Stargazer 2.409-rc2 (legacy)"\
  45. 2> /tmp/stgver
  46. clear
  47. #configuring LAN interface
  48. ALL_IFACES=`basename -a /sys/class/net/* | grep -v lo | tr "\n" " "`
  49. INTIF_DIALOG_START="$DIALOG --menu \"Select LAN interface that interracts with your INTERNAL network\" 15 85 6 \\"
  50. INTIF_DIALOG="${INTIF_DIALOG_START}"
  51. for EACH_IFACE in $ALL_IFACES
  52. do
  53. LIIFACE_IP=`ifconfig ${EACH_IFACE} | grep "inet " | xargs`
  54. INTIF_DIALOG="${INTIF_DIALOG}${EACH_IFACE} \\ \"${LIIFACE_IP}\" "
  55. done
  56. INTIF_DIALOG="${INTIF_DIALOG} 2> /tmp/ubiface"
  57. sh -c "${INTIF_DIALOG}"
  58. clear
  59. #configuring internal network
  60. TMP_LAN_IFACE=`cat /tmp/ubiface`
  61. TMP_NET_DATA=`netstat -rn -f inet | grep -v UG | grep ${TMP_LAN_IFACE}`
  62. TMP_LAN_NETW=`echo ${TMP_NET_DATA} | cut -f 1 -d " "`
  63. TMP_LAN_CIDR=`ip address show dev ${TMP_LAN_IFACE} | grep "inet " | cut -f 2 -d "/" | cut -f 1 -d " " | xargs`
  64. echo ${TMP_LAN_NETW} > /tmp/ubnetw
  65. echo ${TMP_LAN_CIDR} > /tmp/ubcidr
  66. #NAT etc presets setup
  67. clear
  68. $DIALOG --title "Setup NAS" --yesno "Do you want to install firewall/nat/shaper presets for setup all-in-one Billing+NAS server" 10 40
  69. NAS_KERNEL=$?
  70. clear
  71. case $NAS_KERNEL in
  72. 0)
  73. #NAS kernel setup with preconfigured firewall
  74. #configuring WAN interface
  75. ALL_IFACES=`basename -a /sys/class/net/* | grep -v lo | tr "\n" " "`
  76. EXTIF_DIALOG_START="$DIALOG --menu \"Select WAN interface for NAT that interracts with Internet\" 15 85 6 \\"
  77. EXTIF_DIALOG="${EXTIF_DIALOG_START}"
  78. for EACH_IFACE in $ALL_IFACES
  79. do
  80. LIIFACE_IP=`ifconfig ${EACH_IFACE} | grep "inet " | xargs`
  81. EXTIF_DIALOG="${EXTIF_DIALOG}${EACH_IFACE} \\ \"${LIIFACE_IP}\" "
  82. done
  83. EXTIF_DIALOG="${EXTIF_DIALOG} 2> /tmp/ubextif"
  84. sh -c "${EXTIF_DIALOG}"
  85. clear
  86. EXT_IF=`cat /tmp/ubextif`
  87. ;;
  88. 1)
  89. EXT_IF="none"
  90. ;;
  91. esac
  92. #some passwords generation or manual input
  93. PASSW_MODE=`cat /tmp/insttype`
  94. case $PASSW_MODE in
  95. NEW)
  96. #generating mysql password
  97. GEN_MYS_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5sum | cut -b-8`
  98. echo "mys"${GEN_MYS_PASS} > /tmp/ubmypass
  99. #getting stargazer admin password
  100. GEN_STG_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5sum | cut -b-8`
  101. echo "stg"${GEN_STG_PASS} > /tmp/ubstgpass
  102. #getting rscriptd encryption password
  103. GEN_RSD_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5sum | cut -b-8`
  104. echo "rsd"${GEN_RSD_PASS} > /tmp/ubrsd
  105. ;;
  106. MIG)
  107. request previous MySQL/Stargazer/rscriptd passwords
  108. clear
  109. $DIALOG --title "MySQL root password" --inputbox "Enter your previous installation MySQL root password" 8 60 2> /tmp/ubmypass
  110. clear
  111. $DIALOG --title "Stargazer password" --inputbox "Enter your previous installation Stargazer password" 8 60 2> /tmp/ubstgpass
  112. clear
  113. $DIALOG --title "rscriptd password" --inputbox "Enter your previous installation rscriptd password" 8 60 2> /tmp/ubrsd
  114. clear
  115. $DIALOG --title "Ubilling serial" --inputbox "Enter your previous installation Ubilling serial number" 8 60 2> /tmp/ubsrl
  116. ;;
  117. esac
  118. LAN_IFACE=`cat /tmp/ubiface`
  119. MYSQL_PASSWD=`cat /tmp/ubmypass`
  120. LAN_NETW=`cat /tmp/ubnetw`
  121. LAN_CIDR=`cat /tmp/ubcidr`
  122. STG_PASS=`cat /tmp/ubstgpass`
  123. RSD_PASS=`cat /tmp/ubrsd`
  124. ARCH=`hostnamectl | grep System | xargs`
  125. STG_VER=`cat /tmp/stgver`
  126. case $PASSW_MODE in
  127. NEW)
  128. UBSERIAL="auto"
  129. ;;
  130. MIG)
  131. UBSERIAL=`cat /tmp/ubsrl`
  132. ;;
  133. esac
  134. # cleaning temp files
  135. rm -fr /tmp/ubiface
  136. rm -fr /tmp/ubmypass
  137. rm -fr /tmp/ubnetw
  138. rm -fr /tmp/ubcidr
  139. rm -fr /tmp/ubstgpass
  140. rm -fr /tmp/ubrsd
  141. rm -fr /tmp/ubextif
  142. rm -fr /tmp/stgver
  143. rm -fr /tmp/insttype
  144. rm -fr /tmp/ubsrl
  145. #last chance to exit
  146. $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 70
  147. AGREE=$?
  148. clear
  149. case $AGREE in
  150. 0)
  151. $DIALOG --infobox "Everything is okay! Installation is starting..." 4 60
  152. mkdir /usr/local/ubinstaller/
  153. cp -R ./* /usr/local/ubinstaller/
  154. cd /usr/local/ubinstaller/
  155. #Selecting stargazer release to install
  156. case $STG_VER in
  157. 409RC5)
  158. DL_STG_NAME="stg-2.409-rc5.tar.gz"
  159. DL_STG_RELEASE="stg-2.409-rc5"
  160. ;;
  161. 409RC2)
  162. DL_STG_NAME="stg-2.409-rc2.tar.gz"
  163. DL_STG_RELEASE="stg-2.409-rc2"
  164. ;;
  165. 409REL)
  166. DL_STG_NAME="stg-2.409.tar.gz"
  167. DL_STG_RELEASE="stg-2.409"
  168. ;;
  169. esac
  170. # install binary packages from repos
  171. $DIALOG --infobox "Software installation is in progress. This takes a while." 4 70
  172. #MariaDB setup
  173. apt install -y software-properties-common dirmngr >> /var/log/debianstaller.log 2>&1
  174. $DIALOG --infobox "Installing MariaDB" 4 60
  175. #old way
  176. #${FETCH} https://mariadb.org/mariadb_release_signing_key.asc >> /var/log/debianstaller.log 2>&1
  177. #chmod -c 644 mariadb_release_signing_key.asc >> /var/log/debianstaller.log 2>&1
  178. #mv -v mariadb_release_signing_key.asc /etc/apt/trusted.gpg.d/ >> /var/log/debianstaller.log 2>&1
  179. $DIALOG --infobox "Installing MariaDB." 4 60
  180. #old way too
  181. #echo "deb [arch=amd64,arm64,ppc64el] \
  182. #https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.0.2/debian \
  183. #bullseye main" | tee /etc/apt/sources.list.d/mariadb.list >> /var/log/debianstaller.log 2>&1
  184. $DIALOG --infobox "Installing MariaDB.." 4 60
  185. #apt update >> /var/log/debianstaller.log 2>&1
  186. $DIALOG --infobox "Installing MariaDB..." 4 60
  187. apt install -y mariadb-server >> /var/log/debianstaller.log 2>&1
  188. $DIALOG --infobox "Installing MariaDB...." 4 60
  189. apt install -y mariadb-client >> /var/log/debianstaller.log 2>&1
  190. $DIALOG --infobox "Installing MariaDB....." 4 60
  191. apt install -y libmariadb-dev >> /var/log/debianstaller.log 2>&1
  192. $DIALOG --infobox "Installing MariaDB......" 4 60
  193. apt install -y default-libmysqlclient-dev >> /var/log/debianstaller.log 2>&1
  194. $DIALOG --infobox "MariaDB installed" 4 60
  195. mariadb --version >> /var/log/debianstaller.log 2>&1
  196. systemctl start mariadb >> /var/log/debianstaller.log 2>&1
  197. systemctl enable mariadb >> /var/log/debianstaller.log 2>&1
  198. $DIALOG --infobox "MariaDB startup enabled" 4 60
  199. $DIALOG --infobox "Installing some required software" 4 60
  200. apt install -y expat >> /var/log/debianstaller.log 2>&1
  201. apt install -y libexpat1-dev >> /var/log/debianstaller.log 2>&1
  202. apt install -y sudo >> /var/log/debianstaller.log 2>&1
  203. apt install -y curl >> /var/log/debianstaller.log 2>&1
  204. $DIALOG --infobox "Installing Apache server" 4 60
  205. apt install -y apache2 >> /var/log/debianstaller.log 2>&1
  206. apt install -y libapache2-mod-php8.2 >> /var/log/debianstaller.log 2>&1
  207. $DIALOG --infobox "Installing DHCP server" 4 60
  208. apt install -y isc-dhcp-server >> /var/log/debianstaller.log 2>&1
  209. $DIALOG --infobox "Installing misc software" 4 60
  210. apt install -y build-essential >> /var/log/debianstaller.log 2>&1
  211. apt install -y bind9 >> /var/log/debianstaller.log 2>&1
  212. DEBIAN_FRONTEND=noninteractive apt install -y bandwidthd >> /var/log/debianstaller.log 2>&1
  213. DEBIAN_FRONTEND=noninteractive apt install -y softflowd >> /var/log/debianstaller.log 2>&1
  214. apt install -y libxmlrpc-c++8-dev >> /var/log/debianstaller.log 2>&1
  215. apt install -y ipset >> /var/log/debianstaller.log 2>&1
  216. $DIALOG --infobox "Installing memory caching servers" 4 60
  217. apt install -y memcached >> /var/log/debianstaller.log 2>&1
  218. apt install -y redis >> /var/log/debianstaller.log 2>&1
  219. $DIALOG --infobox "Installing PHP and required extensions" 4 60
  220. apt install -y php8.2-cli >> /var/log/debianstaller.log 2>&1
  221. apt install -y php8.2-mysql >> /var/log/debianstaller.log 2>&1
  222. apt install -y php8.2-mysqli >> /var/log/debianstaller.log 2>&1
  223. apt install -y php8.2-mbstring >> /var/log/debianstaller.log 2>&1
  224. apt install -y php8.2-bcmath >> /var/log/debianstaller.log 2>&1
  225. apt install -y php8.2-curl >> /var/log/debianstaller.log 2>&1
  226. apt install -y php8.2-gd >> /var/log/debianstaller.log 2>&1
  227. apt install -y php8.2-snmp >> /var/log/debianstaller.log 2>&1
  228. apt install -y php8.2-soap >> /var/log/debianstaller.log 2>&1
  229. apt install -y php8.2-zip >> /var/log/debianstaller.log 2>&1
  230. apt install -y php8.2-imap >> /var/log/debianstaller.log 2>&1
  231. apt install -y php8.2-json >> /var/log/debianstaller.log 2>&1
  232. apt install -y php8.2-tokenizer >> /var/log/debianstaller.log 2>&1
  233. apt install -y php8.2-xml >> /var/log/debianstaller.log 2>&1
  234. apt install -y php8.2-xmlreader >> /var/log/debianstaller.log 2>&1
  235. apt install -y php8.2-xmlwriter >> /var/log/debianstaller.log 2>&1
  236. apt install -y php8.2-simplexml >> /var/log/debianstaller.log 2>&1
  237. apt install -y php8.2-sqlite3 >> /var/log/debianstaller.log 2>&1
  238. apt install -y php8.2-sockets >> /var/log/debianstaller.log 2>&1
  239. apt install -y php8.2-opcache >> /var/log/debianstaller.log 2>&1
  240. apt install -y php8.2-json >> /var/log/debianstaller.log 2>&1
  241. apt install -y php8.2-pdo >> /var/log/debianstaller.log 2>&1
  242. apt install -y php8.2-pdo-sqlite >> /var/log/debianstaller.log 2>&1
  243. apt install -y php8.2-phar >> /var/log/debianstaller.log 2>&1
  244. apt install -y php8.2-posix >> /var/log/debianstaller.log 2>&1
  245. apt install -y php8.2-memcached >> /var/log/debianstaller.log 2>&1
  246. apt install -y php8.2-redis >> /var/log/debianstaller.log 2>&1
  247. $DIALOG --infobox "Installing some optional software" 4 60
  248. apt install -y graphviz >> /var/log/debianstaller.log 2>&1
  249. apt install -y vim-tiny >> /var/log/debianstaller.log 2>&1
  250. apt install -y arping >> /var/log/debianstaller.log 2>&1
  251. apt install -y elinks >> /var/log/debianstaller.log 2>&1
  252. apt install -y mc >> /var/log/debianstaller.log 2>&1
  253. apt install -y nano >> /var/log/debianstaller.log 2>&1
  254. apt install -y nmap >> /var/log/debianstaller.log 2>&1
  255. apt install -y mtr >> /var/log/debianstaller.log 2>&1
  256. apt install -y expect >> /var/log/debianstaller.log 2>&1
  257. apt install -y bwm-ng >> /var/log/debianstaller.log 2>&1
  258. apt install -y ifstat >> /var/log/debianstaller.log 2>&1
  259. #apt install -y iperf >> /var/log/debianstaller.log 2>&1
  260. #apt install -y iperf3 >> /var/log/debianstaller.log 2>&1
  261. apt install -y arpwatch >> /var/log/debianstaller.log 2>&1
  262. apt install -y git >> /var/log/debianstaller.log 2>&1
  263. apt install -y ffmpeg >> /var/log/debianstaller.log 2>&1
  264. apt install -y bmon >> /var/log/debianstaller.log 2>&1
  265. apt install -y iftop >> /var/log/debianstaller.log 2>&1
  266. apt install -y netdiag >> /var/log/debianstaller.log 2>&1
  267. apt install -y htop >> /var/log/debianstaller.log 2>&1
  268. apt install -y rsyslog >> /var/log/debianstaller.log 2>&1
  269. $DIALOG --infobox "Installing FreeRADIUS server" 4 60
  270. apt install -y freeradius freeradius-mysql >> /var/log/debianstaller.log 2>&1
  271. #back to installation directory
  272. cd /usr/local/ubinstaller/
  273. #installing stargazer
  274. $DIALOG --infobox "Stargazer download is in progress." 4 60
  275. $FETCH ${DL_STG_URL}${DL_STG_NAME} >> /var/log/debianstaller.log 2>&1
  276. if [ -f ${DL_STG_NAME} ];
  277. then
  278. $DIALOG --infobox "Stargazer distro download has been completed." 4 60
  279. else
  280. echo "=== Error: stargazer sources are not available. Installation is aborted. ==="
  281. exit
  282. fi
  283. $DIALOG --infobox "Compiling Stargazer." 4 60
  284. tar zxvf ${DL_STG_NAME} >> /var/log/debianstaller.log 2>&1
  285. cd ${DL_STG_RELEASE}/projects/stargazer/
  286. ./build >> /var/log/debianstaller.log 2>&1
  287. /usr/bin/gmake install >> /var/log/debianstaller.log 2>&1
  288. $DIALOG --infobox "Compiling Stargazer..." 4 60
  289. #and configurators
  290. cd ../sgconf
  291. ./build >> /var/log/debianstaller.log 2>&1
  292. /usr/bin/gmake >> /var/log/debianstaller.log 2>&1
  293. /usr/bin/gmake install >> /var/log/debianstaller.log 2>&1
  294. $DIALOG --infobox "Compiling Stargazer...." 4 60
  295. cd ../sgconf_xml/
  296. ./build >> /var/log/debianstaller.log 2>&1
  297. /usr/bin/gmake >> /var/log/debianstaller.log 2>&1
  298. $DIALOG --infobox "Compiling Stargazer....." 4 60
  299. /usr/bin/gmake install >> /var/log/debianstaller.log 2>&1
  300. $DIALOG --infobox "Stargazer installed." 4 60
  301. #stopping apache
  302. ${APACHE_INIT_SCRIPT} stop
  303. # copying prepared configs
  304. cd /usr/local/ubinstaller/configs/
  305. cp -R ${APACHE_CONFIG_PRESET_NAME} ${APACHE_CONFIG_DIR}${APACHE_CONFIG_NAME}
  306. cp -R php82.ini /etc/php/8.2/apache2/php.ini
  307. cp -R stargazer.conf /etc/stargazer/
  308. cp -R bandwidthd.conf /etc/bandwidthd/bandwidthd.conf
  309. perl -e "s/em0/${LAN_IFACE}/g" -pi /etc/bandwidthd/bandwidthd.conf
  310. perl -e "s/NETW/${LAN_NETW}\/${LAN_CIDR}/g" -pi /etc/bandwidthd/bandwidthd.conf
  311. cp -R sudoers_preset /etc/sudoers.d/ubilling
  312. #setting up default web awesomeness
  313. cp -R inside.html ${APACHE_DATA_PATH}/index.html
  314. #fixing maria issues
  315. service mariadb stop
  316. cp -R 50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf
  317. service mariadb start
  318. #starting apache with new configs
  319. ${APACHE_INIT_SCRIPT} start
  320. #Setting MySQL root password
  321. mysqladmin -u root password ${MYSQL_PASSWD}
  322. ######################
  323. # unpacking Ubilling
  324. ######################
  325. $DIALOG --infobox "Ubilling download, unpacking and installation is in progress." 4 60
  326. cd /usr/local/ubinstaller/
  327. $FETCH ${DL_UB_URL}${DL_UB_NAME} >> /var/log/debianstaller.log 2>&1
  328. #check is ubilling distro download complete
  329. if [ -f ${DL_UB_NAME} ];
  330. then
  331. $DIALOG --infobox "Ubilling download has been completed." 4 60
  332. else
  333. echo "=== Error: Ubilling release is not available. Installation is aborted. ==="
  334. exit
  335. fi
  336. mkdir ${APACHE_DATA_PATH}billing/
  337. cp ${DL_UB_NAME} ${APACHE_DATA_PATH}billing/
  338. cd ${APACHE_DATA_PATH}billing/
  339. tar zxvf ${DL_UB_NAME} >> /var/log/debianstaller.log 2>&1
  340. chmod -R 777 content/ config/ multinet/ exports/ remote_nas.conf
  341. chmod -R 777 userstats/config/
  342. # updating passwords and login in mysql.ini
  343. perl -e "s/mylogin/root/g" -pi ./config/mysql.ini
  344. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./config/mysql.ini
  345. #userstats
  346. perl -e "s/mylogin/root/g" -pi ./userstats/config/mysql.ini
  347. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./userstats/config/mysql.ini
  348. #alter
  349. perl -e "s/rl0/${LAN_IFACE}/g" -pi ./config/alter.ini
  350. # and in stargazer.conf
  351. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi /etc/stargazer/stargazer.conf
  352. # change rscriptd password
  353. perl -e "s/secretpassword/${RSD_PASS}/g" -pi /etc/stargazer/stargazer.conf
  354. # change default Mikrotik presets password
  355. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./docs/presets/MikroTik/config.ini
  356. # OpenPayz may be?
  357. perl -e "s/mylogin/root/g" -pi ./docs/openpayz/config/mysql.ini
  358. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./docs/openpayz/config/mysql.ini
  359. #fixing paths to linux specific
  360. perl -e "s/\/usr\/local\/bin\/sudo/\/usr\/bin\/sudo/g" -pi ./config/billing.ini
  361. perl -e "s/\/usr\/bin\/top -b/\/usr\/bin\/top -b -n1/g" -pi ./config/billing.ini
  362. perl -e "s/\/usr\/local\/etc\/rc.d\/isc-dhcpd/\/etc\/init.d\/isc-dhcp-server/g" -pi ./config/billing.ini
  363. perl -e "s/\/sbin\/ping/\/usr\/bin\/ping/g" -pi ./config/billing.ini
  364. perl -e "s/\/usr\/local\/bin\/wget/\/usr\/bin\/wget/g" -pi ./config/billing.ini
  365. perl -e "s/\/usr\/local\/bin\/expect/\/usr\/bin\/expect/g" -pi ./config/billing.ini
  366. perl -e "s/\/usr\/local\/bin\/mysqldump/\/usr\/bin\/mysqldump/g" -pi ./config/alter.ini
  367. perl -e "s/\/usr\/local\/bin\/mysql/\/usr\/bin\/mysql/g" -pi ./config/alter.ini
  368. perl -e "s/\/usr\/local\/bin\/snmpset/\/usr\/bin\/snmpset/g" -pi ./config/alter.ini
  369. perl -e "s/\/usr\/local\/bin\/snmpwalk/\/usr\/bin\/snmpwalk/g" -pi ./config/alter.ini
  370. perl -e "s/\/usr\/local\/bin\/nmap/\/usr\/bin\/nmap/g" -pi ./config/alter.ini
  371. perl -e "s/\/usr\/local\/bin\/radclient/\/usr\/bin\/radclient/g" -pi ./config/alter.ini
  372. perl -e "s/\/usr\/local\/sbin\/arping/\/usr\/sbin\/arping/g" -pi ./config/alter.ini
  373. perl -e "s/-c 10 -w 20000/-c 10 -W 0.1/g" -pi ./config/alter.ini
  374. #fixing apache rights
  375. chmod -R 777 /var/log/apache2
  376. #creating stargazer database
  377. $DIALOG --infobox "Creating initial Stargazer DB" 4 60
  378. cat docs/dumps/stargazer.sql | /usr/bin/mysql -u root --password=${MYSQL_PASSWD} >> /var/log/debianstaller.log 2>&1
  379. # starting stargazer
  380. $DIALOG --infobox "Starting Stargazer" 4 60
  381. /usr/sbin/stargazer
  382. sleep 3
  383. #changing default password
  384. /usr/sbin/sgconf_xml -s localhost -p 5555 -a admin -w 123456 -r " <ChgAdmin Login=\"admin\" password=\"${STG_PASS}\" /> " >> /var/log/debianstaller.log 2>&1
  385. $DIALOG --infobox "Stargazer default password changed." 4 60
  386. #stopping stargazer
  387. $DIALOG --infobox "Stopping Stargazer." 4 60
  388. killall stargazer
  389. sleep 10
  390. # restoring default Ubilling SQL dump
  391. $DIALOG --infobox "Restoring Ubilling database" 4 60
  392. cat docs/dumps/ubilling.sql | /usr/bin/mysql -u root -p stg --password=${MYSQL_PASSWD} >> /var/log/debianstaller.log 2>&1
  393. $DIALOG --infobox "Installing OpenPayz database preset" 4 60
  394. cat docs/dumps/openpayz.sql | /usr/bin/mysql -u root -p stg --password=${MYSQL_PASSWD} >> /var/log/debianstaller.log 2>&1
  395. # apply hotfix for stargazer 2.408 and change passwords in configs
  396. cat /usr/local/ubinstaller/configs/admin_rights_hotfix.sql | /usr/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  397. perl -e "s/123456/${STG_PASS}/g" -pi ./config/billing.ini
  398. perl -e "s/123456/${STG_PASS}/g" -pi ./userstats/config/userstats.ini
  399. perl -e "s/123456/${STG_PASS}/g" -pi ./docs/openpayz/config/openpayz.ini
  400. #preconfiguring dhcpd logging
  401. cat /usr/local/ubinstaller/configs/rsyslog.preconf >> /etc/rsyslog.conf
  402. perl -e "s/NMLEASES = \/var\/log\/messages/NMLEASES = \/var\/log\/dhcpd.log/g" -pi ./config/alter.ini
  403. $DIALOG --infobox "dhcpd logging configured." 4 60
  404. #first install flag setup for the future
  405. touch ./exports/FIRST_INSTALL
  406. chmod 777 ./exports/FIRST_INSTALL
  407. # unpacking ubapi preset
  408. cp -R /usr/local/ubinstaller/configs/ubapi /bin/
  409. chmod a+x /bin/ubapi
  410. $DIALOG --infobox "remote API wrapper installed" 4 60
  411. #starting stargazer
  412. $DIALOG --infobox "Starting stargazer" 4 60
  413. /usr/sbin/stargazer
  414. sleep 3
  415. #initial crontab configuration
  416. cd ${APACHE_DATA_PATH}billing
  417. if [ -f ./docs/crontab/crontab.preconf ];
  418. then
  419. #generating new Ubilling serial or using predefined
  420. case $PASSW_MODE in
  421. NEW)
  422. #generating new Ubilling serial
  423. /usr/bin/curl -o /dev/null "http://127.0.0.1/billing/?module=remoteapi&action=identify&param=save" >> /var/log/debianstaller.log 2>&1
  424. #waiting saving data
  425. sleep 2
  426. NEW_UBSERIAL=`cat ./exports/ubserial`
  427. $DIALOG --infobox "New Ubilling serial generated: ${NEW_UBSERIAL}" 4 60
  428. ;;
  429. MIG)
  430. NEW_UBSERIAL=${UBSERIAL}
  431. $DIALOG --infobox "Using Ubilling serial: ${NEW_UBSERIAL}" 4 60
  432. ;;
  433. esac
  434. if [ -n "$NEW_UBSERIAL" ];
  435. then
  436. echo "OK: new Ubilling serial ${NEW_UBSERIAL}" >> /var/log/debianstaller.log 2>&1
  437. else
  438. $DIALOG --infobox "New Ubilling serial generated: ${NEW_UBSERIAL}" 4 60
  439. echo "Installation failed and aborted. Empty Ubilling serial. Retry your attempt."
  440. echo "FATAL: empty new Ubilling serial" >> /var/log/debianstaller.log 2>&1
  441. exit
  442. fi
  443. crontab ./docs/crontab/crontab.preconf
  444. $DIALOG --infobox "Installing default crontab preset" 4 60
  445. #updating serial in ubapi wrapper
  446. perl -e "s/UB000000000000000000000000000000000/${NEW_UBSERIAL}/g" -pi /bin/ubapi
  447. $DIALOG --infobox "New serial installed into ubapi wrapper" 4 60
  448. else
  449. echo "Looks like this Ubilling release is not supporting automatic crontab configuration"
  450. fi
  451. #installing default htaccess file with compression and client-side cachig optimizations
  452. cd ${APACHE_DATA_PATH}billing
  453. if [ -f ./docs/webspeed/speed_hta ];
  454. then
  455. cp -R ./docs/webspeed/speed_hta ${APACHE_DATA_PATH}billing/.htaccess
  456. else
  457. echo "Looks like this Ubilling release does not containing default htaccess preset"
  458. fi
  459. #Multigen/FreeRADIUS3 preconfiguration
  460. cd ${APACHE_DATA_PATH}billing
  461. cp -R ./docs/multigen/raddb3/* /etc/freeradius/3.0/
  462. cp -R ./docs/multigen/debian/radiusd.conf /etc/freeradius/3.0/radiusd.conf
  463. RADVER=`freeradius -v | grep "radiusd: FreeRADIUS Version" | awk '{print $4}' | tr -d ,`
  464. $DIALOG --infobox "Configuring FreeRADIUS ${RADVER} and MultiGen" 4 70
  465. perl -e "s/\/usr\/local\/share\/freeradius\/dictionary/\/usr\/share\/freeradius\/dictionary/g" -pi /etc/freeradius/3.0/dictionary
  466. perl -e "s/\/usr\/local\/etc\/raddb\/dictionary_preset/\/etc\/freeradius\/3.0\/dictionary_preset/g" -pi /etc/freeradius/3.0/dictionary
  467. cat ./docs/multigen/dump.sql | /usr/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  468. cat ./docs/multigen/radius3_fix.sql | /usr/bin/mysql -u root -p stg --password=${MYSQL_PASSWD}
  469. perl -e "s/yourmysqlpassword/${MYSQL_PASSWD}/g" -pi /etc/freeradius/3.0/sql.conf
  470. #sphinxsearch preconf
  471. $DIALOG --infobox "Installing Sphinx search service" 4 60
  472. cd /opt
  473. wget http://sphinxsearch.com/files/sphinx-3.4.1-efbcc65-linux-amd64.tar.gz >> /var/log/debianstaller.log 2>&1
  474. tar zxvf sphinx-3.4.1-efbcc65-linux-amd64.tar.gz >> /var/log/debianstaller.log 2>&1
  475. mv sphinx-3.4.1 sphinx
  476. cd sphinx
  477. mkdir -p sphinxdata/logs
  478. touch sphinxdata/logs/searchd.log
  479. cp -R ${APACHE_DATA_PATH}billing/docs/sphinxsearch/sphinx3.conf /opt/sphinx/etc/sphinx.conf
  480. perl -e "s/rootpassword/${MYSQL_PASSWD}/g" -pi /opt/sphinx/etc/sphinx.conf
  481. /opt/sphinx/bin/indexer --config /opt/sphinx/etc/sphinx.conf --all >> /var/log/debianstaller.log 2>&1
  482. /opt/sphinx/bin/searchd --config /opt/sphinx/etc/sphinx.conf >> /var/log/debianstaller.log 2>&1
  483. cp -R /usr/local/ubinstaller/configs/searchd.service /etc/systemd/system/
  484. systemctl daemon-reload
  485. systemctl enable searchd.service >> /var/log/debianstaller.log 2>&1
  486. #stopping stargazer
  487. $DIALOG --infobox "Stopping stargazer" 4 60
  488. killall stargazer
  489. sleep 10
  490. #installing systemd stargazer startup part
  491. cp -R /usr/local/ubinstaller/configs/stargazer.service /etc/systemd/system/
  492. systemctl daemon-reload
  493. systemctl enable stargazer.service >> /var/log/debianstaller.log 2>&1
  494. #all-in-one box presets if required
  495. case $NAS_KERNEL in
  496. 0)
  497. $DIALOG --infobox "Installing NAS presets" 4 60
  498. cd /usr/local/ubinstaller/
  499. cat configs/sysctl.preconf >> /etc/sysctl.conf
  500. cp -R configs/furrywall /etc/
  501. chmod a+x /etc/furrywall
  502. perl -e "s/INTERNAL_INTERFACE/${LAN_IFACE}/g" -pi /etc/furrywall
  503. perl -e "s/EXTERNAL_INTERFACE/${EXT_IF}/g" -pi /etc/furrywall
  504. perl -e "s/INTERNAL_NETWORK/${LAN_NETW}/g" -pi /etc/furrywall
  505. perl -e "s/INTERNAL_CIDR/${LAN_CIDR}/g" -pi /etc/furrywall
  506. cp -R configs/furrywall.service /etc/systemd/system/
  507. systemctl daemon-reload
  508. systemctl enable furrywall.service >> /var/log/debianstaller.log 2>&1
  509. cp -R configs/softflowd.preconf /etc/softflowd/default.conf
  510. perl -e "s/INTERNAL_INTERFACE/${LAN_IFACE}/g" -pi /etc/softflowd/default.conf
  511. #stargazer user init scripts preset
  512. cd ${APACHE_DATA_PATH}billing/
  513. cp -f docs/presets/Debian/etc/stargazer/* /etc/stargazer/
  514. chmod a+x /etc/stargazer/*
  515. perl -e "s/mylogin/root/g" -pi /etc/stargazer/config
  516. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi /etc/stargazer/config
  517. perl -e "s/INTERNAL_INTERFACE/${LAN_IFACE}/g" -pi /etc/stargazer/OnConnect
  518. perl -e "s/EXTERNAL_INTERFACE/${EXT_IF}/g" -pi /etc/stargazer/OnConnect
  519. perl -e "s/INTERNAL_INTERFACE/${LAN_IFACE}/g" -pi /etc/stargazer/OnDisconnect
  520. perl -e "s/EXTERNAL_INTERFACE/${EXT_IF}/g" -pi /etc/stargazer/OnDisconnect
  521. #bandwidthd service setup
  522. systemctl enable bandwidthd.service >> /var/log/debianstaller.log 2>&1
  523. ;;
  524. 1)
  525. $DIALOG --infobox "No NAS presets required" 4 60
  526. ;;
  527. esac
  528. #some magic
  529. mkdir /etc/stargazer/dn
  530. chmod -R 777 /etc/stargazer/dn
  531. mkdir ${APACHE_DATA_PATH}billing/content/dn
  532. chmod 777 ${APACHE_DATA_PATH}billing/content/dn
  533. cp -R /usr/local/ubinstaller/configs/dhcp_preset /etc/default/isc-dhcp-server
  534. perl -e "s/LAN_IFACE/${LAN_IFACE}/g" -pi /etc/default/isc-dhcp-server
  535. ln -fs /var/www/html/billing/multinet /usr/local/etc/multinet
  536. ln -fs /var/lib/bandwidthd/htdocs/ /var/www/html/band
  537. ln -fs ${APACHE_DATA_PATH}billing/remote_nas.conf /etc/stargazer/remote_nas.conf
  538. #disabling apparmor
  539. systemctl stop apparmor >> /var/log/debianstaller.log 2>&1
  540. systemctl disable apparmor >> /var/log/debianstaller.log 2>&1
  541. # Setting up autoupdate script
  542. if [ -f ./docs/presets/Debian/ubautoupgrade.sh ];
  543. then
  544. cp -R ./docs/presets/Debian/ubautoupgrade.sh /bin/
  545. chmod a+x /bin/ubautoupgrade.sh
  546. else
  547. echo "Looks like this Ubilling release does not containing automatic upgrade preset"
  548. fi
  549. $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
  550. ############################## END OF CONFIRMED SETUP #####################
  551. ;;
  552. 1)
  553. echo "Installation has been aborted"
  554. exit
  555. ;;
  556. esac