Skip to content

Commit

Permalink
nc-init as a nextcloudpi-config option
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Jun 28, 2017
1 parent f2f0687 commit c33cabc
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source etc/library.sh # initializes $IMGNAME

IP=$1 # First argument is the QEMU Raspbian IP address
NC_INSTALL=etc/nextcloudpi-config.d/nc-nextcloud.sh
NC_CONFIG=etc/nc-init.sh
NC_CONFIG=etc/nextcloudpi-config.d/nc-init.sh

IMGBASE="NextCloudPi_$( date "+%m-%d-%y" )_base.img"

Expand Down
2 changes: 1 addition & 1 deletion docker/nextcloud.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MAINTAINER Ignacio Núñez Hernanz <[email protected]>

SHELL ["/bin/bash", "-c"]

COPY etc/library.sh etc/nc-init.sh etc/nextcloudpi-config.d/nc-nextcloud.sh /usr/local/etc/
COPY etc/library.sh etc/nextcloudpi-config.d/nc-init.sh etc/nextcloudpi-config.d/nc-nextcloud.sh /usr/local/etc/

RUN apt-get update; apt-get install --no-install-recommends -y wget ca-certificates; \
source /usr/local/etc/library.sh; set +x; activate_script /usr/local/etc/nc-nextcloud.sh; \
Expand Down
2 changes: 1 addition & 1 deletion docker/run-nc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test -d /data/app || {

# INIT DATABASE AND NEXTCLOUD CONFIG
source /usr/local/etc/library.sh
install_script /usr/local/etc/nc-init.sh
activate_script /usr/local/etc/nextcloudpi-config.d/nc-init.sh

# COPY DATADIR TO /data, WHICH WILL BE IN A PERSISTENT VOLUME
cd /var/www/nextcloud/
Expand Down
29 changes: 26 additions & 3 deletions etc/nc-init.sh → etc/nextcloudpi-config.d/nc-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,26 @@
ADMINUSER_=admin
DBADMIN_=ncadmin
DBPASSWD_=ownyourbits
DESCRIPTION="(Re)initiate Nextcloud to a clean configuration"

install()
show_info()
{
## RE-CREATE DATABASE TABLE (workaround to emulate DROP USER IF EXISTS ..;)
whiptail --yesno \
--backtitle "NextCloudPi configuration" \
--title "Clean NextCloud configuration" \
"This action will configure NextCloud to NextCloudPi defaults.
** YOUR CONFIGURATION WILL BE LOST **
" \
20 90
}

configure()
{
systemctl stop apache2;

## RE-CREATE DATABASE TABLE

echo "Setting up database..."

Expand All @@ -31,6 +47,7 @@ install()
sleep 0.5
done

# workaround to emulate DROP USER IF EXISTS ..;)
mysql -u root -p$DBPASSWD_ <<EOF
DROP DATABASE IF EXISTS nextcloud;
CREATE DATABASE nextcloud
Expand All @@ -48,6 +65,7 @@ EOF
echo "Setting up Nextcloud..."

cd /var/www/nextcloud/
rm -f config/config.php
sudo -u www-data php occ maintenance:install --database \
"mysql" --database-name "nextcloud" --database-user "$DBADMIN_" --database-pass \
"$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_"
Expand All @@ -60,9 +78,14 @@ EOF

# 4 Byte UTF8 support
sudo -u www-data php occ config:system:set mysql.utf8mb4 --type boolean --value="true"

# Default trusted domain ( only from nextcloudpi-config )
test -f /usr/local/bin/nextcloud-domain.sh && bash /usr/local/bin/nextcloud-domain.sh

systemctl start apache2;
}

configure(){ :; }
install(){ :; }
cleanup() { :; }

# License
Expand Down
72 changes: 70 additions & 2 deletions etc/nextcloudpi-config.d/nc-nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ VER_=12.0.0
MAXFILESIZE_=2G
MEMORYLIMIT_=768M
MAXTRANSFERTIME_=3600
DBADMIN_=ncadmin
DBPASSWD_=ownyourbits
DESCRIPTION="Install any NextCloud version"

export DEBIAN_FRONTEND=noninteractive
Expand All @@ -32,6 +34,8 @@ show_info()
"This new installation will cleanup current
NextCloud instance, including files and database.
You can later use nc-init to configure to NextCloudPi defaults
** perform backup before proceding **
You can use nc-backup " \
Expand All @@ -42,10 +46,38 @@ install() { :; }

configure()
{
systemctl stop apache2;

## RE-CREATE DATABASE TABLE

# wait for mariadb
while :; do
[[ -S /var/run/mysqld/mysqld.sock ]] && break
sleep 0.5
done

echo "Setting up database..."
# workaround to emulate DROP USER IF EXISTS ..;)
mysql -u root -p$DBPASSWD_ <<EOF
DROP DATABASE IF EXISTS nextcloud;
CREATE DATABASE nextcloud
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
GRANT USAGE ON *.* TO '$DBADMIN_'@'localhost' IDENTIFIED BY '$DBPASSWD_';
DROP USER '$DBADMIN_'@'localhost';
CREATE USER '$DBADMIN_'@'localhost' IDENTIFIED BY '$DBPASSWD_';
GRANT ALL PRIVILEGES ON nextcloud.* TO $DBADMIN_@localhost;
EXIT
EOF

## DOWNLOAD AND (OVER)WRITE NEXTCLOUD
cd /var/www/
wget -q https://download.nextcloud.com/server/releases/nextcloud-$VER_.tar.bz2 -O nextcloud.tar.bz2

echo "Downloading Nextcloud $VER_..."
wget -q https://download.nextcloud.com/server/releases/nextcloud-$VER_.tar.bz2 -O nextcloud.tar.bz2 || return 1
rm -rf nextcloud

echo "Installing Nextcloud $VER_..."
tar -xf nextcloud.tar.bz2
rm nextcloud.tar.bz2

Expand Down Expand Up @@ -84,7 +116,37 @@ configure()
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

## CONFIGURE NEXTCLOUD
# create and configure opcache dir
OPCACHEDIR=/var/www/nextcloud/data/.opcache
sed -i "s|^opcache.file_cache=.*|opcache.file_cache=$OPCACHEDIR|" /etc/php/7.0/mods-available/opcache.ini
mkdir -p $OPCACHEDIR
chown -R www-data:www-data $OPCACHEDIR

## SET APACHE VHOST
cat > /etc/apache2/sites-available/nextcloud.conf <<'EOF'
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
DocumentRoot /var/www/nextcloud
CustomLog /var/www/nextcloud/data/access.log combined
ErrorLog /var/www/nextcloud/data/error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
SSLRenegBufferSize 10486000
</Directory>
</IfModule>
EOF
a2ensite nextcloud
echo "Setting up Apache..."

cat > /etc/apache2/sites-available/000-default.conf <<'EOF'
<VirtualHost _default_:80>
DocumentRoot /var/www/nextcloud
Expand All @@ -96,6 +158,8 @@ cat > /etc/apache2/sites-available/000-default.conf <<'EOF'
</VirtualHost>
EOF

echo "Setting up system..."

## SET LIMITS
sed -i "s/post_max_size=.*/post_max_size=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini
sed -i "s/upload_max_filesize=.*/upload_max_filesize=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini
Expand All @@ -109,6 +173,10 @@ EOF
echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http
crontab -u www-data /tmp/crontab_http
rm /tmp/crontab_http

systemctl start apache2;

echo "Don't forget to run nc-init"
}

cleanup()
Expand Down
28 changes: 1 addition & 27 deletions lamp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#

DBPASSWD_=ownyourbits
OPCACHEDIR=/var/www/nextcloud/data/.opcache

APTINSTALL="apt-get install -y --no-install-recommends"
export DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -96,16 +95,14 @@ EOF
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache=$OPCACHEDIR;
opcache.fast_shutdown=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
opcache.file_cache=/tmp;
EOF
mkdir -p $OPCACHEDIR
chown -R www-data:www-data $OPCACHEDIR

a2enmod http2
a2enconf http2
Expand All @@ -127,29 +124,6 @@ EOF
sed -i '/\[mysqld\]/ainnodb_large_prefix=on' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i '/\[mysqld\]/ainnodb_file_per_table=1' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i '/\[mysqld\]/ainnodb_file_format=barracuda' /etc/mysql/mariadb.conf.d/50-server.cnf

cat > /etc/apache2/sites-available/nextcloud.conf <<'EOF'
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
DocumentRoot /var/www/nextcloud
CustomLog /var/www/nextcloud/data/access.log combined
ErrorLog /var/www/nextcloud/data/error.log
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
<Directory /var/www/nextcloud/>
Options +FollowSymlinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
LimitRequestBody 0
SSLRenegBufferSize 10486000
</Directory>
</IfModule>
EOF
a2ensite nextcloud
}

configure() { :; }
Expand Down
2 changes: 1 addition & 1 deletion test-devel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install()
{
echo -e "Downloading updates"
rm -rf /tmp/ncp-update-tmp
git clone -q --depth 1 -b devel https://github.com/nextcloud/nextcloudpi.git /tmp/ncp-update-tmp
git clone -q -b devel https://github.com/nextcloud/nextcloudpi.git /tmp/ncp-update-tmp
cd /tmp/ncp-update-tmp

echo -e "Performing updates"
Expand Down

0 comments on commit c33cabc

Please sign in to comment.