#!/bin/bash timedatectl set-timezone Europe/Madrid start_time=`date` echo "provisioning started: ${start_time}" echo "provisioning started: ${start_time}" #### The user must fill these variables - START # Fully Qualified Name: ex. "nc.localenv.com" MACHINE_HOSTNAME= # Nextcloud Installer name (format tar.bz2): ex. "nextcloud-21.0.7.tar.bz2" NEXTCLOUD_INSTALLER_ARCHIVE= #### The user must fill these variables - END SYSTEM_USER=usrv NEXTCLOUD_DB_NAME=nextcloud_db NEXTCLOUD_DB_USER=nextcloud_usr NEXTCLOUD_DB_PASSWORD=${NEXTCLOUD_DB_USER} NEXTCLOUD_DB_PORT=3306 NETWORK_INTERFACE=eth0 PHP_INI=/etc/php/7.4/apache2/php.ini hostnamectl set-hostname ${MACHINE_HOSTNAME} # Print some information about the container OS hostnamectl # Print some information about the container timezone timedatectl ##################################################################### ## Get the IP address into an environment variable. This command outputs ## an empty variable if the network interface name is not ${NETWORK_INTERFACE} ##################################################################### ip_address=`ip -4 addr show ${NETWORK_INTERFACE} | grep -oP '(?<=inet\s)\d+(\.\d+){3}'` adduser --disabled-password --gecos GECOS ${SYSTEM_USER} usermod -p "`openssl passwd -1 -salt 5RPVAd ${SYSTEM_USER}`" ${SYSTEM_USER} adduser ${SYSTEM_USER} sudo ## Install Nextcloud: https://docs.nextcloud.com/server/stable/admin_manual/installation/example_ubuntu.html ##### ## Step 001 ## Check the MD5 of the Nextcloud Installer ##(cd to the folder to avoid a 'File Not Found' error cd /vagrant/artifacts md5sum -c ${NEXTCLOUD_INSTALLER_ARCHIVE}.md5 < ${NEXTCLOUD_INSTALLER_ARCHIVE} md5sum_exit_status=$? cd -- echo "Exit status for md5sum check for Nextcloud installer: ${md5sum_exit_status}" if [ "${md5sum_exit_status}" == "0" ]; then echo "Check OK" else echo "Check KO" echo "Aborting" exit 1 fi ## Install the needed packages from apt repositories apt update apt install -y mariadb-server apt install -y php7.4 apt install -y php7.4-gd php7.4-mysql php7.4-curl php7.4-mbstring php7.4-intl apt install -y php7.4-gmp php7.4-bcmath php-imagick php7.4-xml php7.4-zip ## Replace the MariaDB configuration file and restart MariaDB cp /vagrant/artifacts/50-server.cnf /etc/mysql/mariadb.conf.d/50-server.cnf systemctl restart mysql ## Create the database and the user for the Nextcloud backend database echo "START - Create the database" mysql -u root -e 'create database nextcloud_db;' mysql -u root -e "create user nextcloud_usr@'%' identified by 'nextcloud_usr'" mysql -u root -e "grant all privileges on nextcloud_db.* to 'nextcloud_usr'@'%'" echo "END - Create the database" ## Expand the installer archive and move the content to the web server root folder (/var/www) echo "START - Expand the installer archive" cd /vagrant/artifacts tar -xjf ${NEXTCLOUD_INSTALLER_ARCHIVE} echo "END - Expand the installer archive" ## Installing Nextcloud from CLI (https://docs.nextcloud.com/server/stable/admin_manual/installation/command_line_installation.html) echo "START - Installing Nextcloud from CLI" php /vagrant/artifacts/nextcloud/occ maintenance:install --database "mysql"\ --database-name "${NEXTCLOUD_DB_NAME}"\ --database-host "${MACHINE_HOSTNAME}"\ --database-user "${NEXTCLOUD_DB_USER}"\ --database-pass "${NEXTCLOUD_DB_PASSWORD}"\ --admin-user "admin"\ --admin-pass "admin" echo "START - Cleanup" rm -rf /vagrant/artifacts/nextcloud echo "END - Cleanup" end_time=`date` echo "This container has IP (interface: ${NETWORK_INTERFACE}): ${ip_address}" echo "If you add this IP to the hostname (${MACHINE_HOSTNAME}) in your hosts file:" echo " You can connect with user ${SYSTEM_USER} via ssh (password ${SYSTEM_USER}): ssh ${SYSTEM_USER}@${MACHINE_HOSTNAME}" echo " You can connect to this MariaDB instance with the following parameters:" echo " hostname: ${MACHINE_HOSTNAME}" echo " database name: ${NEXTCLOUD_DB_NAME}" echo " username: ${NEXTCLOUD_DB_USER}" echo " password: ${NEXTCLOUD_DB_PASSWORD}" echo " port: ${NEXTCLOUD_DB_PORT}" echo "provisioning started: ${start_time}" echo "provisioning ended: ${end_time}"