Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.24 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Install script for Restyaboard
  4. #
  5. # Usage: ./restyaboard.sh
  6. #
  7. # Copyright (c) 2014-2018 Restya.
  8. # Dual License (OSL 3.0 & Commercial License)
  9. {
  10. main() {
  11. if [[ $EUID -ne 0 ]];
  12. then
  13. echo "This script must be run as root"
  14. exit 1
  15. fi
  16. set -x
  17. whoami
  18. echo $(cat /etc/issue)
  19. OS_REQUIREMENT=$(lsb_release -i -s)
  20. if ([ "$OS_REQUIREMENT" = "" ])
  21. then
  22. echo "lsb_release is not enabled, please install \"yum install -y redhat-lsb-core\" command before running install script"
  23. exit 1
  24. fi
  25. OS_VERSION=$(lsb_release -rs | cut -f1 -d.)
  26. if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
  27. then
  28. apt-get update
  29. apt-get install -y curl unzip
  30. else
  31. yum install -y curl unzip
  32. fi
  33. RESTYABOARD_VERSION=$(curl --silent https://api.github.com/repos/RestyaPlatform/board/releases | grep tag_name -m 1 | awk '{print $2}' | sed -e 's/[^v0-9.]//g')
  34. POSTGRES_DBHOST=localhost
  35. POSTGRES_DBNAME=restyaboard
  36. POSTGRES_DBUSER=restya
  37. POSTGRES_DBPASS=hjVl2!rGd
  38. POSTGRES_DBPORT=5432
  39. DOWNLOAD_DIR=/opt/restyaboard
  40.  
  41. get_geoip_data ()
  42. {
  43. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
  44. gunzip GeoIP.dat.gz
  45. mv GeoIP.dat /usr/share/GeoIP/GeoIP.dat
  46. wget http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz
  47. gunzip GeoIPv6.dat.gz
  48. mv GeoIPv6.dat /usr/share/GeoIP/GeoIPv6.dat
  49. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
  50. gunzip GeoLiteCity.dat.gz
  51. mv GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat
  52. wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz
  53. gunzip GeoLiteCityv6.dat.gz
  54. mv GeoLiteCityv6.dat /usr/share/GeoIP/GeoLiteCityv6.dat
  55. wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
  56. gunzip GeoIPASNum.dat.gz
  57. mv GeoIPASNum.dat /usr/share/GeoIP/GeoIPASNum.dat
  58. wget http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz
  59. gunzip GeoIPASNumv6.dat.gz
  60. mv GeoIPASNumv6.dat /usr/share/GeoIP/GeoIPASNumv6.dat
  61. }
  62.  
  63. upgrade-0.3-0.4()
  64. {
  65. sed -i "s/*\/5 * * * * $dir\/server\/php\/shell\/chat_activities.sh//" /var/spool/cron/crontabs/root
  66. sed -i "s/0 * * * * $dir\/server\/php\/shell\/periodic_chat_email_notification.sh//" /var/spool/cron/crontabs/root
  67. sed -i "s/*\/5 * * * * $dir\/server\/php\/shell\/indexing_to_elasticsearch.sh//" /var/spool/cron/crontabs/root
  68.  
  69. rm $dir/server/php/shell/chat_activities.sh
  70. rm $dir/server/php/shell/chat_activities.php
  71. rm $dir/server/php/shell/indexing_to_elasticsearch.sh
  72. rm $dir/server/php/shell/indexing_to_elasticsearch.php
  73. rm $dir/server/php/shell/periodic_chat_email_notification.sh
  74. rm $dir/server/php/shell/periodic_chat_email_notification.php
  75. rm $dir/server/php/shell/upgrade_v0.2.1_v0.3.php
  76.  
  77. rm -rf $dir/client/apps/
  78.  
  79. rm -rf $dir/server/php/libs/vendors/xmpp/
  80. rm -rf $dir/server/php/libs/vendors/jaxl3/
  81. rm -rf $dir/server/php/libs/vendors/xmpp-prebind-php/
  82. }
  83.  
  84. upgrade-0.4-0.4.1()
  85. {
  86. sed -i "s/*\/5 * * * * $dir\/server\/php\/shell\/chat_activities.sh//" /var/spool/cron/crontabs/root
  87. sed -i "s/0 * * * * $dir\/server\/php\/shell\/periodic_chat_email_notification.sh//" /var/spool/cron/crontabs/root
  88. sed -i "s/*\/5 * * * * $dir\/server\/php\/shell\/indexing_to_elasticsearch.sh//" /var/spool/cron/crontabs/root
  89.  
  90. rm $dir/server/php/shell/chat_activities.sh
  91. rm $dir/server/php/shell/chat_activities.php
  92. rm $dir/server/php/shell/indexing_to_elasticsearch.sh
  93. rm $dir/server/php/shell/indexing_to_elasticsearch.php
  94. rm $dir/server/php/shell/periodic_chat_email_notification.sh
  95. rm $dir/server/php/shell/periodic_chat_email_notification.php
  96. rm $dir/server/php/shell/upgrade_v0.2.1_v0.3.php
  97.  
  98. rm -rf $dir/client/apps/
  99.  
  100. rm -rf $dir/server/php/libs/vendors/xmpp/
  101. rm -rf $dir/server/php/libs/vendors/jaxl3/
  102. rm -rf $dir/server/php/libs/vendors/xmpp-prebind-php/
  103. }
  104.  
  105. upgrade-0.5.2-0.6()
  106. {
  107. sed -i "s/rewrite ^\/ical\/.*/rewrite ^\/ical\/([0-9]*)\/([0-9]*)\/([a-z0-9]*).ics\$ \/server\/php\/ical.php?board_id=\$1\&user_id=\$2\&hash=\$3 last;/" /etc/nginx/conf.d/restyaboard.conf
  108. }
  109.  
  110. upgrade-0.6.1-0.6.2()
  111. {
  112. set +x
  113. echo "Do you want to install Restyaboard app 'Hide Card Additional Informations' (y/n)?"
  114. read -r answer
  115. set -x
  116. case "${answer}" in
  117. [Yy])
  118. mkdir "$dir/client/apps"
  119. chmod -R go+w "$dir/client/apps"
  120. curl -v -L -G -o /tmp/r_hide_card_additional_informations-v0.1.1.zip https://github.com/RestyaPlatform/board-apps/releases/download/v1/r_hide_card_additional_informations-v0.1.1.zip
  121. unzip /tmp/r_hide_card_additional_informations-v0.1.1.zip -d "$dir/client/apps"
  122. esac
  123. }
  124.  
  125. upgrade-0.6.3-0.6.4()
  126. {
  127. if [ -d "$dir/client/apps/r_hide_card_created_date" ]; then
  128. rm -rf $dir/client/apps/r_hide_card_created_date/
  129. chmod -R go+w "$dir/client/apps"
  130. curl -v -L -G -o /tmp/r_hide_card_additional_informations-v0.1.1.zip https://github.com/RestyaPlatform/board-apps/releases/download/v1/r_hide_card_additional_informations-v0.1.1.zip
  131. unzip /tmp/r_hide_card_additional_informations-v0.1.1.zip -d "$dir/client/apps"
  132. fi
  133. }
  134.  
  135. upgrade-0.6.4-0.6.5()
  136. {
  137. if [ -d "$dir/client/apps/r_hide_card_id" ]; then
  138. rm -rf $dir/client/apps/r_hide_card_id/
  139. chmod -R go+w "$dir/client/apps"
  140. curl -v -L -G -o /tmp/r_hide_card_additional_informations-v0.1.2.zip https://github.com/RestyaPlatform/board-apps/releases/download/v1/r_hide_card_additional_informations-v0.1.2.zip
  141. unzip /tmp/r_hide_card_additional_informations-v0.1.2.zip -d "$dir/client/apps"
  142. fi
  143. }
  144.  
  145. update_version()
  146. {
  147. set +x
  148. echo -e "A newer version ${RESTYABOARD_VERSION} of Restyaboard is available.\n\nImportant: Please note that upgrading will remove any commercial apps that were free in previous version.\nFor more details about commercial apps, please visit http://restya.com/board/pricing\n\nDo you want to get it now y/n?"
  149. read -r answer
  150. set -x
  151. case "${answer}" in
  152. [Yy])
  153. set +x
  154. echo "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):"
  155. read -r dir
  156. while [[ -z "$dir" ]]
  157. do
  158. read -r -p "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):" dir
  159. done
  160. set -x
  161.  
  162. echo "Downloading files..."
  163. curl -v -L -G -d "app=board&ver=${RESTYABOARD_VERSION}" -o /tmp/restyaboard.zip http://restya.com/download.php
  164. unzip /tmp/restyaboard.zip -d ${DOWNLOAD_DIR}
  165.  
  166. echo "Updating files..."
  167. cp -r ${DOWNLOAD_DIR}/. "$dir"
  168.  
  169. echo "Connecting database to run SQL changes..."
  170. psql -U postgres -c "\q"
  171. error_code=$?
  172. if [ ${error_code} != 0 ]
  173. then
  174. echo "PostgreSQL database connection failed with error code ${error_code} (PostgreSQL database connection failed with error code 32)"
  175. return 32
  176. fi
  177. sleep 1
  178.  
  179. echo "Changing PostgreSQL database name, user and password..."
  180. sed -i "s/^.*'R_DB_NAME'.*$/define('R_DB_NAME', '${POSTGRES_DBNAME}');/g" "$dir/server/php/config.inc.php"
  181. sed -i "s/^.*'R_DB_USER'.*$/define('R_DB_USER', '${POSTGRES_DBUSER}');/g" "$dir/server/php/config.inc.php"
  182. sed -i "s/^.*'R_DB_PASSWORD'.*$/define('R_DB_PASSWORD', '${POSTGRES_DBPASS}');/g" "$dir/server/php/config.inc.php"
  183. sed -i "s/^.*'R_DB_HOST'.*$/define('R_DB_HOST', '${POSTGRES_DBHOST}');/g" "$dir/server/php/config.inc.php"
  184. sed -i "s/^.*'R_DB_PORT'.*$/define('R_DB_PORT', '${POSTGRES_DBPORT}');/g" "$dir/server/php/config.inc.php"
  185. PHP_VERSION=$(php --version | head -n 1 | cut -d " " -f 2 | grep --only-matching --perl-regexp "^\\d\.\\d+")
  186. version=$(cat ${DOWNLOAD_DIR}/release)
  187. declare -a upgrade;
  188. if [[ $version < "v0.4" ]];
  189. then
  190. upgrade+=("upgrade-0.3-0.4")
  191. fi
  192. if [[ $version < "v0.4.1" ]];
  193. then
  194. upgrade+=("upgrade-0.4-0.4.1")
  195. fi
  196. if [[ $version < "v0.5" ]];
  197. then
  198. upgrade+=("upgrade-0.4.2-0.5")
  199. fi
  200. if [[ $version < "v0.5.2" ]];
  201. then
  202. upgrade+=("upgrade-0.5.1-0.5.2")
  203. fi
  204. if [[ $version < "v0.6" ]];
  205. then
  206. upgrade+=("upgrade-0.5.2-0.6")
  207. fi
  208. if [[ $version < "v0.6.1" ]];
  209. then
  210. upgrade+=("upgrade-0.6-0.6.1")
  211. fi
  212. if [[ $version < "v0.6.2" ]];
  213. then
  214. upgrade+=("upgrade-0.6.1-0.6.2")
  215. fi
  216. if [[ $version < "v0.6.3" ]];
  217. then
  218. upgrade+=("upgrade-0.6.2-0.6.3")
  219. fi
  220. if [[ $version < "v0.6.4" ]];
  221. then
  222. upgrade+=("upgrade-0.6.3-0.6.4")
  223. fi
  224. if [[ $version < "v0.6.5" ]];
  225. then
  226. upgrade+=("upgrade-0.6.4-0.6.5")
  227. fi
  228. # use for loop to read all values and indexes
  229. for i in "${upgrade[@]}"
  230. do
  231. if [ "$(type -t ${i})" = function ];
  232. then
  233. eval ${i}
  234. fi
  235. if [ -f "$dir/sql/${i}.sql" ];
  236. then
  237. echo "Updating SQL..."
  238. psql -d ${POSTGRES_DBNAME} -f "$dir/sql/${i}.sql" -U ${POSTGRES_DBUSER}
  239. error_code=$?
  240. if [ ${error_code} != 0 ]
  241. then
  242. echo "PostgreSQL updation of SQL failed with error code ${error_code} (PostgreSQL updation of SQL failed with error code 33)"
  243. return 33
  244. fi
  245. fi
  246. done
  247. /bin/echo "$RESTYABOARD_VERSION" > ${DOWNLOAD_DIR}/release
  248.  
  249. if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
  250. then
  251. service nginx restart
  252. service php${PHP_VERSION}-fpm restart
  253. else
  254. if [ -f "/bin/systemctl" ]; then
  255. echo "Starting services with systemd..."
  256. systemctl restart nginx
  257. systemctl restart php-fpm
  258. else
  259. echo "Starting services..."
  260. /etc/init.d/php-fpm restart
  261. /etc/init.d/nginx restart
  262. fi
  263. fi
  264.  
  265. esac
  266. }
  267.  
  268. if [ -f "$DOWNLOAD_DIR/release" ];
  269. then
  270. version=$(cat ${DOWNLOAD_DIR}/release)
  271. if [[ $version < $RESTYABOARD_VERSION ]];
  272. then
  273. update_version
  274. exit
  275. else
  276. echo "No new version available"
  277. exit;
  278. fi
  279. else
  280. set +x
  281. echo "Is Restyaboard already installed and configured/working y/n?"
  282. read -r answer
  283. set -x
  284. case "${answer}" in
  285. [Yy])
  286. update_version
  287. exit
  288. esac
  289. fi
  290. if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
  291. then
  292. set +x
  293. echo "Setup script will install version ${RESTYABOARD_VERSION} and create database ${POSTGRES_DBNAME} with user ${POSTGRES_DBUSER} and password ${POSTGRES_DBPASS}. To continue enter \"y\" or to quit the process and edit the version and database details enter \"n\" (y/n)?"
  294. read -r answer
  295. set -x
  296. case "${answer}" in
  297. [Yy])
  298. apt-get install debian-keyring debian-archive-keyring
  299. error_code=$?
  300. if [ ${error_code} != 0 ]
  301. then
  302. echo "debian-keyring installation failed with error code ${error_code} (debian-keyring installation failed with error code 1)"
  303. fi
  304.  
  305. apt-get update -y
  306. apt-get upgrade -y
  307. apt-get install python-software-properties software-properties-common -y
  308. add-apt-repository ppa:ondrej/php
  309. apt-get update -y
  310. apt-get install libjpeg8 -y --allow-unauthenticated
  311.  
  312. echo "Checking nginx..."
  313. if ! which nginx > /dev/null 2>&1; then
  314. echo "nginx not installed!"
  315. set +x
  316. echo "Do you want to install nginx (y/n)?"
  317. read -r answer
  318. set -x
  319. case "${answer}" in
  320. [Yy])
  321. echo "Installing nginx..."
  322. apt-get install -y cron nginx
  323. error_code=$?
  324. if [ ${error_code} != 0 ]
  325. then
  326. echo "nginx installation failed with error code ${error_code} (nginx installation failed with error code 2)"
  327. return 2
  328. fi
  329. service nginx start
  330. esac
  331. fi
  332.  
  333. echo "Checking PHP..."
  334. if ! hash php 2>&-; then
  335. echo "PHP is not installed!"
  336. set +x
  337. echo "Do you want to install PHP (y/n)?"
  338. read -r answer
  339. set -x
  340. case "${answer}" in
  341. [Yy])
  342. echo "Installing PHP..."
  343. apt-get install -y php7.2 php7.2-common --allow-unauthenticated
  344. error_code=$?
  345. if [ ${error_code} != 0 ]
  346. then
  347. echo "PHP installation failed with error code ${error_code} (PHP installation failed with error code 3)"
  348. return 3
  349. fi
  350. esac
  351. fi
  352.  
  353. echo "Installing PHP fpm and cli extension..."
  354. apt-get install -y php7.2-fpm php7.2-cli --allow-unauthenticated
  355. error_code=$?
  356. if [ ${error_code} != 0 ]
  357. then
  358. echo "php7.2-cli installation failed with error code ${error_code} (php7.2-cli installation failed with error code 4)"
  359. fi
  360. service php7.2-fpm start
  361.  
  362. echo "Checking PHP curl extension..."
  363. php -m | grep curl
  364. if [ "$?" -gt 0 ]; then
  365. echo "Installing php7.2-curl..."
  366. apt-get install -y php7.2-curl --allow-unauthenticated
  367. error_code=$?
  368. if [ ${error_code} != 0 ]
  369. then
  370. echo "php7.2-curl installation failed with error code ${error_code} (php7.2-curl installation failed with error code 5)"
  371. return 5
  372. fi
  373. fi
  374.  
  375. echo "Checking PHP pgsql extension..."
  376. php -m | grep pgsql
  377. if [ "$?" -gt 0 ]; then
  378. echo "Installing php7.2-pgsql..."
  379. apt-get install libpq5
  380. apt-get install -y php7.2-pgsql --allow-unauthenticated
  381. error_code=$?
  382. if [ ${error_code} != 0 ]
  383. then
  384. echo "php7.2-pgsql installation failed with error code ${error_code} (php7.2-pgsql installation failed with error code 6)"
  385. return 6
  386. fi
  387. fi
  388.  
  389. echo "Checking PHP mbstring extension..."
  390. php -m | grep mbstring
  391. if [ "$?" -gt 0 ]; then
  392. echo "Installing php7.2-mbstring..."
  393. apt-get install -y php7.2-mbstring --allow-unauthenticated
  394. error_code=$?
  395. if [ ${error_code} != 0 ]
  396. then
  397. echo "php7.2-mbstring installation failed with error code ${error_code} (php7.2-mbstring installation failed with error code 7)"
  398. return 7
  399. fi
  400. fi
  401.  
  402. echo "Checking PHP ldap extension..."
  403. php -m | grep ldap
  404. if [ "$?" -gt 0 ]; then
  405. echo "Installing php7.2-ldap..."
  406. apt-get install -y php7.2-ldap --allow-unauthenticated
  407. error_code=$?
  408. if [ ${error_code} != 0 ]
  409. then
  410. echo "php7.2-ldap installation failed with error code ${error_code} (php7.2-ldap installation failed with error code 8)"
  411. return 8
  412. fi
  413. fi
  414.  
  415. echo "Checking PHP imagick extension..."
  416. php -m | grep imagick
  417. if [ "$?" -gt 0 ]; then
  418. echo "Installing php7.2-imagick..."
  419. apt-get install -y gcc
  420. error_code=$?
  421. if [ ${error_code} != 0 ]
  422. then
  423. echo "gcc installation failed with error code ${error_code} (gcc installation failed with error code 9)"
  424. return 9
  425. fi
  426. apt-get install -y imagemagick
  427. error_code=$?
  428. if [ ${error_code} != 0 ]
  429. then
  430. echo "imagemagick installation failed with error code ${error_code} (imagemagick installation failed with error code 9)"
  431. return 9
  432. fi
  433. apt-get install -y php7.2-imagick --allow-unauthenticated
  434. error_code=$?
  435. if [ ${error_code} != 0 ]
  436. then
  437. echo "php7.2-imagick installation failed with error code ${error_code} (php7.2-imagick installation failed with error code 10)"
  438. return 10
  439. fi
  440. fi
  441.  
  442. echo "Checking PHP imap extension..."
  443. php -m | grep imap
  444. if [ "$?" -gt 0 ]; then
  445. echo "Installing php7.2-imap..."
  446. apt-get install -y php7.2-imap --allow-unauthenticated
  447. error_code=$?
  448. if [ ${error_code} != 0 ]
  449. then
  450. echo "php7.2-imap installation failed with error code ${error_code} (php7.2-imap installation failed with error code 11)"
  451. return 11
  452. fi
  453. fi
  454.  
  455. echo "Checking xml..."
  456. php -m | grep xml
  457. if [ "$?" -gt 0 ]; then
  458. echo "Installing xml..."
  459. apt-get install php7.2-xml --allow-unauthenticated
  460. error_code=$?
  461. if [ ${error_code} != 0 ]
  462. then
  463. echo "xml installation failed with error code ${error_code} (xml installation failed with error code 56)"
  464. return 56
  465. fi
  466. fi
  467.  
  468. echo "Setting up timezone..."
  469. timezone=$(cat /etc/timezone)
  470. sed -i -e 's/date.timezone/;date.timezone/g' /etc/php/7.2/fpm/php.ini
  471. echo "date.timezone = $timezone" >> /etc/php/7.2/fpm/php.ini
  472.  
  473. echo "Checking PostgreSQL..."
  474. id -a postgres
  475. error_code=$?
  476. if [ ${error_code} != 0 ]; then
  477. echo "PostgreSQL not installed!"
  478. set +x
  479. echo "Do you want to install PostgreSQL (y/n)?"
  480. read -r answer
  481. set -x
  482. case "${answer}" in
  483. [Yy])
  484. echo "Installing PostgreSQL..."
  485. sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  486. apt-get install wget ca-certificates
  487. error_code=$?
  488. if [ ${error_code} != 0 ]
  489. then
  490. echo "ca-certificates installation failed with error code ${error_code} (ca-certificates installation failed with error code 12)"
  491. fi
  492. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc
  493. apt-key add ACCC4CF8.asc
  494. apt-get update
  495. apt-get install -y postgresql-9.6 --allow-unauthenticated
  496. error_code=$?
  497. if [ ${error_code} != 0 ]
  498. then
  499. echo "postgresql-9.6 installation failed with error code ${error_code} (postgresql-9.6 installation failed with error code 13)"
  500. return 13
  501. fi
  502. esac
  503. else
  504. PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
  505. if [[ $PSQL_VERSION < 9.3 ]]; then
  506. set +x
  507. echo "Restyaboard will not work in your PostgreSQL version (i.e. less than 9.3). So script going to update PostgreSQL version 9.6"
  508. sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  509. apt-get install wget ca-certificates
  510. error_code=$?
  511. if [ ${error_code} != 0 ]
  512. then
  513. echo "ca-certificates installation failed with error code ${error_code} (ca-certificates installation failed with error code 12)"
  514. fi
  515. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc
  516. apt-key add ACCC4CF8.asc
  517. apt-get update
  518. apt-get upgrade
  519. apt-get install -y postgresql-9.6 --allow-unauthenticated
  520. error_code=$?
  521. if [ ${error_code} != 0 ]
  522. then
  523. echo "postgresql-9.6 installation failed with error code ${error_code} (postgresql-9.6 installation failed with error code 13)"
  524. return 13
  525. fi
  526. fi
  527. fi
  528. PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
  529. sed -e 's/peer/trust/g' -e 's/ident/trust/g' < /etc/postgresql/${PSQL_VERSION}/main/pg_hba.conf > /etc/postgresql/${PSQL_VERSION}/main/pg_hba.conf.1
  530. cd /etc/postgresql/${PSQL_VERSION}/main || exit
  531. mv pg_hba.conf pg_hba.conf_old
  532. mv pg_hba.conf.1 pg_hba.conf
  533. service postgresql restart
  534.  
  535. if ! hash GeoIP-devel 2>&-;
  536. then
  537. apt-get install -y php7.2-geoip php7.2-dev libgeoip-dev
  538. error_code=$?
  539. if [ ${error_code} != 0 ]
  540. then
  541. echo "php7.2-geoip php7.2-dev libgeoip-dev installation failed with error code ${error_code} (php7.2-geoip php7.2-dev libgeoip-dev installation failed with error code 50)"
  542. fi
  543. fi
  544.  
  545. if ! hash pecl/geoip 2>&-;
  546. then
  547. pecl install geoip
  548. error_code=$?
  549. if [ ${error_code} != 0 ]
  550. then
  551. echo "pecl geoip installation failed with error code ${error_code} (pecl geoip installation failed with error code 47)"
  552. fi
  553. fi
  554.  
  555. echo "extension=geoip.so" >> /etc/php.ini
  556.  
  557. mkdir -v /usr/share/GeoIP
  558. error_code=$?
  559. if [ ${error_code} != 0 ]
  560. then
  561. echo "GeoIP folder creation failed with error code ${error_code} (GeoIP folder creation failed with error code 52)"
  562. fi
  563.  
  564. get_geoip_data
  565.  
  566. apt-get install -y autotools-dev
  567.  
  568. apt-get install -y automake
  569.  
  570. apt-get install -y erlang
  571.  
  572. apt-get install -y libyaml-dev
  573.  
  574. apt-get install -y rebar
  575.  
  576. cd /opt
  577. wget http://liquidtelecom.dl.sourceforge.net/project/expat/expat/2.1.1/expat-2.1.1.tar.bz2
  578. tar -jvxf expat-2.1.1.tar.bz2
  579. cd expat-2.1.1/
  580. ./configure
  581. make
  582. make install
  583.  
  584. echo "Downloading Restyaboard script..."
  585. apt-get install -y curl
  586. mkdir ${DOWNLOAD_DIR}
  587. curl -v -L -G -d "app=board&ver=${RESTYABOARD_VERSION}" -o /tmp/restyaboard.zip http://restya.com/download.php
  588. unzip /tmp/restyaboard.zip -d ${DOWNLOAD_DIR}
  589. cp ${DOWNLOAD_DIR}/restyaboard.conf /etc/nginx/conf.d
  590. rm /tmp/restyaboard.zip
  591.  
  592. set +x
  593. echo "To configure nginx, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):"
  594. read -r webdir
  595. while [[ -z "$webdir" ]]
  596. do
  597. read -r -p "To configure nginx, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):" webdir
  598. done
  599. set -x
  600. echo "$webdir"
  601. echo "Changing server_name in nginx configuration..."
  602. sed -i "s/server_name.*$/server_name \"$webdir\";/" /etc/nginx/conf.d/restyaboard.conf
  603. sed -i "s|listen 80.*$|listen 80;|" /etc/nginx/conf.d/restyaboard.conf
  604.  
  605. set +x
  606. echo "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):"
  607. read -r dir
  608. while [[ -z "$dir" ]]
  609. do
  610. read -r -p "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):" dir
  611. done
  612. set -x
  613. echo "$dir"
  614. mkdir -p "$dir"
  615. echo "Changing root directory in nginx configuration..."
  616. sed -i "s|root.*html|root $dir|" /etc/nginx/conf.d/restyaboard.conf
  617. echo "Copying Restyaboard script to root directory..."
  618. cp -r ${DOWNLOAD_DIR}/* "$dir"
  619.  
  620. echo "Installing postfix..."
  621. echo "postfix postfix/mailname string $webdir"\
  622. | debconf-set-selections &&\
  623. echo "postfix postfix/main_mailer_type string 'Internet Site'"\
  624. | debconf-set-selections &&\
  625. apt-get install -y postfix
  626. error_code=$?
  627. if [ ${error_code} != 0 ]
  628. then
  629. echo "postfix installation failed with error code ${error_code} (postfix installation failed with error code 16)"
  630. fi
  631. echo "Changing permission..."
  632. find $dir -type d -exec chmod 755 {} \;
  633. find $dir -type f -exec chmod 644 {} \;
  634. chmod -R go+w "$dir/media"
  635. chmod -R go+w "$dir/client/img"
  636. chmod -R go+w "$dir/tmp/cache"
  637. chmod -R 0755 $dir/server/php/shell/*.sh
  638.  
  639. psql -U postgres -c "\q"
  640. error_code=$?
  641. if [ ${error_code} != 0 ]
  642. then
  643. echo "PostgreSQL Changing the permission failed with error code ${error_code} (PostgreSQL Changing the permission failed with error code 34)"
  644. return 34
  645. fi
  646. sleep 1
  647.  
  648. echo "Creating PostgreSQL user and database..."
  649. psql -U postgres -c "DROP USER IF EXISTS ${POSTGRES_DBUSER};CREATE USER ${POSTGRES_DBUSER} WITH ENCRYPTED PASSWORD '${POSTGRES_DBPASS}'"
  650. error_code=$?
  651. if [ ${error_code} != 0 ]
  652. then
  653. echo "PostgreSQL user creation failed with error code ${error_code} (PostgreSQL user creation failed with error code 35)"
  654. return 35
  655. fi
  656. psql -U postgres -c "CREATE DATABASE ${POSTGRES_DBNAME} OWNER ${POSTGRES_DBUSER} ENCODING 'UTF8' TEMPLATE template0"
  657. error_code=$?
  658. if [ ${error_code} != 0 ]
  659. then
  660. echo "PostgreSQL database creation failed with error code ${error_code} (PostgreSQL database creation failed with error code 36)"
  661. return 36
  662. fi
  663. psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;"
  664. error_code=$?
  665. if [ ${error_code} != 0 ]
  666. then
  667. echo "PostgreSQL extension creation failed with error code ${error_code} (PostgreSQL extension creation failed with error code 37)"
  668. return 37
  669. fi
  670. psql -U postgres -c "COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';"
  671. error_code=$?
  672. if [ ${error_code} = 0 ];
  673. then
  674. echo "Importing empty SQL..."
  675. psql -d ${POSTGRES_DBNAME} -f "$dir/sql/restyaboard_with_empty_data.sql" -U ${POSTGRES_DBUSER}
  676. if [ ${error_code} != 0 ]
  677. then
  678. echo "PostgreSQL Empty SQL importing failed with error code ${error_code} (PostgreSQL Empty SQL importing failed with error code 39)"
  679. return 39
  680. fi
  681. fi
  682.  
  683. echo "Changing PostgreSQL database name, user and password..."
  684. sed -i "s/^.*'R_DB_NAME'.*$/define('R_DB_NAME', '${POSTGRES_DBNAME}');/g" "$dir/server/php/config.inc.php"
  685. sed -i "s/^.*'R_DB_USER'.*$/define('R_DB_USER', '${POSTGRES_DBUSER}');/g" "$dir/server/php/config.inc.php"
  686. sed -i "s/^.*'R_DB_PASSWORD'.*$/define('R_DB_PASSWORD', '${POSTGRES_DBPASS}');/g" "$dir/server/php/config.inc.php"
  687. sed -i "s/^.*'R_DB_HOST'.*$/define('R_DB_HOST', '${POSTGRES_DBHOST}');/g" "$dir/server/php/config.inc.php"
  688. sed -i "s/^.*'R_DB_PORT'.*$/define('R_DB_PORT', '${POSTGRES_DBPORT}');/g" "$dir/server/php/config.inc.php"
  689.  
  690. echo "Setting up cron for every 5 minutes to send email notification to user, if the user chosen notification type as instant..."
  691. echo "*/5 * * * * $dir/server/php/shell/instant_email_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/root
  692.  
  693. echo "Setting up cron for every 1 hour to send email notification to user, if the user chosen notification type as periodic..."
  694. echo "0 * * * * $dir/server/php/shell/periodic_email_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/root
  695.  
  696. echo "Setting up cron for every 30 minutes to fetch IMAP email..."
  697. echo "*/30 * * * * $dir/server/php/shell/imap.sh > /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/root
  698.  
  699. echo "Setting up cron for every 5 minutes to send activities to webhook..."
  700. echo "*/5 * * * * $dir/server/php/shell/webhook.sh > /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/root
  701.  
  702. echo "Setting up cron for every 5 minutes to send email notification to past due..."
  703. echo "*/5 * * * * $dir/server/php/shell/card_due_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/crontabs/root
  704.  
  705. set +x
  706. echo "Do you want to install Restyaboard apps (y/n)?"
  707. read -r answer
  708. set -x
  709. case "${answer}" in
  710. [Yy])
  711. if ! hash jq 2>&-;
  712. then
  713. echo "Installing jq..."
  714. apt-get install -y jq
  715. error_code=$?
  716. if [ ${error_code} != 0 ]
  717. then
  718. echo "jq installation failed with error code ${error_code} (jq installation failed with error code 53)"
  719. fi
  720. fi
  721. mkdir "$dir/client/apps"
  722. chmod -R go+w "$dir/client/apps"
  723. curl -v -L -G -o /tmp/apps.json https://raw.githubusercontent.com/RestyaPlatform/board-apps/master/apps.json
  724. chmod -R go+w "/tmp/apps.json"
  725. for fid in `jq -r '.[] | .id + "-v" + .version + "#" + .price' /tmp/apps.json`
  726. do
  727. app_name=$(echo ${fid} | cut -d"#" -f1)
  728. app_price=$(echo ${fid} | cut -d"#" -f2)
  729. if ([ "$app_price" = "Free" ])
  730. then
  731. curl -v -L -G -o /tmp/$app_name.zip https://github.com/RestyaPlatform/board-apps/releases/download/v1/$app_name.zip
  732. unzip /tmp/$app_name.zip -d "$dir/client/apps"
  733. fi
  734. done
  735. esac
  736.  
  737. echo "Starting services..."
  738. service cron restart
  739. service php7.2-fpm restart
  740. service nginx restart
  741. service postfix restart
  742. apt install -y python-pip
  743. pip install virtualenv
  744. esac
  745. else
  746. set +x
  747. echo "Setup script will install version ${RESTYABOARD_VERSION} and create database ${POSTGRES_DBNAME} with user ${POSTGRES_DBUSER} and password ${POSTGRES_DBPASS}. To continue enter \"y\" or to quit the process and edit the version and database details enter \"n\" (y/n)?"
  748. read -r answer
  749. set -x
  750. case "${answer}" in
  751. [Yy])
  752.  
  753. echo "Checking nginx..."
  754. if ! which nginx > /dev/null 2>&1;
  755. then
  756. echo "nginx not installed!"
  757. set +x
  758. echo "Do you want to install nginx (y/n)?"
  759. read -r answer
  760. set -x
  761. case "${answer}" in
  762. [Yy])
  763. echo "Installing nginx..."
  764. rpm -Uvh "http://nginx.org/packages/centos/${OS_VERSION}/noarch/RPMS/nginx-release-centos-${OS_VERSION}-0.el${OS_VERSION}.ngx.noarch.rpm"
  765. yum install -y zip cronie nginx
  766. error_code=$?
  767. if [ ${error_code} != 0 ]
  768. then
  769. echo "cron nginx installation failed with error code ${error_code} cron nginx installation failed with error code 18"
  770. return 18
  771. fi
  772. service nginx start
  773. chkconfig --levels 35 nginx on
  774. esac
  775. fi
  776.  
  777. echo "Checking PHP..."
  778. if ! hash php 2>&-;
  779. then
  780. echo "PHP is not installed!"
  781. set +x
  782. echo "Do you want to install PHP (y/n)?"
  783. read -r answer
  784. set -x
  785. case "${answer}" in
  786. [Yy])
  787. echo "Note: For the latest version of PHP, we're going to download https://mirror.webtatic.com/yum/el${OS_VERSION}/webtatic-release.rpm."
  788. echo "Installing PHP..."
  789. rpm -Uvh "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${OS_VERSION}.noarch.rpm"
  790. rpm -Uvh "https://mirror.webtatic.com/yum/el${OS_VERSION}/webtatic-release.rpm"
  791. yum install -y php72w php72w-opcache
  792. error_code=$?
  793. if [ ${error_code} != 0 ]
  794. then
  795. echo "php installation failed with error code ${error_code} (php installation failed with error code 20)"
  796. return 20
  797. fi
  798. esac
  799. fi
  800.  
  801. echo "Installing PHP fpm and cli extension..."
  802. yum install -y php72w-fpm php72w-devel php72w-cli php72w-opcache
  803. error_code=$?
  804. if [ ${error_code} != 0 ]
  805. then
  806. echo "php-devel installation failed with error code ${error_code} (php-devel installation failed with error code 21)"
  807. return 21
  808. fi
  809. service php-fpm start
  810. chkconfig --levels 35 php72w-fpm on
  811.  
  812. echo "Checking PHP curl extension..."
  813. php -m | grep curl
  814. if [ "$?" -gt 0 ];
  815. then
  816. echo "Installing php-curl..."
  817. yum install -y php72w-curl
  818. error_code=$?
  819. if [ ${error_code} != 0 ]
  820. then
  821. echo "php-curl installation failed with error code ${error_code} (php-curl installation failed with error code 22)"
  822. return 22
  823. fi
  824. fi
  825.  
  826. echo "Checking PHP pgsql extension..."
  827. php -m | grep pgsql
  828. if [ "$?" -gt 0 ];
  829. then
  830. echo "Installing php-pgsql..."
  831. yum install -y php72w-pgsql
  832. error_code=$?
  833. if [ ${error_code} != 0 ]
  834. then
  835. echo "php-pgsql installation failed with error code ${error_code} (php-pgsql installation failed with error code 23)"
  836. return 23
  837. fi
  838. fi
  839.  
  840. echo "Checking PHP mbstring extension..."
  841. php -m | grep mbstring
  842. if [ "$?" -gt 0 ];
  843. then
  844. echo "Installing php-mbstring..."
  845. yum install -y php72w-mbstring
  846. error_code=$?
  847. if [ ${error_code} != 0 ]
  848. then
  849. echo "php-mbstring installation failed with error code ${error_code} (php-mbstring installation failed with error code 24)"
  850. return 24
  851. fi
  852. fi
  853.  
  854. echo "Checking PHP ldap extension..."
  855. php -m | grep ldap
  856. if [ "$?" -gt 0 ];
  857. then
  858. echo "Installing php-ldap..."
  859. yum install -y php72w-ldap
  860. error_code=$?
  861. if [ ${error_code} != 0 ]
  862. then
  863. echo "php-ldap installation failed with error code ${error_code} (php-ldap installation failed with error code 25)"
  864. return 25
  865. fi
  866. fi
  867.  
  868. echo "Checking PHP imagick extension..."
  869. php -m | grep imagick
  870. if [ "$?" -gt 0 ];
  871. then
  872. echo "Installing php-imagick..."
  873.  
  874. yum install -y ImageM* netpbm gd gd-* libjpeg libexif gcc coreutils make
  875. yum install -y php72w-pear
  876. error_code=$?
  877. if [ ${error_code} != 0 ]
  878. then
  879. echo "Installing php-imagick failed with error code ${error_code} (Installing php-imagick failed with error code 26)"
  880. return 26
  881. fi
  882.  
  883. cd /usr/local/src
  884. wget http://pecl.php.net/get/imagick-2.2.2.tgz
  885. tar zxvf ./imagick-2.2.2.tgz
  886. cd imagick-2.2.2
  887. phpize
  888. ./configure
  889. make
  890. make test
  891. make install
  892. echo "extension=imagick.so" >> /etc/php.ini
  893. fi
  894.  
  895. echo "Checking PHP imap extension..."
  896. php -m | grep imap
  897. if [ "$?" -gt 0 ];
  898. then
  899. echo "Installing php-imap..."
  900. yum install -y php72w-imap
  901. error_code=$?
  902. if [ ${error_code} != 0 ]
  903. then
  904. echo "php-imap installation failed with error code ${error_code} (php-imap installation failed with error code 26)"
  905. return 26
  906. fi
  907.  
  908. fi
  909.  
  910. echo "Checking xml..."
  911. php -m | grep xml
  912. if [ "$?" -gt 0 ]; then
  913. echo "Installing xml..."
  914. yum install -y php72w-xml
  915. error_code=$?
  916. if [ ${error_code} != 0 ]
  917. then
  918. echo "xml installation failed with error code ${error_code} (xml installation failed with error code 57)"
  919. return 57
  920. fi
  921. fi
  922.  
  923. echo "Setting up timezone..."
  924. timezone=$(cat /etc/sysconfig/clock | grep ZONE | cut -d"\"" -f2)
  925. sed -i -e 's/date.timezone/;date.timezone/g' /etc/php.ini
  926. echo "date.timezone = $timezone" >> /etc/php.ini
  927.  
  928. PHP_VERSION=$(php -v | grep "PHP 5" | sed 's/.*PHP \([^-]*\).*/\1/' | cut -c 1-3)
  929. echo "Installed PHP version: '$PHP_VERSION'"
  930.  
  931. echo "Checking PostgreSQL..."
  932. id -a postgres
  933. error_code=$?
  934. if [ ${error_code} != 0 ];
  935. then
  936. echo "PostgreSQL not installed!"
  937. set +x
  938. echo "Do you want to install PostgreSQL (y/n)?"
  939. read -r answer
  940. set -x
  941. case "${answer}" in
  942. [Yy])
  943. echo "Installing PostgreSQL..."
  944. if [ $(getconf LONG_BIT) = "32" ]; then
  945. if [[ $OS_REQUIREMENT = "Fedora" ]]; then
  946. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-${OS_VERSION}-i386/pgdg-fedora96-9.6-3.noarch.rpm"
  947. else
  948. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-${OS_VERSION}-i386/pgdg-redhat96-9.6-3.noarch.rpm"
  949. fi
  950. fi
  951. if [ $(getconf LONG_BIT) = "64" ]; then
  952. if [[ $OS_REQUIREMENT = "Fedora" ]]; then
  953. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-${OS_VERSION}-x86_64/pgdg-fedora96-9.6-3.noarch.rpm"
  954. else
  955. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-${OS_VERSION}-x86_64/pgdg-redhat96-9.6-3.noarch.rpm"
  956. fi
  957. fi
  958.  
  959. yum install -y postgresql96 postgresql96-server postgresql96-contrib postgresql96-libs
  960. error_code=$?
  961. if [ ${error_code} != 0 ]
  962. then
  963. echo "postgresql96 installation failed with error code ${error_code} (postgresql96 installation failed with error code 29)"
  964. return 29
  965. fi
  966. esac
  967. else
  968. PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
  969. if [[ $PSQL_VERSION < 9.3 ]]; then
  970. set +x
  971. echo "Restyaboard will not work in your PostgreSQL version (i.e. less than 9.3). So script going to update PostgreSQL version 9.6"
  972. if [ $(getconf LONG_BIT) = "32" ]; then
  973. if [[ $OS_REQUIREMENT = "Fedora" ]]; then
  974. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-${OS_VERSION}-i386/pgdg-fedora96-9.6-3.noarch.rpm"
  975. else
  976. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-${OS_VERSION}-i386/pgdg-redhat96-9.6-3.noarch.rpm"
  977. fi
  978. else
  979. if [[ $OS_REQUIREMENT = "Fedora" ]]; then
  980. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/fedora/fedora-${OS_VERSION}-x86_64/pgdg-fedora96-9.6-3.noarch.rpm"
  981. else
  982. rpm -Uvh "https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-${OS_VERSION}-x86_64/pgdg-redhat96-9.6-3.noarch.rpm"
  983. fi
  984. fi
  985.  
  986. yum install -y postgresql96 postgresql96-server postgresql96-contrib postgresql96-libs
  987. error_code=$?
  988. if [ ${error_code} != 0 ]
  989. then
  990. echo "postgresql installation failed with error code ${error_code} (postgresql installation failed with error code 29)"
  991. return 29
  992. fi
  993. fi
  994. fi
  995.  
  996. PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
  997. PSQL_FOLDER=$(echo ${PSQL_VERSION} | sed 's/\.//')
  998. if [ -f "/usr/pgsql-${PSQL_VERSION}/bin/postgresql${PSQL_FOLDER}-setup" ]; then
  999. "/usr/pgsql-${PSQL_VERSION}/bin/postgresql${PSQL_FOLDER}-setup" initdb
  1000. fi
  1001. if [ -f "/bin/systemctl" ]; then
  1002. systemctl start "postgresql-${PSQL_VERSION}.service"
  1003. systemctl enable "postgresql-${PSQL_VERSION}.service"
  1004. else
  1005. "/etc/init.d/postgresql-${PSQL_VERSION}" start
  1006. chkconfig --levels 35 "postgresql-${PSQL_VERSION}" on
  1007. fi
  1008.  
  1009. sed -e 's/peer/trust/g' -e 's/ident/trust/g' < "/var/lib/pgsql/${PSQL_VERSION}/data/pg_hba.conf" > "/var/lib/pgsql/${PSQL_VERSION}/data/pg_hba.conf.1"
  1010. cd "/var/lib/pgsql/${PSQL_VERSION}/data" || exit
  1011. mv pg_hba.conf pg_hba.conf_old
  1012. mv pg_hba.conf.1 pg_hba.conf
  1013.  
  1014. if [ -f "/bin/systemctl" ]; then
  1015. systemctl restart "postgresql-${PSQL_VERSION}.service"
  1016. else
  1017. "/etc/init.d/postgresql-${PSQL_VERSION}" restart
  1018. fi
  1019.  
  1020. if ! hash pecl/geoip 2>&-;
  1021. then
  1022. pecl install geoip
  1023. error_code=$?
  1024. if [ ${error_code} != 0 ]
  1025. then
  1026. echo "pecl geoip installation failed with error code ${error_code} (pecl geoip installation failed with error code 47)"
  1027. return 47
  1028. fi
  1029. fi
  1030.  
  1031. yum install -y git
  1032. git clone git://github.com/rebar/rebar.git
  1033. cd rebar
  1034. ./bootstrap
  1035.  
  1036. yum install -y gcc glibc-devel make ncurses-devel openssl-devel autoconf expat-devel
  1037.  
  1038. cd /opt
  1039. wget http://erlang.org/download/otp_src_R15B01.tar.gz
  1040. tar zxvf otp_src_R15B01.tar.gz
  1041. cd otp_src_R15B01
  1042. ./configure && make && make install
  1043.  
  1044. yum install -y php-xml
  1045.  
  1046. echo "Downloading Restyaboard script..."
  1047. mkdir ${DOWNLOAD_DIR}
  1048. curl -v -L -G -d "app=board&ver=${RESTYABOARD_VERSION}" -o /tmp/restyaboard.zip http://restya.com/download.php
  1049. unzip /tmp/restyaboard.zip -d ${DOWNLOAD_DIR}
  1050. cp ${DOWNLOAD_DIR}/restyaboard.conf /etc/nginx/conf.d
  1051. rm /tmp/restyaboard.zip
  1052.  
  1053. set +x
  1054. echo "To configure nginx, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):"
  1055. read -r webdir
  1056. while [[ -z "$webdir" ]]
  1057. do
  1058. read -r -p "To configure nginx, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):" webdir
  1059. done
  1060. set -x
  1061. echo "$webdir"
  1062. echo "Changing server_name in nginx configuration..."
  1063. sed -i "s/server_name.*$/server_name \"$webdir\";/" /etc/nginx/conf.d/restyaboard.conf
  1064. sed -i "s|listen 80.*$|listen 80;|" /etc/nginx/conf.d/restyaboard.conf
  1065.  
  1066. set +x
  1067. echo "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):"
  1068. read -r dir
  1069. while [[ -z "$dir" ]]
  1070. do
  1071. read -r -p "Enter your document root (where your Restyaboard to be installed. e.g., /usr/share/nginx/html/restyaboard):" dir
  1072. done
  1073. set -x
  1074. echo "$dir"
  1075. mkdir -p "$dir"
  1076. echo "Changing root directory in nginx configuration..."
  1077. sed -i "s|root.*html|root $dir|" /etc/nginx/conf.d/restyaboard.conf
  1078. echo "Copying Restyaboard script to root directory..."
  1079. cp -r "$DOWNLOAD_DIR"/* "$dir"
  1080.  
  1081. echo "Changing permission..."
  1082. find $dir -type d -exec chmod 755 {} \;
  1083. find $dir -type f -exec chmod 644 {} \;
  1084. chmod -R go+w "$dir/media"
  1085. chmod -R go+w "$dir/client/img"
  1086. chmod -R go+w "$dir/tmp/cache"
  1087. chmod -R 0755 $dir/server/php/shell/*.sh
  1088.  
  1089. psql -U postgres -c "\q"
  1090. error_code=$?
  1091. if [ ${error_code} != 0 ]
  1092. then
  1093. echo "PostgreSQL Changing the permission failed with error code ${error_code} (PostgreSQL Changing the permission failed with error code 40)"
  1094. return 40
  1095. fi
  1096. sleep 1
  1097.  
  1098. echo "Creating PostgreSQL user and database..."
  1099. psql -U postgres -c "DROP USER IF EXISTS ${POSTGRES_DBUSER};CREATE USER ${POSTGRES_DBUSER} WITH ENCRYPTED PASSWORD '${POSTGRES_DBPASS}'"
  1100. error_code=$?
  1101. if [ ${error_code} != 0 ]
  1102. then
  1103. echo "PostgreSQL user creation failed with error code ${error_code} (PostgreSQL user creation failed with error code 41)"
  1104. return 41
  1105. fi
  1106. psql -U postgres -c "CREATE DATABASE ${POSTGRES_DBNAME} OWNER ${POSTGRES_DBUSER} ENCODING 'UTF8' TEMPLATE template0"
  1107. error_code=$?
  1108. if [ ${error_code} != 0 ]
  1109. then
  1110. echo "PostgreSQL database creation failed with error code ${error_code} (PostgreSQL database creation failed with error code 42)"
  1111. return 42
  1112. fi
  1113. psql -U postgres -c "CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;"
  1114. error_code=$?
  1115. if [ ${error_code} != 0 ]
  1116. then
  1117. echo "PostgreSQL extension creation failed with error code ${error_code} (PostgreSQL extension creation failed with error code 43)"
  1118. return 43
  1119. fi
  1120. psql -U postgres -c "COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';"
  1121. if [ "$?" = 0 ];
  1122. then
  1123. echo "Importing empty SQL..."
  1124. psql -d ${POSTGRES_DBNAME} -f "$dir/sql/restyaboard_with_empty_data.sql" -U ${POSTGRES_DBUSER}
  1125. error_code=$?
  1126. if [ ${error_code} != 0 ]
  1127. then
  1128. echo "PostgreSQL Empty SQL importing failed with error code ${error_code} (PostgreSQL Empty SQL importing failed with error code 45)"
  1129. return 45
  1130. fi
  1131. fi
  1132.  
  1133. echo "Changing PostgreSQL database name, user and password..."
  1134. sed -i "s/^.*'R_DB_NAME'.*$/define('R_DB_NAME', '${POSTGRES_DBNAME}');/g" "$dir/server/php/config.inc.php"
  1135. sed -i "s/^.*'R_DB_USER'.*$/define('R_DB_USER', '${POSTGRES_DBUSER}');/g" "$dir/server/php/config.inc.php"
  1136. sed -i "s/^.*'R_DB_PASSWORD'.*$/define('R_DB_PASSWORD', '${POSTGRES_DBPASS}');/g" "$dir/server/php/config.inc.php"
  1137. sed -i "s/^.*'R_DB_HOST'.*$/define('R_DB_HOST', '${POSTGRES_DBHOST}');/g" "$dir/server/php/config.inc.php"
  1138. sed -i "s/^.*'R_DB_PORT'.*$/define('R_DB_PORT', '${POSTGRES_DBPORT}');/g" "$dir/server/php/config.inc.php"
  1139.  
  1140. echo "Setting up cron for every 5 minutes to send email notification to user, if the user chosen notification type as instant..."
  1141. echo "*/5 * * * * $dir/server/php/shell/instant_email_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/root
  1142.  
  1143. echo "Setting up cron for every 1 hour to send email notification to user, if the user chosen notification type as periodic..."
  1144. echo "0 * * * * $dir/server/php/shell/periodic_email_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/root
  1145.  
  1146. echo "Setting up cron for every 30 minutes to fetch IMAP email..."
  1147. echo "*/30 * * * * $dir/server/php/shell/imap.sh > /dev/null 2> /dev/null" >> /var/spool/cron/root
  1148.  
  1149. echo "Setting up cron for every 5 minutes to send activities to webhook..."
  1150. echo "*/5 * * * * $dir/server/php/shell/webhook.sh > /dev/null 2> /dev/null" >> /var/spool/cron/root
  1151.  
  1152. echo "Setting up cron for every 5 minutes to send email notification to past due..."
  1153. echo "*/5 * * * * $dir/server/php/shell/card_due_notification.sh > /dev/null 2> /dev/null" >> /var/spool/cron/root
  1154.  
  1155. echo "Reset php-fpm (use unix socket mode)..."
  1156. if [ -f "/run/php/php7.2-fpm.sock" ]; then
  1157. sed -i "s/listen = 127.0.0.1:9000/listen = \/run\/php\/php7.2-fpm.sock/g" /etc/php-fpm.d/www.conf
  1158. else
  1159. sed -i "s/unix:\/run\/php\/php7.2-fpm.sock/127.0.0.1:9000/g" /etc/nginx/conf.d/restyaboard.conf
  1160. fi
  1161.  
  1162. set +x
  1163. echo "Do you want to install Restyaboard apps (y/n)?"
  1164. read -r answer
  1165. set -x
  1166. case "${answer}" in
  1167. [Yy])
  1168. if ! hash jq 2>&-;
  1169. then
  1170. echo "Installing jq..."
  1171. yum install -y jq
  1172. error_code
  1173. if [ ${error_code} != 0 ]
  1174. then
  1175. echo "jq installation failed with error code ${error_code} (jq installation failed with error code 49)"
  1176. return 49
  1177. fi
  1178. fi
  1179. mkdir "$dir/client/apps"
  1180. chmod -R go+w "$dir/client/apps"
  1181. curl -v -L -G -o /tmp/apps.json https://raw.githubusercontent.com/RestyaPlatform/board-apps/master/apps.json
  1182. chmod -R go+w "/tmp/apps.json"
  1183. for fid in `jq -r '.[] | .id + "-v" + .version + "#" + .price' /tmp/apps.json`
  1184. do
  1185. app_name=$(echo ${fid} | cut -d"#" -f1)
  1186. app_price=$(echo ${fid} | cut -d"#" -f2)
  1187. if ([ "$app_price" = "Free" ])
  1188. then
  1189. curl -v -L -G -o /tmp/$app_name.zip https://github.com/RestyaPlatform/board-apps/releases/download/v1/$app_name.zip
  1190. unzip /tmp/$app_name.zip -d "$dir/client/apps"
  1191. fi
  1192. done
  1193. esac
  1194.  
  1195. if [ -f "/bin/systemctl" ]; then
  1196. echo "Starting services with systemd..."
  1197. systemctl start nginx
  1198. systemctl start php-fpm
  1199. else
  1200. echo "Starting services..."
  1201. /etc/init.d/php-fpm restart
  1202. /etc/init.d/nginx restart
  1203. fi
  1204. yum install -y python-pip
  1205. pip install virtualenv
  1206.  
  1207. esac
  1208. fi
  1209. /bin/echo "$RESTYABOARD_VERSION" > ${DOWNLOAD_DIR}/release
  1210.  
  1211. set +x
  1212. echo "Do you want to setup SSL connectivity for your domain and your domain should be publicly accessible Restyaboard instance (y/n)?"
  1213. read -r answer
  1214. set -x
  1215. case "${answer}" in
  1216. [Yy])
  1217. cd /opt/
  1218. wget https://github.com/certbot/certbot/archive/master.zip -O certbot-master.zip
  1219. unzip certbot-master.zip
  1220. cd /opt/certbot-master/
  1221. sudo -H ./certbot-auto certonly --webroot --no-bootstrap -d $webdir -w "$dir/client"
  1222. sed -i "s/restya\.com/$webdir/g" ${DOWNLOAD_DIR}/restyaboard-ssl.conf
  1223.  
  1224. sed -i "/client_max_body_size 300M;/r ${DOWNLOAD_DIR}/restyaboard-ssl.conf" /etc/nginx/conf.d/restyaboard.conf
  1225. if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
  1226. then
  1227. service nginx restart
  1228. service php7.2-fpm restart
  1229. else
  1230. if [ -f "/bin/systemctl" ]; then
  1231. echo "Starting services with systemd..."
  1232. systemctl restart nginx
  1233. systemctl restart php-fpm
  1234. else
  1235. echo "Starting services..."
  1236. /etc/init.d/php-fpm restart
  1237. /etc/init.d/nginx restart
  1238. fi
  1239. fi
  1240. esac
  1241.  
  1242. set +x
  1243. curl -v -L -G -d "app=board&os=${os}&version=${version}" "http://restya.com/success_installation.php"
  1244. echo "Restyaboard URL : $webdir"
  1245.  
  1246. echo "Login with username admin and password restya"
  1247. exit 1
  1248. }
  1249. main
  1250. error=$?
  1251. os=$(lsb_release -i -s)
  1252. curl -v -L -G -d "app=board&os=${os}&error=${error}" "http://restya.com/error_installation.php"
  1253. echo "If you're finding it difficult to install Restyaboard from your end, we do also offer free installation support that you may consider http://restya.com/contact?category=free-installation"
  1254. exit 1
  1255. } 2>&1 | tee -a restyaboard_install.log
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement