v-add-sys-rainloop 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. # info: Install Rainloop in HestiaCP
  3. # options: [MODE]
  4. # labels: hestia
  5. #
  6. # The function installs Rainloop
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Includes
  11. source $HESTIA/func/main.sh
  12. source $HESTIA/conf/hestia.conf
  13. source $HESTIA/install/upgrade/upgrade.conf
  14. MODE=$2
  15. UPDATE="no"
  16. # Version and Download paths
  17. # Version to be moved to upgrade script
  18. RL_FILE="rainloop-community-latest.zip"
  19. # For removal of folder
  20. RL_EXTRACT_MAIN="rainloop"
  21. # Downloading full version
  22. RL_URL="https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip"
  23. # Folder paths
  24. RL_INSTALL_DIR="/var/lib/rainloop"
  25. RL_CONFIG_DIR="/etc/rainloop"
  26. RL_LOG="/var/log/rainloop"
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. # Checking root permissions
  31. if [ "x$(id -u)" != 'x0' ]; then
  32. echo "ERROR: v-add-sys-rainloop can be run executed only by root user"
  33. exit 10
  34. fi
  35. # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
  36. if [ -z "$HESTIA" ]; then
  37. HESTIA="/usr/local/hestia"
  38. fi
  39. if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
  40. echo "ERROR: Environment variables not present, installation aborted."
  41. exit 2
  42. fi
  43. # Get current version
  44. if [ -f "/var/lib/rainloop/data/VERSION" ]; then
  45. version=$(cat $RL_INSTALL_DIR/data/VERSION);
  46. if [ "$version" == "$rl_v" ]; then
  47. echo "Error: Installed version ($version) is equal as the availble version ($rc_v)"
  48. exit 2;
  49. else
  50. UPDATE="yes"
  51. fi
  52. fi
  53. # Perform verification if read-only mode is enabled
  54. check_hestia_demo_mode
  55. #----------------------------------------------------------#
  56. # Action #
  57. #----------------------------------------------------------#
  58. if [ "$UPDATE" == "no" ]; then
  59. rm -f -r $RL_INSTALL_DIR
  60. rm -f -r $RL_CONFIG_DIR
  61. mkdir $RL_INSTALL_DIR
  62. mkdir $RL_CONFIG_DIR
  63. cd "$RL_INSTALL_DIR"
  64. [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
  65. key=$(openssl rand -hex 4);
  66. admin_account="admin_$key"
  67. admin_password=$(generate_password)
  68. r=$(generate_password)
  69. echo "Username: admin_$key" > ~/.rainloop
  70. echo "Password: $admin_password" >> ~/.rainloop
  71. echo "Secret key: admin_$key" >> ~/.rainloop
  72. unzip -q $RL_FILE
  73. mv ./data $RL_CONFIG_DIR/
  74. ln -s $RL_CONFIG_DIR/data/ ./data
  75. SALT=$(openssl rand -base64 64)
  76. cp ./data/VERSION ./data/INSTALLED
  77. echo "<?php //$SALT" > ./data/SALT.php
  78. echo "Forbidden" > ./data/index.php
  79. echo "Forbidden" > ./data/index.html
  80. # Create database
  81. mysql -e "DROP DATABASE rainloop"
  82. mysql -e "DROP USER rainloop@localhost"
  83. mysql -e "CREATE DATABASE rainloop"
  84. # Mysql available on system
  85. r=$(generate_password)
  86. mysql -e "GRANT ALL ON rainloop.*
  87. TO rainloop@localhost IDENTIFIED BY '$r'"
  88. mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/configs
  89. php -f $HESTIA_INSTALL_DIR/rainloop/change_password.php "admin_$key" "$admin_password" "$r"
  90. mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/domains
  91. cp -f $HESTIA_INSTALL_DIR/rainloop/default.ini $RL_CONFIG_DIR/data/_data_/_default_/domains
  92. mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins
  93. cp -f -r $HESTIA_INSTALL_DIR/rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR/data/_data_/_default_/plugins
  94. mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
  95. # Download add-x-originating-ip-header from rainloop github
  96. wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/index.php https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/index.php
  97. wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/VERSION https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/VERSION
  98. wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/README https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/README
  99. wget --quiet -O $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header/LICENSE https://raw.githubusercontent.com/RainLoop/rainloop-webmail/master/plugins/add-x-originating-ip-header/LICENSE
  100. cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-add-x-originating-ip-header.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-add-x-originating-ip-header.ini
  101. cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
  102. sed -i "s/%hostname%/$(hostname)/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
  103. sed -i "s/%port%/$BACKEND_PORT/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
  104. chown -R www-data:www-data ./data
  105. chown -R www-data:www-data $RL_CONFIG_DIR/
  106. rm ${RL_INSTALL_DIR}/${RL_FILE}
  107. # Add robots.txt
  108. echo "User-agent: *" > $RL_INSTALL_DIR/robots.txt
  109. echo "Disallow: /" >> $RL_INSTALL_DIR/robots.txt
  110. # Updating hestia.conf
  111. if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
  112. $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'rainloop'
  113. else
  114. if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
  115. if [ ! -z "$WEBMAIL_SYSTEM" ]; then
  116. $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop,$WEBMAIL_SYSTEM"
  117. else
  118. $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop"
  119. fi
  120. fi
  121. fi
  122. else
  123. [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
  124. unzip -q -o $RL_FILE
  125. rm $RL_INSTALL_DIR/$RL_FILE
  126. fi
  127. #----------------------------------------------------------#
  128. # Logging #
  129. #----------------------------------------------------------#
  130. log_history "Rouncube successfuly installed" '' 'admin'
  131. log_event "$OK" "$ARGUMENTS"