Skip to content

Commit

Permalink
add nextcloud instance installation command to ncp-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed May 23, 2017
1 parent 1df92f9 commit 0909fce
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 41 deletions.
5 changes: 3 additions & 2 deletions batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
source etc/library.sh # initializes $IMGNAME

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

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

NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE
NO_CONFIG=1 ./installer.sh $NC_SCRIPT $IP $( ls -1t *.img | head -1 )
NO_CONFIG=1 ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 )
NO_CONFIG=1 ./installer.sh nextcloud.sh $IP $( ls -1t *.img | head -1 )

IMGFILE=$( ls -1t *.img | head -1 )
IMGOUT=$( basename "$IMGFILE" _base ).img
IMGOUT=$( basename "$IMGFILE" _base_nc-nextcloud_nextcloudpi.img ).img

pack_image "$IMGFILE" "$IMGOUT"
md5sum $( ls -1t *.img | head -1 )
Expand Down
Empty file modified etc/nextcloudpi-config.d/NFS.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/dnsmasq.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/fail2ban.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/letsencrypt.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/modsecurity.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-database.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-datadir.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-httpsonly.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-limits.sh
100755 → 100644
Empty file.
91 changes: 53 additions & 38 deletions nextcloud.sh → etc/nextcloudpi-config.d/nc-nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,68 @@
#
# Usage:
#
# ./installer.sh nextcloud.sh <IP> (<img>)
# ./installer.sh nc-nextcloud <IP> (<img>)
#
# See installer.sh instructions for details
#
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
#

VER=11.0.3
VER_=11.0.3
ADMINUSER_=admin
DBADMIN_=ncadmin
DBPASSWD_=ownyourbits
MAXFILESIZE_=768M
MAXTRANSFERTIME_=3600
OPCACHEDIR=/var/www/nextcloud/data/.opcache
DESCRIPTION="Install any NextCloud version"

install()
show_info()
{
[ -d /var/www/nextcloud ] && \
whiptail --yesno \
--backtitle "NextCloudPi configuration" \
--title "NextCloud installation" \
"This new installation will cleanup current
NextCloud instance, including files and database.
** perform backup before proceding **
You can use nc-backup " \
20 90
}

install() { :; }

configure()
{
service apache2 stop

# RE-CREATE DATABASE TABLE (workaround to emulate DROP USER IF EXISTS ..;)
sleep 40 # TODO wait for mysql to be up
mysql -u root -p$DBPASSWD_ <<EOF
DROP DATABASE IF EXISTS nextcloud;
CREATE DATABASE nextcloud;
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
[ $? -ne 0 ] && { echo -e "error configuring nextcloud database"; return 1; }

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

ocpath='/var/www/nextcloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'
# CONFIGURE FILE PERMISSIONS
local ocpath='/var/www/nextcloud'
local htuser='www-data'
local htgroup='www-data'
local rootuser='root'

printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
Expand Down Expand Up @@ -66,6 +102,7 @@ install()
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

# CONFIGURE NEXTCLOUD
cat > /etc/apache2/sites-available/000-default.conf <<'EOF'
<VirtualHost _default_:80>
DocumentRoot /var/www/nextcloud
Expand All @@ -77,32 +114,6 @@ cat > /etc/apache2/sites-available/000-default.conf <<'EOF'
</VirtualHost>
EOF

mkdir -p /usr/lib/systemd/system
cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF'
[Unit]
Description=Register Current IP as Nextcloud trusted domain
Requires=network.target
After=mysql.service
[Service]
ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable nextcloud-domain

cat > /usr/local/bin/nextcloud-domain.sh <<'EOF'
#!/bin/bash
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
cd /var/www/nextcloud
sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP
EOF
}

configure()
{
cd /var/www/nextcloud/

sudo -u www-data php occ maintenance:install --database \
Expand All @@ -123,14 +134,18 @@ configure()
echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http
crontab -u www-data /tmp/crontab_http
rm /tmp/crontab_http

# Initial Trusted Domain
local IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
local IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP
cd -

service apache2 start
}

cleanup()
{
[ "$STATE" != "1" ] && return
apt-get autoremove
apt-get clean
rm /var/lib/apt/lists/* -r
rm -f /home/pi/.bash_history

systemctl disable ssh
Expand Down
Empty file modified etc/nextcloudpi-config.d/nc-ramlogs.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-scan-auto.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-scan.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-swapfile.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-update.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/nc-wifi.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/no-ip.sh
100755 → 100644
Empty file.
Empty file modified etc/nextcloudpi-config.d/unattended-upgrades.sh
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion nextcloudpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ configure() { :; }

cleanup()
{
[ "$STATE" != "1" ] && return
apt-get autoremove
apt-get clean
rm /var/lib/apt/lists/* -r
Expand Down

0 comments on commit 0909fce

Please sign in to comment.