wrinstaller.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #!/bin/sh
  2. #
  3. # Acta, non verba
  4. #
  5. OS_NAME=`uname`
  6. case $OS_NAME in
  7. FreeBSD)
  8. DIALOG=${DIALOG=dialog}
  9. FETCH="/usr/bin/fetch"
  10. APACHE_VERSION="apache24"
  11. APACHE_DATA_PATH="/usr/local/www/apache24/data/"
  12. APACHE_CONFIG_DIR="/usr/local/etc/apache24/"
  13. APACHE_INIT_SCRIPT="/usr/local/etc/rc.d/apache24"
  14. APACHE_CONFIG_PRESET_NAME="httpd24f8.conf"
  15. APACHE_CONFIG_NAME="httpd.conf"
  16. PHP_CONFIG_PRESET="php8.ini"
  17. MYSQL_INIT_SCRIPT="/usr/local/etc/rc.d/mysql-server"
  18. CACHE_INIT_SCRIPT="/usr/local/etc/rc.d/memcached"
  19. WR_WEB_DIR="wr/"
  20. INSTALLER_WORK_DIR="/usr/local/wrinstaller/"
  21. INSTALLER_LOG="/var/log/wrinstaller.log"
  22. #some remote paths here
  23. DL_PACKAGES_URL="http://wolfrecorder.com/packages/"
  24. DL_PACKAGES_EXT=".tar.gz"
  25. DL_WR_URL="http://wolfrecorder.com/"
  26. DL_WR_NAME="wr.tgz"
  27. set PATH=/usr/local/bin:/usr/local/sbin:$PATH
  28. # config interface section
  29. clear
  30. $DIALOG --title "WolfRecorder NVR installation" --msgbox "This wizard helps you to install WolfRecorder of the latest stable version to CLEAN (!) FreeBSD distribution" 10 50
  31. clear
  32. #new or migration installation
  33. clear
  34. $DIALOG --menu "Type of WolfRecorder installation" 10 75 8 \
  35. NEW "This is new WolfRecorder installation"\
  36. MIG "Migrating existing WolfRecorder setup from another host"\
  37. 2> /tmp/insttype
  38. clear
  39. $DIALOG --menu "Choose FreeBSD version and architecture" 16 50 8 \
  40. 142_6L "FreeBSD 14.2 amd64"\
  41. 141_6K "FreeBSD 14.1 amd64"\
  42. 140_6K "FreeBSD 14.0 amd64"\
  43. 134_6K "FreeBSD 13.4 amd64"\
  44. 133_6K "FreeBSD 13.3 amd64"\
  45. 2> /tmp/wrarch
  46. clear
  47. #some passwords generation or manual input
  48. PASSW_MODE=`cat /tmp/insttype`
  49. case $PASSW_MODE in
  50. NEW)
  51. #generating mysql password
  52. GEN_MYS_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  53. echo "mys"${GEN_MYS_PASS} > /tmp/wrmypass
  54. ;;
  55. MIG)
  56. #request previous MySQL password
  57. clear
  58. $DIALOG --title "MySQL root password" --inputbox "Enter your previous installation MySQL root password" 8 60 2> /tmp/wrmypass
  59. clear
  60. $DIALOG --title "WolfRecorder serial" --inputbox "Enter your previous installation WolfRecorder serial number" 8 60 2> /tmp/wrsrl
  61. ;;
  62. esac
  63. #setting some opts for future
  64. MYSQL_PASSWD=`cat /tmp/wrmypass`
  65. ARCH=`cat /tmp/wrarch`
  66. case $PASSW_MODE in
  67. NEW)
  68. WRSERIAL="AUTO"
  69. ;;
  70. MIG)
  71. WRSERIAL=`cat /tmp/wrsrl`
  72. ;;
  73. esac
  74. # generating snmp community string
  75. GEN_SNM_COMM=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  76. echo "snm"${GEN_SNM_COMM} > /tmp/wrsnmpcomm
  77. SNMP_COMMUNITY=`cat /tmp/wrsnmpcomm`
  78. # cleaning temp files
  79. rm -fr /tmp/wrarch
  80. rm -fr /tmp/wrmypass
  81. rm -fr /tmp/wrsrl
  82. rm -fr /tmp/insttype
  83. rm -fr /tmp/wrsnmpcomm
  84. #last chance to exit
  85. $DIALOG --title "Check settings" --yesno "Are all of these settings correct? \n \n MySQL password: ${MYSQL_PASSWD} \n SNMP RO community: ${SNMP_COMMUNITY} \n System: ${ARCH} \n WolfRecorder serial: ${WRSERIAL}\n" 10 60
  86. AGREE=$?
  87. clear
  88. # confirm installation
  89. case $AGREE in
  90. 0)
  91. echo "Everything is okay! Installation is starting."
  92. # preparing for installation
  93. mkdir ${INSTALLER_WORK_DIR}
  94. cd ${INSTALLER_WORK_DIR}
  95. #######################################
  96. # Platform specific issues handling #
  97. #######################################
  98. case $ARCH in
  99. 140_6K)
  100. # 14.0K contains PHP 8.3 binaries
  101. #APACHE_CONFIG_PRESET_NAME="httpd24f8.conf"
  102. #PHP_CONFIG_PRESET="php8.ini"
  103. ;;
  104. esac
  105. #botstrapping pkg ng
  106. pkg info
  107. #check is FreeBSD installation clean
  108. PKG_COUNT=`/usr/sbin/pkg info | /usr/bin/wc -l`
  109. if [ $PKG_COUNT -ge 2 ]
  110. then
  111. echo "WRinstaller supports setup only for clean FreeBSD distribution. Installation is aborted."
  112. exit
  113. fi
  114. # install prebuilded binary packages
  115. $DIALOG --infobox "Downloading binary packages." 4 60
  116. $FETCH ${DL_PACKAGES_URL}${ARCH}${DL_PACKAGES_EXT}
  117. #check is binary packages download has beed completed
  118. if [ -f ${ARCH}${DL_PACKAGES_EXT} ];
  119. then
  120. $DIALOG --infobox "Binary packages download has been completed." 4 60
  121. else
  122. echo "=== Error: binary packages are not available. Installation is aborted. ==="
  123. exit
  124. fi
  125. # unpacking and installing packages
  126. $DIALOG --infobox "Unpacking binary packages." 4 60
  127. tar zxvf ${ARCH}${DL_PACKAGES_EXT} 2>> ${INSTALLER_LOG}
  128. cd ${ARCH}
  129. $DIALOG --infobox "Software installation is in progress. This takes a while." 4 70
  130. ls -1 | xargs -n 1 pkg add >> ${INSTALLER_LOG}
  131. $DIALOG --infobox "Binary packages installation has been completed." 4 60
  132. ################################################
  133. # Downloading and unpacking WolfRecorder distro
  134. ################################################
  135. $DIALOG --infobox "WolfRecorder download, unpacking and installation is in progress." 4 60
  136. #back to installation directory
  137. cd ${INSTALLER_WORK_DIR}
  138. # downloading distro
  139. $FETCH ${DL_WR_URL}${DL_WR_NAME}
  140. #check is wolfrecorder distro download complete
  141. if [ -f ${DL_WR_NAME} ];
  142. then
  143. $DIALOG --infobox "WolfRecorder download has been completed." 4 60
  144. else
  145. echo "=== Error: WolfRecorder release is not available. Installation is aborted. ==="
  146. exit
  147. fi
  148. mkdir ${APACHE_DATA_PATH}${WR_WEB_DIR}
  149. cp -R ${DL_WR_NAME} ${APACHE_DATA_PATH}${WR_WEB_DIR}
  150. cd ${APACHE_DATA_PATH}${WR_WEB_DIR}
  151. tar zxvf ${DL_WR_NAME} 2>> ${INSTALLER_LOG}
  152. chmod -R 777 content/ config/ exports/ howl/
  153. # setting up config presets
  154. cp -R dist/presets/freebsd/${APACHE_CONFIG_PRESET_NAME} ${APACHE_CONFIG_DIR}${APACHE_CONFIG_NAME}
  155. cp -R dist/presets/freebsd/${PHP_CONFIG_PRESET} /usr/local/etc/php.ini
  156. cat dist/presets/freebsd/rc.preconf >> /etc/rc.conf
  157. cat dist/presets/freebsd/sysctl.preconf >> /etc/sysctl.conf
  158. cat dist/presets/freebsd/loader.preconf >> /boot/loader.conf
  159. cp -R dist/presets/freebsd/firewall.conf /etc/firewall.conf
  160. chmod a+x /etc/firewall.conf
  161. cp -R dist/presets/freebsd/snmpd.preconf /usr/local/etc/snmpd.conf
  162. # setting up default web awesomeness
  163. cp -R dist/landing/index.html ${APACHE_DATA_PATH}/index.html
  164. cp -R dist/landing/bg.gif ${APACHE_DATA_PATH}/
  165. # database specific issues handling
  166. case $ARCH in
  167. 133_6K)
  168. # MySQL 8.0 requires custom config
  169. cp -R dist/presets/freebsd/80_my.cnf /usr/local/etc/mysql/my.cnf
  170. $DIALOG --infobox "MySQL 8.0 config replaced" 4 60
  171. ;;
  172. 134_6K)
  173. # MySQL 8.0 requires custom config
  174. cp -R dist/presets/freebsd/80_my.cnf /usr/local/etc/mysql/my.cnf
  175. $DIALOG --infobox "MySQL 8.0 config replaced" 4 60
  176. ;;
  177. 140_6K)
  178. # MySQL 8.0 requires custom config
  179. cp -R dist/presets/freebsd/80_my.cnf /usr/local/etc/mysql/my.cnf
  180. $DIALOG --infobox "MySQL 8.0 config replaced" 4 60
  181. ;;
  182. 141_6K)
  183. # MySQL 8.0 requires custom config
  184. cp -R dist/presets/freebsd/80_my.cnf /usr/local/etc/mysql/my.cnf
  185. $DIALOG --infobox "MySQL 8.0 config replaced" 4 60
  186. ;;
  187. 142_6L)
  188. # MySQL 8.0 requires custom config
  189. cp -R dist/presets/freebsd/80_my.cnf /usr/local/etc/mysql/my.cnf
  190. $DIALOG --infobox "MySQL 8.0 config replaced" 4 60
  191. ;;
  192. esac
  193. # start reqired services
  194. $DIALOG --infobox "Starting web server.." 4 60
  195. ${APACHE_INIT_SCRIPT} start 2>> ${INSTALLER_LOG}
  196. $DIALOG --infobox "Starting database server.." 4 60
  197. ${MYSQL_INIT_SCRIPT} start 2>> ${INSTALLER_LOG}
  198. $DIALOG --infobox "Starting caching server.." 4 60
  199. ${CACHE_INIT_SCRIPT} start 2>> ${INSTALLER_LOG}
  200. #Setting MySQL root password
  201. mysqladmin -u root password ${MYSQL_PASSWD} 2>> ${INSTALLER_LOG}
  202. # updating passwords and login in mysql.ini
  203. perl -e "s/mylogin/root/g" -pi ./config/mysql.ini
  204. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./config/mysql.ini
  205. # creating wr database
  206. $DIALOG --infobox "Creating initial WolfRecorder DB" 4 60
  207. cat dist/dumps/wolfrecorder.sql | /usr/local/bin/mysql -u root --password=${MYSQL_PASSWD} 2>> ${INSTALLER_LOG}
  208. # creation default storage
  209. $DIALOG --infobox "Creating default storage" 4 60
  210. cat dist/dumps/defaultstorage.sql | /usr/local/bin/mysql -u root -p wr --password=${MYSQL_PASSWD} 2>> ${INSTALLER_LOG}
  211. mkdir /wrstorage
  212. chmod 777 /wrstorage
  213. # first install flag setup for the future
  214. touch ./exports/FIRST_INSTALL
  215. chmod 777 ./exports/FIRST_INSTALL
  216. # unpacking wrapi preset
  217. cp -R dist/wrap/wrapi /bin/
  218. chmod a+x /bin/wrapi
  219. $DIALOG --infobox "remote API wrapper installed" 4 60
  220. # updating sudoers
  221. echo "User_Alias WOLFRECORDER = www" >> /usr/local/etc/sudoers
  222. echo "WOLFRECORDER ALL = NOPASSWD: ALL" >> /usr/local/etc/sudoers
  223. #disabling mysql>=5.6 strict trans tables in various config locations
  224. if [ -f /usr/local/my.cnf ];
  225. then
  226. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/my.cnf
  227. $DIALOG --infobox "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/my.cnf done" 4 60
  228. else
  229. $DIALOG --infobox "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/my.cnf" 4 60
  230. fi
  231. if [ -f /usr/local/etc/my.cnf ];
  232. then
  233. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/etc/my.cnf
  234. $DIALOG --infobox "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/etc/my.cnf done" 4 60
  235. else
  236. $DIALOG --infobox "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/etc/my.cnf" 4 60
  237. fi
  238. if [ -f /usr/local/etc/mysql/my.cnf ];
  239. then
  240. perl -e "s/,STRICT_TRANS_TABLES//g" -pi /usr/local/etc/mysql/my.cnf
  241. $DIALOG --infobox "Disabling MySQL STRICT_TRANS_TABLES in /usr/local/etc/mysql/my.cnf done" 4 60
  242. else
  243. $DIALOG --infobox "Looks like no MySQL STRICT_TRANS_TABLES disable required in /usr/local/etc/mysql/my.cnf" 4 60
  244. fi
  245. #initial crontab configuration
  246. cd ${APACHE_DATA_PATH}${WR_WEB_DIR}
  247. if [ -f ./dist/crontab/crontab.preconf ];
  248. then
  249. #generating new WolfRecorder serial or using predefined
  250. case $PASSW_MODE in
  251. NEW)
  252. /usr/local/bin/curl -o /dev/null "http://127.0.0.1/${WR_WEB_DIR}?module=remoteapi&action=identify&param=save" 2>> ${INSTALLER_LOG}
  253. NEW_WRSERIAL=`cat ./exports/wrserial`
  254. $DIALOG --infobox "New WolfRecorder serial generated: ${NEW_WRSERIAL}" 4 60
  255. ;;
  256. MIG)
  257. NEW_WRSERIAL=${WRSERIAL}
  258. $DIALOG --infobox "Using WolfRecorder serial: ${NEW_WRSERIAL}" 4 60
  259. ;;
  260. esac
  261. #loading default crontab preset
  262. crontab ./dist/crontab/crontab.preconf
  263. $DIALOG --infobox "Installing default crontab preset" 4 60
  264. # updating serial in wrapi wrapper
  265. perl -e "s/WR00000000000000000000000000000000/${NEW_WRSERIAL}/g" -pi /bin/wrapi
  266. $DIALOG --infobox "New serial installed into wrapi wrapper" 4 60
  267. else
  268. echo "Looks like this WolfRecorder release is not supporting automatic crontab configuration"
  269. fi
  270. # Setting up autoupdate sctipt
  271. cp -R ./dist/presets/freebsd/autowrupdate.sh /bin/
  272. chmod a+x /bin/autowrupdate.sh
  273. # Setting snmpd read only community string
  274. perl -e "s/SNMPCOMMTPL/${SNMP_COMMUNITY}/g" -pi /usr/local/etc/snmpd.conf
  275. $DIALOG --infobox "SNMP read only community set: ${SNMP_COMMUNITY}" 4 60
  276. #cleaning up installer work directory
  277. cd /
  278. rm -fr ${INSTALLER_WORK_DIR}
  279. $DIALOG --title "WolfRecorder installation has been completed" --msgbox "Now you can access your web-interface by address http://server_ip/${WR_WEB_DIR} with login and password: admin/demo. Please reboot your server to check correct startup of all services" 15 50
  280. # Finishing installation
  281. ;;
  282. #cancel installstion
  283. 1)
  284. echo "Installation has been aborted"
  285. exit
  286. ;;
  287. esac
  288. #
  289. # End of FreeBSD setup
  290. #
  291. ;;
  292. Linux)
  293. # START of Linux installation scripts here
  294. DIALOG="dialog"
  295. INSTALLER_LOG="/var/log/wrinstaller.log"
  296. #initial repos update
  297. echo "Preparing to installation.."
  298. apt update >> ${INSTALLER_LOG} 2>&1
  299. apt -y upgrade >> ${INSTALLER_LOG} 2>&1
  300. #installation of basic software required for installer
  301. echo "Installing basic software required for Debianstaller.."
  302. apt install -y dialog >> ${INSTALLER_LOG} 2>&1
  303. apt install -y net-tools >> ${INSTALLER_LOG} 2>&1
  304. apt install -y gnupg2 >> ${INSTALLER_LOG} 2>&1
  305. $DIALOG --menu "Choose your Linux distribution" 16 50 8 \
  306. DEB126 "Debian 12.6 Bookworm"\
  307. 2> /tmp/wrarch
  308. clear
  309. ARCH=`cat /tmp/wrarch`
  310. case $ARCH in
  311. DEB126)
  312. #some remote paths here
  313. FETCH="/usr/bin/wget"
  314. APACHE_VERSION="apache24"
  315. APACHE_DATA_PATH="/var/www/html/"
  316. APACHE_CONFIG_DIR="/etc/apache2/"
  317. APACHE_INIT_SCRIPT="/usr/sbin/service apache2"
  318. APACHE_CONFIG_PRESET_NAME="debi12_apache2.conf"
  319. APACHE_CONFIG_NAME="apache2.conf"
  320. PHP_CONFIG_PRESET="php82.ini"
  321. MYSQL_INIT_SCRIPT="/usr/sbin/service mariadb"
  322. CACHE_INIT_SCRIPT="/usr/sbin/service memcached"
  323. WR_WEB_DIR="wr/"
  324. INSTALLER_WORK_DIR="/usr/local/wrinstaller/"
  325. DL_WR_URL="http://wolfrecorder.com/"
  326. DL_WR_NAME="wr.tgz"
  327. # config interface section
  328. clear
  329. $DIALOG --title "WolfRecorder NVR installation" --msgbox "This wizard helps you to install WolfRecorder of the latest stable version to CLEAN (!) Linux distribution" 10 50
  330. clear
  331. #new or migration installation
  332. clear
  333. $DIALOG --menu "Type of WolfRecorder installation" 10 75 8 \
  334. NEW "This is new WolfRecorder installation"\
  335. MIG "Migrating existing WolfRecorder setup from another host"\
  336. 2> /tmp/insttype
  337. clear
  338. #some passwords generation or manual input
  339. PASSW_MODE=`cat /tmp/insttype`
  340. case $PASSW_MODE in
  341. NEW)
  342. #generating mysql password
  343. GEN_MYS_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5sum | cut -b-8`
  344. echo "mys"${GEN_MYS_PASS} > /tmp/wrmypass
  345. ;;
  346. MIG)
  347. #request previous MySQL password
  348. clear
  349. $DIALOG --title "MySQL root password" --inputbox "Enter your previous installation MySQL root password" 8 60 2> /tmp/wrmypass
  350. clear
  351. $DIALOG --title "WolfRecorder serial" --inputbox "Enter your previous installation WolfRecorder serial number" 8 60 2> /tmp/wrsrl
  352. ;;
  353. esac
  354. #setting some opts for future
  355. MYSQL_PASSWD=`cat /tmp/wrmypass`
  356. case $PASSW_MODE in
  357. NEW)
  358. WRSERIAL="AUTO"
  359. ;;
  360. MIG)
  361. WRSERIAL=`cat /tmp/wrsrl`
  362. ;;
  363. esac
  364. # cleaning temp files
  365. rm -fr /tmp/wrarch
  366. rm -fr /tmp/wrmypass
  367. rm -fr /tmp/wrsrl
  368. rm -fr /tmp/insttype
  369. #last chance to exit
  370. $DIALOG --title "Check settings" --yesno "Are all of these settings correct? \n \n MySQL password: ${MYSQL_PASSWD} \n System: ${ARCH} \n WolfRecorder serial: ${WRSERIAL}\n" 10 60
  371. AGREE=$?
  372. clear
  373. # confirm installation
  374. case $AGREE in
  375. 0)
  376. echo "Everything is okay! Installation is starting."
  377. # preparing for installation
  378. mkdir ${INSTALLER_WORK_DIR}
  379. cd ${INSTALLER_WORK_DIR}
  380. # install binary packages from repos
  381. $DIALOG --infobox "Software installation is in progress. This takes a while." 4 70
  382. #MariaDB setup
  383. apt install -y software-properties-common dirmngr >> ${INSTALLER_LOG} 2>&1
  384. $DIALOG --infobox "Installing MariaDB" 4 60
  385. $DIALOG --infobox "Installing MariaDB." 4 60
  386. $DIALOG --infobox "Installing MariaDB.." 4 60
  387. $DIALOG --infobox "Installing MariaDB..." 4 60
  388. apt install -y mariadb-server >> ${INSTALLER_LOG} 2>&1
  389. $DIALOG --infobox "Installing MariaDB...." 4 60
  390. apt install -y mariadb-client >> ${INSTALLER_LOG} 2>&1
  391. $DIALOG --infobox "Installing MariaDB....." 4 60
  392. apt install -y libmariadb-dev >> ${INSTALLER_LOG} 2>&1
  393. $DIALOG --infobox "Installing MariaDB......" 4 60
  394. apt install -y default-libmysqlclient-dev >> ${INSTALLER_LOG} 2>&1
  395. $DIALOG --infobox "MariaDB installed" 4 60
  396. mariadb --version >> ${INSTALLER_LOG} 2>&1
  397. systemctl start mariadb >> ${INSTALLER_LOG} 2>&1
  398. systemctl enable mariadb >> ${INSTALLER_LOG} 2>&1
  399. $DIALOG --infobox "MariaDB startup enabled" 4 60
  400. $DIALOG --infobox "Installing some required software" 4 60
  401. apt install -y expat >> ${INSTALLER_LOG} 2>&1
  402. apt install -y libexpat1-dev >> ${INSTALLER_LOG} 2>&1
  403. apt install -y sudo >> ${INSTALLER_LOG} 2>&1
  404. apt install -y curl >> ${INSTALLER_LOG} 2>&1
  405. $DIALOG --infobox "Installing Apache server" 4 60
  406. apt install -y apache2 >> ${INSTALLER_LOG} 2>&1
  407. apt install -y libapache2-mod-php8.2 >> ${INSTALLER_LOG} 2>&1
  408. $DIALOG --infobox "Installing misc software" 4 60
  409. apt install -y build-essential >> ${INSTALLER_LOG} 2>&1
  410. apt install -y libxmlrpc-c++8-dev >> ${INSTALLER_LOG} 2>&1
  411. apt install -y ipset >> ${INSTALLER_LOG} 2>&1
  412. $DIALOG --infobox "Installing memory caching servers" 4 60
  413. apt install -y memcached >> ${INSTALLER_LOG} 2>&1
  414. apt install -y redis >> ${INSTALLER_LOG} 2>&1
  415. $DIALOG --infobox "Installing PHP and required extensions" 4 60
  416. apt install -y php8.2-cli >> ${INSTALLER_LOG} 2>&1
  417. apt install -y php8.2-mysql >> ${INSTALLER_LOG} 2>&1
  418. apt install -y php8.2-mysqli >> ${INSTALLER_LOG} 2>&1
  419. apt install -y php8.2-mbstring >> ${INSTALLER_LOG} 2>&1
  420. apt install -y php8.2-bcmath >> ${INSTALLER_LOG} 2>&1
  421. apt install -y php8.2-curl >> ${INSTALLER_LOG} 2>&1
  422. apt install -y php8.2-gd >> ${INSTALLER_LOG} 2>&1
  423. apt install -y php8.2-snmp >> ${INSTALLER_LOG} 2>&1
  424. apt install -y php8.2-soap >> ${INSTALLER_LOG} 2>&1
  425. apt install -y php8.2-zip >> ${INSTALLER_LOG} 2>&1
  426. apt install -y php8.2-imap >> ${INSTALLER_LOG} 2>&1
  427. apt install -y php8.2-json >> ${INSTALLER_LOG} 2>&1
  428. apt install -y php8.2-tokenizer >> ${INSTALLER_LOG} 2>&1
  429. apt install -y php8.2-xml >> ${INSTALLER_LOG} 2>&1
  430. apt install -y php8.2-xmlreader >> ${INSTALLER_LOG} 2>&1
  431. apt install -y php8.2-xmlwriter >> ${INSTALLER_LOG} 2>&1
  432. apt install -y php8.2-simplexml >> ${INSTALLER_LOG} 2>&1
  433. apt install -y php8.2-sqlite3 >> ${INSTALLER_LOG} 2>&1
  434. apt install -y php8.2-sockets >> ${INSTALLER_LOG} 2>&1
  435. apt install -y php8.2-opcache >> ${INSTALLER_LOG} 2>&1
  436. apt install -y php8.2-json >> ${INSTALLER_LOG} 2>&1
  437. apt install -y php8.2-pdo >> ${INSTALLER_LOG} 2>&1
  438. apt install -y php8.2-pdo-sqlite >> ${INSTALLER_LOG} 2>&1
  439. apt install -y php8.2-phar >> ${INSTALLER_LOG} 2>&1
  440. apt install -y php8.2-posix >> ${INSTALLER_LOG} 2>&1
  441. apt install -y php8.2-memcached >> ${INSTALLER_LOG} 2>&1
  442. apt install -y php8.2-redis >> ${INSTALLER_LOG} 2>&1
  443. $DIALOG --infobox "Installing ffmpeg" 4 60
  444. apt install -y ffmpeg >> ${INSTALLER_LOG} 2>&1
  445. $DIALOG --infobox "Installing some optional software" 4 60
  446. apt install -y graphviz >> ${INSTALLER_LOG} 2>&1
  447. apt install -y vim-tiny >> ${INSTALLER_LOG} 2>&1
  448. apt install -y arping >> ${INSTALLER_LOG} 2>&1
  449. apt install -y elinks >> ${INSTALLER_LOG} 2>&1
  450. apt install -y mc >> ${INSTALLER_LOG} 2>&1
  451. apt install -y nano >> ${INSTALLER_LOG} 2>&1
  452. apt install -y nmap >> ${INSTALLER_LOG} 2>&1
  453. apt install -y mtr >> ${INSTALLER_LOG} 2>&1
  454. apt install -y expect >> ${INSTALLER_LOG} 2>&1
  455. apt install -y bwm-ng >> ${INSTALLER_LOG} 2>&1
  456. apt install -y git >> ${INSTALLER_LOG} 2>&1
  457. apt install -y netdiag >> ${INSTALLER_LOG} 2>&1
  458. apt install -y htop >> ${INSTALLER_LOG} 2>&1
  459. apt install -y rsyslog >> ${INSTALLER_LOG} 2>&1
  460. $DIALOG --infobox "Binary packages installation has been completed." 4 60
  461. ################################################
  462. # Downloading and unpacking WolfRecorder distro
  463. ################################################
  464. $DIALOG --infobox "WolfRecorder download, unpacking and installation is in progress." 4 60
  465. #back to installation directory
  466. cd ${INSTALLER_WORK_DIR}
  467. # downloading distro
  468. $FETCH ${DL_WR_URL}${DL_WR_NAME}
  469. #check is wolfrecorder distro download complete
  470. if [ -f ${DL_WR_NAME} ];
  471. then
  472. $DIALOG --infobox "WolfRecorder download has been completed." 4 60
  473. else
  474. echo "=== Error: WolfRecorder release is not available. Installation is aborted. ==="
  475. exit
  476. fi
  477. mkdir ${APACHE_DATA_PATH}${WR_WEB_DIR}
  478. cp -R ${DL_WR_NAME} ${APACHE_DATA_PATH}${WR_WEB_DIR}
  479. cd ${APACHE_DATA_PATH}${WR_WEB_DIR}
  480. tar zxvf ${DL_WR_NAME} >> ${INSTALLER_LOG} 2>&1
  481. chmod -R 777 content/ config/ exports/ howl/
  482. # setting up config presets
  483. cp -R dist/presets/debian121/${APACHE_CONFIG_PRESET_NAME} ${APACHE_CONFIG_DIR}${APACHE_CONFIG_NAME}
  484. cp -R dist/presets/debian121/${PHP_CONFIG_PRESET} /etc/php/8.2/apache2/php.ini
  485. cp -R dist/presets/debian121/000-default.conf ${APACHE_CONFIG_DIR}sites-enabled/000-default.conf
  486. # setting up default web awesomeness
  487. cp -R dist/landing/index.html ${APACHE_DATA_PATH}/index.html
  488. cp -R dist/landing/bg.gif ${APACHE_DATA_PATH}/
  489. # start reqired services
  490. $DIALOG --infobox "Starting web server.." 4 60
  491. ${APACHE_INIT_SCRIPT} start >> ${INSTALLER_LOG} 2>&1
  492. $DIALOG --infobox "Starting database server.." 4 60
  493. ${MYSQL_INIT_SCRIPT} start >> ${INSTALLER_LOG} 2>&1
  494. $DIALOG --infobox "Starting caching server.." 4 60
  495. ${CACHE_INIT_SCRIPT} start >> ${INSTALLER_LOG} 2>&1
  496. #Setting MySQL root password
  497. mysqladmin -u root password ${MYSQL_PASSWD} >> ${INSTALLER_LOG} 2>&1
  498. # updating passwords and login in mysql.ini
  499. perl -e "s/mylogin/root/g" -pi ./config/mysql.ini
  500. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi ./config/mysql.ini
  501. # updating binary paths in binpaths.ini
  502. cp -R dist/presets/debian121/binpaths.ini ./config/binpaths.ini
  503. # creating wr database
  504. $DIALOG --infobox "Creating initial WolfRecorder DB" 4 60
  505. cat dist/dumps/wolfrecorder.sql | /usr/bin/mysql -u root --password=${MYSQL_PASSWD} >> ${INSTALLER_LOG} 2>&1
  506. # creation default storage
  507. $DIALOG --infobox "Creating default storage" 4 60
  508. cat dist/dumps/defaultstorage.sql | /usr/bin/mysql -u root -p wr --password=${MYSQL_PASSWD} >> ${INSTALLER_LOG} 2>&1
  509. mkdir /wrstorage
  510. chmod 777 /wrstorage
  511. # first install flag setup for the future
  512. touch ./exports/FIRST_INSTALL
  513. chmod 777 ./exports/FIRST_INSTALL
  514. # unpacking wrapi preset
  515. cp -R dist/wrap/deb121_wrapi /bin/wrapi
  516. chmod a+x /bin/wrapi
  517. $DIALOG --infobox "remote API wrapper installed" 4 60
  518. # updating sudoers
  519. echo "User_Alias WOLFRECORDER = www-data" >> /etc/sudoers.d/wolfrecorder
  520. echo "WOLFRECORDER ALL = NOPASSWD: ALL" >> /etc/sudoers.d/wolfrecorder
  521. #enabling required apache modules
  522. /usr/sbin/a2enmod headers
  523. /usr/sbin/a2enmod expires
  524. #restarting apache
  525. $DIALOG --infobox "Restarting web server.." 4 60
  526. ${APACHE_INIT_SCRIPT} restart >> ${INSTALLER_LOG} 2>&1
  527. #initial crontab configuration
  528. cd ${APACHE_DATA_PATH}${WR_WEB_DIR}
  529. if [ -f ./dist/crontab/crontab.preconf ];
  530. then
  531. #generating new WolfRecorder serial or using predefined
  532. case $PASSW_MODE in
  533. NEW)
  534. /usr/bin/curl -o /dev/null "http://127.0.0.1/${WR_WEB_DIR}?module=remoteapi&action=identify&param=save" >> ${INSTALLER_LOG} 2>&1
  535. #waiting saving data
  536. sleep 3
  537. NEW_WRSERIAL=`cat ./exports/wrserial`
  538. $DIALOG --infobox "New WolfRecorder serial generated: ${NEW_WRSERIAL}" 4 60
  539. ;;
  540. MIG)
  541. NEW_WRSERIAL=${WRSERIAL}
  542. $DIALOG --infobox "Using WolfRecorder serial: ${NEW_WRSERIAL}" 4 60
  543. ;;
  544. esac
  545. if [ -n "$NEW_WRSERIAL" ];
  546. then
  547. echo "OK: new WolfRecorder serial ${NEW_WRSERIAL}" >> ${INSTALLER_LOG} 2>&1
  548. else
  549. $DIALOG --infobox "No new WolfRecorder serial generated: ${NEW_WRSERIAL}" 4 60
  550. echo "Installation failed and aborted. Empty WolfRecorder serial. Retry your attempt."
  551. echo "FATAL: empty new WolfRecorder serial" >> ${INSTALLER_LOG} 2>&1
  552. exit
  553. fi
  554. #loading default crontab preset
  555. crontab ./dist/crontab/crontab.preconf
  556. $DIALOG --infobox "Installing default crontab preset" 4 60
  557. # updating serial in wrapi wrapper
  558. perl -e "s/WR00000000000000000000000000000000/${NEW_WRSERIAL}/g" -pi /bin/wrapi
  559. $DIALOG --infobox "New serial installed into wrapi wrapper" 4 60
  560. else
  561. echo "Looks like this WolfRecorder release is not supporting automatic crontab configuration"
  562. fi
  563. # Setting up autoupdate sctipt
  564. cp -R ./dist/presets/debian121/autowrupdate.sh /bin/
  565. chmod a+x /bin/autowrupdate.sh
  566. #cleaning up installer work directory
  567. cd /
  568. rm -fr ${INSTALLER_WORK_DIR}
  569. $DIALOG --title "WolfRecorder installation has been completed" --msgbox "Now you can access your web-interface by address http://server_ip/${WR_WEB_DIR} with login and password: admin/demo. Please reboot your server to check correct startup of all services" 15 50
  570. # Finishing installation
  571. ;;
  572. #cancel installation
  573. 1)
  574. echo "Installation has been aborted"
  575. exit
  576. ;;
  577. esac
  578. #
  579. # End of Debian 12.6 script here
  580. #
  581. ;;
  582. esac
  583. # END
  584. ;;
  585. esac