batchfreebsd.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/sh
  2. DISTRO_URL="https://codeload.github.com/nightflyza/OphanimFlow/zip/refs/heads/main"
  3. DISTRO_NAME="main.zip"
  4. DISTRO_DIR="OphanimFlow-main"
  5. FETCH="/usr/bin/fetch"
  6. APACHE_VERSION="apache24"
  7. PRESETS_PATH="dist/presets/freebsd/"
  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. PHP_CONFIG_PATH="/usr/local/etc/php.ini"
  15. MYSQL_INIT_SCRIPT="/usr/local/etc/rc.d/mysql-server"
  16. MYSQL_CONFIG_PRESET="80_my.cnf"
  17. MYSQL_CONFIG_PATH="/usr/local/etc/mysql/my.cnf"
  18. MYSQL_SECURE="/root/.mysql_secret"
  19. WEB_DIR="of"
  20. DUMP_PATH="dist/dumps/ophanimflow.sql"
  21. LANDING_PATH="dist/landing/"
  22. CRONTAB_PRESET="dist/crontab/crontab.preconf"
  23. set PATH=/usr/local/bin:/usr/local/sbin:$PATH
  24. #bootstraping pkgng
  25. pkg info
  26. #packages installing
  27. pkg install -y bash
  28. pkg install -y sudo
  29. #pkg install -y gmake
  30. pkg install -y libtool
  31. #pkg install -y autoconf
  32. #pkg install -y automake
  33. pkg install -y m4
  34. pkg install -y vim-tiny
  35. pkg install -y memcached
  36. pkg install -y redis
  37. pkg install -y mysql80-client
  38. pkg install -y mysql80-server
  39. pkg install -y apache24
  40. pkg install -y php83
  41. pkg install -y mod_php83
  42. pkg install -y php83-bcmath
  43. pkg install -y php83-ctype
  44. pkg install -y php83-curl
  45. pkg install -y php83-dom
  46. pkg install -y php83-extensions
  47. pkg install -y php83-filter
  48. pkg install -y php83-ftp
  49. pkg install -y php83-gd
  50. pkg install -y php83-hash
  51. pkg install -y php83-iconv
  52. pkg install -y php83-imap
  53. pkg install -y php83-json
  54. pkg install -y php83-mbstring
  55. pkg install -y php83-mysqli
  56. pkg install -y php83-opcache
  57. pkg install -y php83-openssl
  58. pkg install -y php83-pdo
  59. pkg install -y php83-pdo_sqlite
  60. pkg install -y php83-phar
  61. pkg install -y php83-posix
  62. pkg install -y php83-session
  63. pkg install -y php83-simplexml
  64. pkg install -y php83-snmp
  65. pkg install -y php83-soap
  66. pkg install -y php83-sockets
  67. pkg install -y php83-sqlite3
  68. pkg install -y php83-tokenizer
  69. pkg install -y php83-xml
  70. pkg install -y php83-xmlreader
  71. pkg install -y php83-xmlwriter
  72. pkg install -y php83-zip
  73. pkg install -y php83-zlib
  74. pkg install -y php83-pecl-memcached
  75. pkg install -y php83-pecl-redis
  76. pkg install -y git
  77. pkg install -y portsnap
  78. #building specific software from ports
  79. portsnap fetch && portsnap extract && portsnap update
  80. #fresh gmake
  81. cd /usr/ports/devel/gmake && make BATCH=yes install
  82. #installing pmacct with mysql support
  83. cd /usr/ports/net-mgmt/pmacct/ && make WITH="MYSQL" BATCH=yes install
  84. #generating mysql password
  85. GEN_MYS_PASS=`dd if=/dev/urandom count=128 bs=1 2>&1 | md5 | cut -b-8`
  86. MYSQL_PASSWD="mys"${GEN_MYS_PASS}
  87. #
  88. # Preconfiguring software
  89. #
  90. #downloading and unpacking app distro
  91. $FETCH -o ${DISTRO_NAME} ${DISTRO_URL}
  92. unzip ${DISTRO_NAME}
  93. mkdir ${APACHE_DATA_PATH}${WEB_DIR}
  94. mv ${DISTRO_DIR}/* ${APACHE_DATA_PATH}${WEB_DIR}/
  95. rm -fr ${DISTRO_DIR} ${DISTRO_NAME}
  96. cd ${APACHE_DATA_PATH}${WEB_DIR}/
  97. # preconfiguring OS
  98. cat ${PRESETS_PATH}loader.preconf >> /boot/loader.conf
  99. cat ${PRESETS_PATH}rc.preconf >> /etc/rc.conf
  100. cat ${PRESETS_PATH}sysctl.preconf >> /etc/sysctl.conf
  101. cat ${PRESETS_PATH}firewall.conf > /etc/firewall.conf
  102. cat ${PRESETS_PATH}local.preconf > /etc/rc.local
  103. chmod a+x /etc/firewall.conf
  104. #deploying database, webserver and php presets
  105. cp -R ${PRESETS_PATH}${MYSQL_CONFIG_PRESET} ${MYSQL_CONFIG_PATH}
  106. cp -R ${PRESETS_PATH}${APACHE_CONFIG_PRESET_NAME} ${APACHE_CONFIG_DIR}${APACHE_CONFIG_NAME}
  107. cp -R ${PRESETS_PATH}${PHP_CONFIG_PRESET} ${PHP_CONFIG_PATH}
  108. #preconfiguring app
  109. chmod -R 777 config content exports gdata
  110. #creating collector config and data storage placeholders
  111. mkdir /ofstorage
  112. touch /etc/of.conf
  113. touch /etc/pretag.map
  114. chmod -R 777 /etc/of.conf /etc/pretag.map /ofstorage
  115. #setting landing page
  116. cp -R ${LANDING_PATH} ${APACHE_DATA_PATH}
  117. #loading default crontab preset
  118. crontab ${CRONTAB_PRESET}
  119. # start services
  120. ${APACHE_INIT_SCRIPT} start
  121. ${MYSQL_INIT_SCRIPT} start
  122. # Setting MySQL root password
  123. if [ -f ${MYSQL_SECURE} ];
  124. then
  125. echo "Secure MySQL installation"
  126. TMP_PASS=`tail -n 1 ${MYSQL_SECURE}`
  127. echo "Temporary password is ${TMP_PASS}"
  128. mysqladmin -u root -p${TMP_PASS} password ${MYSQL_PASSWD}
  129. else
  130. echo "Insecure MySQL installation"
  131. mysqladmin -u root password ${MYSQL_PASSWD}
  132. fi
  133. #restarting database and web server
  134. ${MYSQL_INIT_SCRIPT} restart
  135. ${APACHE_INIT_SCRIPT} restart
  136. #adding sudoers
  137. echo "User_Alias OPHANIM = www" >> /usr/local/etc/sudoers
  138. echo "OPHANIM ALL = NOPASSWD: ALL" >> /usr/local/etc/sudoers
  139. echo "New MySQL password is ${MYSQL_PASSWD}"
  140. # configuring database
  141. cat ${DUMP_PATH} | /usr/local/bin/mysql -u root --password=${MYSQL_PASSWD}
  142. perl -e "s/mylogin/root/g" -pi config/mysql.ini
  143. perl -e "s/newpassword/${MYSQL_PASSWD}/g" -pi config/mysql.ini
  144. #setting up updater
  145. cp -R ${PRESETS_PATH}autoofupdate.sh /bin/
  146. chmod a+x /bin/autoofupdate.sh
  147. #here we go?
  148. echo "========== Installation finished! ============="
  149. echo "Please, reboot your server to check correct"
  150. echo "startup of all services. You cah access web"
  151. echo "interface by URL http://thishost/${WEB_DIR}/"
  152. echo "with login admin and password demo"
  153. echo "================================================"