Update alpine-nextcloud-install.sh

code refactoring
This commit is contained in:
tteckster 2023-09-29 12:34:23 -04:00 committed by GitHub
parent 9fb5e232bd
commit 6faf005189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 83 additions and 102 deletions

View File

@ -20,9 +20,30 @@ $STD apk add openssl
$STD apk add openssh $STD apk add openssh
$STD apk add nano $STD apk add nano
$STD apk add mc $STD apk add mc
$STD apk add argon2 $STD apk add nginx
echo -e "export VISUAL=nano\nexport EDITOR=nano" >>/etc/profile
msg_ok "Installed Dependencies" msg_ok "Installed Dependencies"
msg_info "Installing PHP/Redis"
$STD apk add php82-opcache
$STD apk add php82-redis
$STD apk add php82-apcu
$STD apk add php82-fpm
$STD apk add php82-sysvsem
$STD apk add php82-pecl-imagick
$STD apk add php82-exif
$STD apk add redis
sed -i -e 's|;opcache.enable=1|opcache.enable=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.enable_cli=1|opcache.enable_cli=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.interned_strings_buffer=8|opcache.interned_strings_buffer=16|' /etc/php82/php.ini
sed -i -e 's|;opcache.max_accelerated_files=10000|opcache.max_accelerated_files=10000|' /etc/php82/php.ini
sed -i -e 's|;opcache.memory_consumption=128|opcache.memory_consumption=256|' /etc/php82/php.ini
sed -i -e 's|;opcache.save_comments=1|opcache.save_comments=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.revalidate_freq=1|opcache.revalidate_freq=1|' /etc/php82/php.ini
$STD rc-update add redis
$STD rc-service redis start
msg_ok "Installed PHP/Redis"
msg_info "Creating Credentials" msg_info "Creating Credentials"
DB_NAME=nextcloud DB_NAME=nextcloud
DB_USER=nextcloud DB_USER=nextcloud
@ -35,8 +56,9 @@ echo -e "MySQL Admin Password: \e[32m$ROOT_PASS\e[0m" >>~/nextcloud.creds
echo -e "Nextcloud Database Username: \e[32m$DB_USER\e[0m" >>~/nextcloud.creds echo -e "Nextcloud Database Username: \e[32m$DB_USER\e[0m" >>~/nextcloud.creds
echo -e "Nextcloud Database Password: \e[32m$DB_PASS\e[0m" >>~/nextcloud.creds echo -e "Nextcloud Database Password: \e[32m$DB_PASS\e[0m" >>~/nextcloud.creds
echo -e "Nextcloud Database Name: \e[32m$DB_NAME\e[0m" >>~/nextcloud.creds echo -e "Nextcloud Database Name: \e[32m$DB_NAME\e[0m" >>~/nextcloud.creds
echo "" >>~/nextcloud.creds
echo -e "Nextcloud Admin Username: \e[32m$ADMIN_USER\e[0m" >>~/nextcloud.creds echo -e "Nextcloud Admin Username: \e[32m$ADMIN_USER\e[0m" >>~/nextcloud.creds
echo -e "Nextcloud Admin Password: \e[32m$ADMIN_PASS\e[0m" >>~/nextcloud.creds echo -e "Nextcloud Admin Password: \e[32m$ADMIN_PASS\e[0m (Initially enter twice)" >>~/nextcloud.creds
msg_ok "Created Credentials" msg_ok "Created Credentials"
msg_info "Installing MySQL Database" msg_info "Installing MySQL Database"
@ -44,32 +66,62 @@ $STD apk add nextcloud-mysql mariadb mariadb-client
$STD mysql_install_db --user=mysql --datadir=/var/lib/mysql $STD mysql_install_db --user=mysql --datadir=/var/lib/mysql
$STD service mariadb start $STD service mariadb start
$STD rc-update add mariadb $STD rc-update add mariadb
mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$ROOT_PASS' WITH GRANT OPTION;FLUSH PRIVILEGES;"
mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.user WHERE User='';"
mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
mysql -uroot -p$ROOT_PASS -e "DROP DATABASE test;"
mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';"
mysql -uroot -p$ROOT_PASS -e "CREATE DATABASE $DB_NAME;"
mysql -uroot -p$ROOT_PASS -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';"
mysql -uroot -p$ROOT_PASS -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost.localdomain' IDENTIFIED BY '$DB_PASS';"
mysql -uroot -p$ROOT_PASS -e "FLUSH PRIVILEGES;"
$STD apk del mariadb-client
msg_ok "Installed MySQL Database" msg_ok "Installed MySQL Database"
msg_info "Setting up MySQL Database" msg_info "Installing Nextcloud"
$STD mysql -uroot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$ROOT_PASS' WITH GRANT OPTION;FLUSH PRIVILEGES;"
$STD mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.user WHERE User='';"
$STD mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
$STD mysql -uroot -p$ROOT_PASS -e "DROP DATABASE test;"
$STD mysql -uroot -p$ROOT_PASS -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';"
$STD mysql -uroot -p$ROOT_PASS -e "CREATE DATABASE $DB_NAME;"
$STD mysql -uroot -p$ROOT_PASS -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASS';"
$STD mysql -uroot -p$ROOT_PASS -e "GRANT ALL ON $DB_NAME.* TO '$DB_USER'@'localhost.localdomain' IDENTIFIED BY '$DB_PASS';"
$STD mysql -uroot -p$ROOT_PASS -e "FLUSH PRIVILEGES;"
$STD apk del mariadb-client
msg_ok "Set up MySQL Database"
msg_info "Installing Web-Server"
$STD apk add nextcloud-initscript $STD apk add nextcloud-initscript
$STD apk add nginx
$STD apk add php82-fpm
$STD apk add php82-sysvsem
$STD apk add php82-pecl-imagick
$STD apk add php82-exif
msg_ok "Installed Web-Server"
msg_info "Setting up Web-Server"
$STD openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/ssl/private/nextcloud-selfsigned.key -out /etc/ssl/certs/nextcloud-selfsigned.crt -subj "/C=US/O=Nextcloud/OU=Domain Control Validated/CN=nextcloud.local" $STD openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/ssl/private/nextcloud-selfsigned.key -out /etc/ssl/certs/nextcloud-selfsigned.crt -subj "/C=US/O=Nextcloud/OU=Domain Control Validated/CN=nextcloud.local"
cat <<'EOF' >/usr/share/webapps/nextcloud/config/config.php
<?php
$CONFIG = array (
'datadirectory' => '/var/lib/nextcloud/data',
'logfile' => '/var/log/nextcloud/nextcloud.log',
'logdateformat' => 'F d, Y H:i:s',
'log_rotate_size' => 104857600,
'apps_paths' => array (
// Read-only location for apps shipped with Nextcloud and installed by apk.
0 => array (
'path' => '/usr/share/webapps/nextcloud/apps',
'url' => '/apps',
'writable' => false,
),
// Writable location for apps installed from AppStore.
1 => array (
'path' => '/var/lib/nextcloud/apps',
'url' => '/apps-appstore',
'writable' => true,
),
),
'updatechecker' => false,
'check_for_working_htaccess' => false,
// Uncomment to enable Zend OPcache.
'memcache.local' => '\\OC\\Memcache\\Redis',
// Uncomment this and add user nextcloud to the redis group to enable Redis
// cache for file locking. This is highly recommended, see
// https://github.com/nextcloud/server/issues/9305.
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
'dbindex' => 0,
'timeout' => 1.5,
),
'installed' => false,
);
EOF
rm /etc/nginx/http.d/default.conf rm /etc/nginx/http.d/default.conf
cat <<'EOF' >/etc/nginx/http.d/nextcloud.conf cat <<'EOF' >/etc/nginx/http.d/nextcloud.conf
server { server {
@ -129,9 +181,10 @@ sed -i -e 's|php_admin_value\[post_max_size\] = 513M|php_admin_value\[post_max_s
sed -i -e 's|php_admin_value\[upload_max_filesize\] = 513M|php_admin_value\[upload_max_filesize\] = 5121M|' /etc/php82/php-fpm.d/nextcloud.conf sed -i -e 's|php_admin_value\[upload_max_filesize\] = 513M|php_admin_value\[upload_max_filesize\] = 5121M|' /etc/php82/php-fpm.d/nextcloud.conf
sed -i -e 's|upload_max_filesize = 513M|upload_max_filesize = 5121M|' /etc/php82/php.ini sed -i -e 's|upload_max_filesize = 513M|upload_max_filesize = 5121M|' /etc/php82/php.ini
sed -i -e 's|memory_limit = 128M|memory_limit = 512M|' /etc/php82/php.ini sed -i -e 's|memory_limit = 128M|memory_limit = 512M|' /etc/php82/php.ini
msg_ok "Set up Web-Server" msg_ok "Installed Nextcloud"
msg_info "Adding Additional Nextcloud Packages" msg_info "Adding Additional Nextcloud Packages"
$STD apk add nextcloud-default-apps
$STD apk add nextcloud-activity $STD apk add nextcloud-activity
$STD apk add nextcloud-admin_audit $STD apk add nextcloud-admin_audit
$STD apk add nextcloud-comments $STD apk add nextcloud-comments
@ -152,80 +205,7 @@ $STD apk add nextcloud-user_status
$STD apk add nextcloud-weather_status $STD apk add nextcloud-weather_status
msg_ok "Added Additional Nextcloud Packages" msg_ok "Added Additional Nextcloud Packages"
msg_info "Setting up PHP/Redis" msg_info "Starting Services"
$STD apk add php82-opcache
$STD apk add php82-redis
$STD apk add php82-apcu
$STD apk add redis
sed -i -e 's|;opcache.enable=1|opcache.enable=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.enable_cli=1|opcache.enable_cli=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.interned_strings_buffer=8|opcache.interned_strings_buffer=16|' /etc/php82/php.ini
sed -i -e 's|;opcache.max_accelerated_files=10000|opcache.max_accelerated_files=10000|' /etc/php82/php.ini
sed -i -e 's|;opcache.memory_consumption=128|opcache.memory_consumption=256|' /etc/php82/php.ini
sed -i -e 's|;opcache.save_comments=1|opcache.save_comments=1|' /etc/php82/php.ini
sed -i -e 's|;opcache.revalidate_freq=1|opcache.revalidate_freq=1|' /etc/php82/php.ini
$STD rc-update add redis
$STD rc-service redis start
msg_ok "Set up PHP/Redis"
msg_info "Setting up Nextcloud-Cronjob"
mkdir -p /etc/periodic/5min
cat <<'EOF' >/etc/periodic/5min/nextcloud_cron
#!/bin/sh
# Run only when nextcloud service is started.
if rc-service nextcloud -q status >/dev/null 2>&1; then
su nextcloud -s /bin/sh -c 'php82 -f /usr/share/webapps/nextcloud/cron.php'
fi
EOF
(crontab -l ; echo "*/5 * * * * run-parts /etc/periodic/5min") | crontab -
chmod +x /etc/periodic/5min/nextcloud_cron
msg_ok "Set up Nextcloud-Cronjob"
msg_info "Setting up Nextcloud-Config"
cat <<'EOF' >/usr/share/webapps/nextcloud/config/config.php
<?php
$CONFIG = array (
'datadirectory' => '/var/lib/nextcloud/data',
'logfile' => '/var/log/nextcloud/nextcloud.log',
'logdateformat' => 'F d, Y H:i:s',
'log_rotate_size' => 104857600,
'apps_paths' => array (
// Read-only location for apps shipped with Nextcloud and installed by apk.
0 => array (
'path' => '/usr/share/webapps/nextcloud/apps',
'url' => '/apps',
'writable' => false,
),
// Writable location for apps installed from AppStore.
1 => array (
'path' => '/var/lib/nextcloud/apps',
'url' => '/apps-appstore',
'writable' => true,
),
),
'updatechecker' => false,
'check_for_working_htaccess' => false,
// Uncomment to enable Zend OPcache.
'memcache.local' => '\\OC\\Memcache\\Redis',
// Uncomment this and add user nextcloud to the redis group to enable Redis
// cache for file locking. This is highly recommended, see
// https://github.com/nextcloud/server/issues/9305.
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
'dbindex' => 0,
'timeout' => 1.5,
),
'installed' => false,
);
EOF
msg_ok "Set up Nextcloud-Config"
msg_info "Starting Alpine-Nextcloud"
$STD rc-service php-fpm82 start $STD rc-service php-fpm82 start
chown -R nextcloud:www-data /var/log/nextcloud/ chown -R nextcloud:www-data /var/log/nextcloud/
$STD rc-service php-fpm82 restart $STD rc-service php-fpm82 restart
@ -233,9 +213,9 @@ $STD rc-service nginx start
$STD rc-service nextcloud start $STD rc-service nextcloud start
$STD rc-update add nginx default $STD rc-update add nginx default
$STD rc-update add nextcloud default $STD rc-update add nextcloud default
msg_ok "Started Alpine-Nextcloud" msg_ok "Started Services"
msg_info "Start Setup-Wizard" msg_info "Start Nextcloud Setup-Wizard"
cd /usr/share/webapps/nextcloud cd /usr/share/webapps/nextcloud
$STD su nextcloud -s /bin/sh -c "php82 occ maintenance:install \ $STD su nextcloud -s /bin/sh -c "php82 occ maintenance:install \
--database='mysql' --database-name $DB_NAME \ --database='mysql' --database-name $DB_NAME \
@ -245,7 +225,8 @@ $STD su nextcloud -s /bin/sh -c "php82 occ maintenance:install \
$STD su nextcloud -s /bin/sh -c 'php82 occ background:cron' $STD su nextcloud -s /bin/sh -c 'php82 occ background:cron'
IP4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1) IP4=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
sed -i "/0 => \'localhost\',/a \ \1 => '$IP4'," /usr/share/webapps/nextcloud/config/config.php sed -i "/0 => \'localhost\',/a \ \1 => '$IP4'," /usr/share/webapps/nextcloud/config/config.php
msg_ok "Finished Setup-Wizard" su nextcloud -s /bin/sh -c 'php82 -f /usr/share/webapps/nextcloud/cron.php'
msg_ok "Finished Nextcloud Setup-Wizard"
motd_ssh motd_ssh
customize customize