v-add-sys-rainloop 6.9 KB

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