v-add-sys-rainloop 6.8 KB

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