Initialer Import der Synology Scripts
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+141
@@ -0,0 +1,141 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variablenblock
|
||||
NEXTCLOUD_VERSION="29.0.7"
|
||||
DB_NAME="nextcloud"
|
||||
DB_USER="nextclouduser"
|
||||
DB_PASSWORD=$(openssl rand -base64 32)
|
||||
DB_ROOT_PASSWORD=$(openssl rand -base64 32)
|
||||
NEXTCLOUD_DIR="/var/www/nextcloud"
|
||||
SSL_CERT_FILE="/etc/ssl/certs/nextcloud-cert.pem"
|
||||
SSL_KEY_FILE="/etc/ssl/private/nextcloud-key.pem"
|
||||
DOMAIN="nextcloud.example.com"
|
||||
APACHE_CONF="/etc/apache2/sites-available/nextcloud.conf"
|
||||
|
||||
# Funktion: Update und Installiere benötigte Pakete
|
||||
install_dependencies() {
|
||||
echo "System aktualisieren und benötigte Pakete installieren..."
|
||||
apt update && apt upgrade -y
|
||||
apt install -y apache2 mariadb-server libapache2-mod-php php php-mysql php-xml php-mbstring php-zip php-gd php-curl php-intl php-bcmath php-imagick php-gmp php-apcu unzip wget curl
|
||||
}
|
||||
|
||||
# Funktion: MariaDB konfigurieren
|
||||
configure_mariadb() {
|
||||
echo "MariaDB einrichten..."
|
||||
systemctl start mariadb
|
||||
systemctl enable mariadb
|
||||
|
||||
mysql -e "CREATE DATABASE ${DB_NAME};"
|
||||
mysql -e "CREATE USER '${DB_USER}'@'localhost' IDENTIFIED BY '${DB_PASSWORD}';"
|
||||
mysql -e "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO '${DB_USER}'@'localhost';"
|
||||
mysql -e "FLUSH PRIVILEGES;"
|
||||
|
||||
# Root Passwort setzen
|
||||
mysqladmin -u root password "${DB_ROOT_PASSWORD}"
|
||||
}
|
||||
|
||||
# Funktion: SSL-Zertifikate konfigurieren
|
||||
configure_ssl() {
|
||||
echo "SSL Zertifikate konfigurieren..."
|
||||
if [[ ! -f "$SSL_CERT_FILE" || ! -f "$SSL_KEY_FILE" ]]; then
|
||||
echo "SSL-Zertifikate nicht gefunden, bitte überprüfen!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
a2enmod ssl
|
||||
systemctl restart apache2
|
||||
}
|
||||
|
||||
# Funktion: Nextcloud herunterladen und installieren
|
||||
install_nextcloud() {
|
||||
echo "Nextcloud herunterladen und installieren..."
|
||||
wget https://download.nextcloud.com/server/releases/nextcloud-${NEXTCLOUD_VERSION}.zip
|
||||
unzip nextcloud-${NEXTCLOUD_VERSION}.zip -d /var/www/
|
||||
chown -R www-data:www-data ${NEXTCLOUD_DIR}
|
||||
chmod -R 755 ${NEXTCLOUD_DIR}
|
||||
}
|
||||
|
||||
# Funktion: Apache konfigurieren
|
||||
configure_apache() {
|
||||
echo "Apache für Nextcloud konfigurieren..."
|
||||
|
||||
cat <<EOF > ${APACHE_CONF}
|
||||
<VirtualHost *:80>
|
||||
ServerAdmin admin@${DOMAIN}
|
||||
DocumentRoot ${NEXTCLOUD_DIR}
|
||||
ServerName ${DOMAIN}
|
||||
|
||||
<Directory ${NEXTCLOUD_DIR}>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
ErrorLog \${APACHE_LOG_DIR}/error.log
|
||||
CustomLog \${APACHE_LOG_DIR}/access.log combined
|
||||
|
||||
RewriteEngine on
|
||||
RewriteCond %{SERVER_NAME} =${DOMAIN}
|
||||
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
|
||||
</VirtualHost>
|
||||
|
||||
<VirtualHost *:443>
|
||||
ServerAdmin admin@${DOMAIN}
|
||||
DocumentRoot ${NEXTCLOUD_DIR}
|
||||
ServerName ${DOMAIN}
|
||||
|
||||
<Directory ${NEXTCLOUD_DIR}>
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
</Directory>
|
||||
|
||||
SSLEngine on
|
||||
SSLCertificateFile ${SSL_CERT_FILE}
|
||||
SSLCertificateKeyFile ${SSL_KEY_FILE}
|
||||
|
||||
ErrorLog \${APACHE_LOG_DIR}/error.log
|
||||
CustomLog \${APACHE_LOG_DIR}/access.log combined
|
||||
</VirtualHost>
|
||||
EOF
|
||||
|
||||
a2ensite nextcloud.conf
|
||||
a2enmod rewrite headers env dir mime
|
||||
systemctl restart apache2
|
||||
}
|
||||
|
||||
# Funktion: Nextcloud über die Kommandozeile initialisieren
|
||||
initialize_nextcloud() {
|
||||
echo "Nextcloud initialisieren..."
|
||||
|
||||
sudo -u www-data php ${NEXTCLOUD_DIR}/occ maintenance:install \
|
||||
--database "mysql" \
|
||||
--database-name "${DB_NAME}" \
|
||||
--database-user "${DB_USER}" \
|
||||
--database-pass "${DB_PASSWORD}" \
|
||||
--admin-user "admin" \
|
||||
--admin-pass "$(openssl rand -base64 16)"
|
||||
|
||||
sudo -u www-data php ${NEXTCLOUD_DIR}/occ config:system:set trusted_domains 0 --value="${DOMAIN}"
|
||||
sudo -u www-data php ${NEXTCLOUD_DIR}/occ config:system:set overwrite.cli.url --value="https://${DOMAIN}/"
|
||||
}
|
||||
|
||||
# Funktion: Firewall konfigurieren
|
||||
configure_firewall() {
|
||||
echo "Firewall konfigurieren..."
|
||||
ufw allow in "Apache Full"
|
||||
ufw enable
|
||||
}
|
||||
|
||||
# Installation starten
|
||||
main() {
|
||||
install_dependencies
|
||||
configure_mariadb
|
||||
configure_ssl
|
||||
install_nextcloud
|
||||
configure_apache
|
||||
initialize_nextcloud
|
||||
configure_firewall
|
||||
echo "Installation abgeschlossen. Besuchen Sie https://${DOMAIN}, um Ihre Nextcloud-Instanz zu nutzen."
|
||||
}
|
||||
|
||||
# Skript starten
|
||||
main
|
||||
Reference in New Issue
Block a user