| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #!/bin/bash
- # info: Install Rainloop in HestiaCP
- # options: [MODE]
- # labels: hestia
- #
- # The function installs Rainloop
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Includes
- source $HESTIA/func/main.sh
- source $HESTIA/conf/hestia.conf
- source $HESTIA/install/upgrade/upgrade.conf
- MODE=$2
- UPDATE="no"
- # Version and Download paths
- # Version to be moved to upgrade script
- RL_FILE="rainloop-community-latest.zip"
- # For removal of folder
- RL_EXTRACT_MAIN="rainloop"
- # Downloading full version
- RL_URL="https://www.rainloop.net/repository/webmail/rainloop-community-latest.zip"
- # Folder paths
- RL_INSTALL_DIR="/var/lib/rainloop"
- RL_CONFIG_DIR="/etc/rainloop"
- RL_LOG="/var/log/rainloop"
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking root permissions
- if [ "x$(id -u)" != 'x0' ]; then
- echo "ERROR: v-add-sys-rainloop can be run executed only by root user"
- exit 10
- fi
- # Ensure that $HESTIA (/usr/local/hestia/) and other variables are valid.
- if [ -z "$HESTIA" ]; then
- HESTIA="/usr/local/hestia"
- fi
- if [ -z "$HOMEDIR" ] || [ -z "$HESTIA_INSTALL_DIR" ]; then
- echo "ERROR: Environment variables not present, installation aborted."
- exit 2
- fi
- # Get current version
- if [ -f "/var/lib/rainloop/data/VERSION" ]; then
- version=$(cat $RL_INSTALL_DIR/data/VERSION);
- if [ "$version" == "$rl_v" ]; then
- echo "Error: Installed version ($version) is equal as the availble version ($rc_v)"
- exit 2;
- else
- UPDATE="yes"
- fi
- fi
- # Perform verification if read-only mode is enabled
- check_hestia_demo_mode
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- if [ "$UPDATE" == "no" ]; then
- rm -f -r $RL_INSTALL_DIR
- rm -f -r $RL_CONFIG_DIR
- mkdir $RL_INSTALL_DIR
- mkdir $RL_CONFIG_DIR
-
- cd "$RL_INSTALL_DIR"
- [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
-
- key=$(openssl rand -hex 4);
-
- admin_account="admin_$key"
- admin_password=$(generate_password)
- r=$(generate_password)
- echo "Username: admin_$key" > ~/.rainloop
- echo "Password: $admin_password" >> ~/.rainloop
- echo "Secret key: admin_$key" >> ~/.rainloop
-
- unzip -q $RL_FILE
-
- mv ./data $RL_CONFIG_DIR/
- ln -s $RL_CONFIG_DIR/data/ ./data
- SALT=$(openssl rand -base64 64)
- cp ./data/VERSION ./data/INSTALLED
- echo "<?php //$SALT" > ./data/SALT.php
- echo "Forbidden" > ./data/index.php
- echo "Forbidden" > ./data/index.html
- # Create database
- mysql -e "DROP DATABASE rainloop"
- mysql -e "DROP USER rainloop@localhost"
- mysql -e "CREATE DATABASE rainloop"
- # Mysql available on system
- r=$(generate_password)
- mysql -e "GRANT ALL ON rainloop.*
- TO rainloop@localhost IDENTIFIED BY '$r'"
- mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/configs
- php -f $HESTIA_INSTALL_DIR/rainloop/change_password.php "admin_$key" "$admin_password" "$r"
- mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/domains
- cp -f $HESTIA_INSTALL_DIR/rainloop/default.ini $RL_CONFIG_DIR/data/_data_/_default_/domains
- mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins
- cp -f -r $HESTIA_INSTALL_DIR/rainloop/plugins/hestia-change-password/ $RL_CONFIG_DIR/data/_data_/_default_/plugins
- mkdir -p $RL_CONFIG_DIR/data/_data_/_default_/plugins/add-x-originating-ip-header
- # Download add-x-originating-ip-header from rainloop github
- 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
- 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
- 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
- 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
-
- 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
- cp -f $HESTIA_INSTALL_DIR/rainloop/plugins/plugin-hestia-change-password.ini $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
-
- sed -i "s/%hostname%/$(hostname)/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
- sed -i "s/%port%/$BACKEND_PORT/g" $RL_CONFIG_DIR/data/_data_/_default_/configs/plugin-hestia-change-password.ini
-
-
- chown -R www-data:www-data ./data
- chown -R www-data:www-data $RL_CONFIG_DIR/
-
- rm ${RL_INSTALL_DIR}/${RL_FILE}
- # Add robots.txt
- echo "User-agent: *" > $RL_INSTALL_DIR/robots.txt
- echo "Disallow: /" >> $RL_INSTALL_DIR/robots.txt
-
- # Updating hestia.conf
- if [ -z "$(grep WEBMAIL_SYSTEM $HESTIA/conf/hestia.conf)" ]; then
- $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' 'rainloop'
- else
- if [ -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
- if [ ! -z "$WEBMAIL_SYSTEM" ]; then
- $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop,$WEBMAIL_SYSTEM"
- else
- $BIN/v-change-sys-config-value 'WEBMAIL_SYSTEM' "rainloop"
- fi
- fi
- fi
- else
- [ ! -f "${RC_INSTALL_DIR}/${RC_FILE}" ] && wget "$RL_URL" --quiet -O "${RL_INSTALL_DIR}/${RL_FILE}"
- unzip -q -o $RL_FILE
- rm $RL_INSTALL_DIR/$RL_FILE
- fi
- #----------------------------------------------------------#
- # Logging #
- #----------------------------------------------------------#
- log_history "Rouncube successfuly installed" '' 'admin'
- log_event "$OK" "$ARGUMENTS"
|