#!/usr/bin/env bash set -e # init.sh (start) PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" WORKING_DIR="/var/www/html" PROJECT_IP=$(hostname -I | awk '{ print $1 }') # Flags while getopts ":t:" opt; do case $opt in t) CHEVERETO_TAG=$OPTARG echo "Using tag $OPTARG" >&2 ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done # Tags CHEVERETO_SOFTWARE="chevereto" CHEVERETO_VERSION="3" CHEVERETO_TAG=${CHEVERETO_TAG:-${CHEVERETO_VERSION}} CHEVERETO_PACKAGE=$CHEVERETO_TAG CHEVERETO_API_DOWNLOAD="https://chevereto.com/api/download/" CHEVERETO_LABEL="Chevereto V$CHEVERETO_VERSION" # Header cat </dev/null apt-get install -qq -y apache2 libapache2-mod-php apt-get install -qq -y mysql-server apt-get install -qq -y php apt-get install -y php-{common,cli,curl,fileinfo,gd,imagick,intl,json,mbstring,mysql,opcache,pdo,pdo-mysql,xml,xmlrpc,zip} apt-get install -y python3-certbot-apache software-properties-common unzip # composer if ! command -v composer &>/dev/null; then COMPOSER_CHECKSUM_VERIFY="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" COMPOSER_HASH_FILE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" if [ "$COMPOSER_CHECKSUM_VERIFY" != "$COMPOSER_HASH_FILE" ]; then echo >&2 'ERROR: Invalid Composer installer checksum' rm composer-setup.php exit 1 fi php composer-setup.php --install-dir=/usr/local/bin --filename=composer rm composer-setup.php chmod +x /usr/local/bin/composer else composer selfupdate fi # Extract rm -rf "${WORKING_DIR}"/* unzip -oq ${CHEVERETO_SOFTWARE}*.zip -d $WORKING_DIR # scripts/01-fs.sh cat >/etc/apache2/sites-available/000-default.conf < Options Indexes FollowSymLinks AllowOverride All Require all granted ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog \${APACHE_LOG_DIR}/error.log CustomLog \${APACHE_LOG_DIR}/access.log combined EOM cat >/etc/update-motd.d/99-one-click < certbot --apache -d example.com -d www.example.com IMPORTANT: * After connecting to the server for the first time, immediately install Chevereto at http://\$myip/ * Secure your database by running: > mysql_secure_installation * Setup email delivery at http://\$myip/dashboard/settings/email For help and more information visit https://chevereto.com ******************************************************************************** To delete this message of the day: rm -rf \$(readlink -f \${0}) EOF EOM chmod +x /etc/update-motd.d/99-one-click cat >/etc/cron.d/chevereto </etc/php/7.4/apache2/conf.d/chevereto.ini <>/var/log/per-instance.log MYSQL_ROOT_PASS=$(openssl rand -hex 16) DEBIAN_SYS_MAINT_MYSQL_PASS=$(openssl rand -hex 16) CHEVERETO_DB_HOST=localhost CHEVERETO_DB_PORT=3306 CHEVERETO_DB_NAME=chevereto CHEVERETO_DB_USER=chevereto CHEVERETO_DB_PASS=$(openssl rand -hex 16) cat >/root/.mysql_password </etc/mysql/debian.cnf <"$WORKING_DIR/app/settings.php" <>/var/log/per-instance.log echo "[OK] $CHEVERETO_LABEL provisioned!" echo "Continue the process at http://$PROJECT_IP"