Skip to content

Commit 37c8992

Browse files
author
nacho
committed
[update 11.0.3] split installation between base LAMP and NC. Cleaner to just update NC releases over the base
1 parent 3324a32 commit 37c8992

File tree

4 files changed

+251
-207
lines changed

4 files changed

+251
-207
lines changed

batch.sh

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@
1111

1212
source etc/library.sh # initializes $IMGNAME
1313

14-
IP=$1 # First argument is the QEMU Raspbian IP address
14+
IP=$1 # First argument is the QEMU Raspbian IP address
1515

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

18-
NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGFILE
19-
NO_CONFIG=1 NO_CFG_STEP=1 ./installer.sh fail2ban.sh $IP $( ls -1t *.img | head -1 )
20-
NO_CONFIG=1 NO_CFG_STEP=1 ./installer.sh no-ip.sh $IP $( ls -1t *.img | head -1 )
21-
NO_CONFIG=1 NO_CFG_STEP=1 ./installer.sh dnsmasq.sh $IP $( ls -1t *.img | head -1 )
22-
NO_CONFIG=1 NO_CFG_STEP=1 ./installer.sh letsencrypt.sh $IP $( ls -1t *.img | head -1 )
23-
NO_CONFIG=1 ./installer.sh unattended-upgrades.sh $IP $( ls -1t *.img | head -1 )
24-
NO_CONFIG=1 NO_CFG_STEP=1 ./installer.sh modsecurity.sh $IP $( ls -1t *.img | head -1 )
18+
NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE
19+
NO_CONFIG=1 ./installer.sh nextcloud.sh $IP $( ls -1t *.img | head -1 )
2520

26-
IMGOUT=$( ls -1t *.img | head -1 )
27-
IMGFULL=$( basename "$IMGFILE" .img )_FULL.img
21+
IMGFILE=$( ls -1t *.img | head -1 )
22+
IMGOUT=$( basename "$IMGFILE" _base_nextcloud.img ).img
2823

29-
pack_image "$IMGOUT" "$IMGFULL"
24+
pack_image "$IMGFILE" "$IMGOUT"
25+
md5sum $( ls -1t *.img | head -1 )
3026

3127
# License
3228
#

install-nextcloud.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IMGFILE=$2 # Second argument is the name for the output image
2020
DOWNLOAD=1 # Download the latest image
2121
EXTRACT=1 # Extract the image from zip, so start from 0
2222
IMG=raspbian_lite_latest
23-
INSTALL_SCRIPT=nextcloud.sh
23+
INSTALL_SCRIPT=nextcloud_base.sh
2424

2525
source etc/library.sh # initializes $IMGNAME
2626

@@ -31,13 +31,10 @@ source etc/library.sh # initializes $IMGNAME
3131
qemu-img resize $IMGFILE +1G || exit
3232
}
3333

34-
IMGOUT="NextCloudPi_$( date "+%m-%d-%y" ).img"
35-
3634
config $INSTALL_SCRIPT || exit 1
3735
launch_install_qemu "$IMGFILE" $IP || exit 1 # initializes $IMGOUT
3836

39-
pack_image $IMGFILE $IMGOUT
40-
37+
pack_image $IMGOUT $IMGFILE
4138

4239
# License
4340
#

nextcloud.sh

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/bin/bash
2+
3+
# Nextcloud installation on Raspbian over LAMP base
4+
# Tested with 2017-03-02-raspbian-jessie-lite.img
5+
#
6+
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
7+
# GPL licensed (see end of file) * Use at your own risk!
8+
#
9+
# Usage:
10+
#
11+
# ./installer.sh nextcloud.sh <IP> (<img>)
12+
#
13+
# See installer.sh instructions for details
14+
#
15+
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
16+
#
17+
18+
VER=11.0.3
19+
ADMINUSER_=admin
20+
DBADMIN_=ncadmin
21+
DBPASSWD_=ownyourbits
22+
MAXFILESIZE_=768M
23+
MAXTRANSFERTIME_=3600
24+
OPCACHEDIR=/var/www/nextcloud/data/.opcache
25+
26+
install()
27+
{
28+
cd /var/www/
29+
wget https://download.nextcloud.com/server/releases/nextcloud-$VER.tar.bz2 -O nextcloud.tar.bz2
30+
tar -xvf nextcloud.tar.bz2
31+
rm nextcloud.tar.bz2
32+
33+
ocpath='/var/www/nextcloud'
34+
htuser='www-data'
35+
htgroup='www-data'
36+
rootuser='root'
37+
38+
printf "Creating possible missing Directories\n"
39+
mkdir -p $ocpath/data
40+
mkdir -p $ocpath/updater
41+
mkdir -p $OPCACHEDIR
42+
43+
printf "chmod Files and Directories\n"
44+
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
45+
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750
46+
47+
printf "chown Directories\n"
48+
# recommended defaults do not play well with updater app
49+
# re-check this with every new version
50+
#chown -R ${rootuser}:${htgroup} ${ocpath}/
51+
chown -R ${htuser}:${htgroup} ${ocpath}/
52+
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
53+
chown -R ${htuser}:${htgroup} ${ocpath}/config/
54+
chown -R ${htuser}:${htgroup} ${ocpath}/data/
55+
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
56+
chown -R ${htuser}:${htgroup} ${ocpath}/updater/
57+
chown -R ${htuser}:${htgroup} $OPCACHEDIR
58+
59+
chmod +x ${ocpath}/occ
60+
61+
printf "chmod/chown .htaccess\n"
62+
if [ -f ${ocpath}/.htaccess ]; then
63+
# breaks updater, see above
64+
#chmod 0644 ${ocpath}/.htaccess
65+
chmod 0664 ${ocpath}/.htaccess
66+
chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
67+
fi
68+
if [ -f ${ocpath}/data/.htaccess ]; then
69+
chmod 0644 ${ocpath}/data/.htaccess
70+
chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
71+
fi
72+
73+
cat > /etc/apache2/sites-available/000-default.conf <<'EOF'
74+
<VirtualHost _default_:80>
75+
DocumentRoot /var/www/nextcloud
76+
<IfModule mod_rewrite.c>
77+
RewriteEngine On
78+
RewriteCond %{HTTPS} !=on
79+
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
80+
</IfModule>
81+
</VirtualHost>
82+
EOF
83+
84+
mkdir -p /usr/lib/systemd/system
85+
cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF'
86+
[Unit]
87+
Description=Register Current IP as Nextcloud trusted domain
88+
Requires=network.target
89+
After=mysql.service
90+
91+
[Service]
92+
ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh
93+
94+
[Install]
95+
WantedBy=multi-user.target
96+
EOF
97+
systemctl enable nextcloud-domain
98+
99+
cat > /usr/local/bin/nextcloud-domain.sh <<'EOF'
100+
#!/bin/bash
101+
IFACE=$( ip r | grep "default via" | awk '{ print $5 }' )
102+
IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 )
103+
cd /var/www/nextcloud
104+
sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP
105+
EOF
106+
}
107+
108+
configure()
109+
{
110+
cd /var/www/nextcloud/
111+
112+
sudo -u www-data php occ maintenance:install --database \
113+
"mysql" --database-name "nextcloud" --database-user "$DBADMIN_" --database-pass \
114+
"$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_"
115+
116+
sudo -u www-data php occ background:cron
117+
118+
sed -i '$s|^.*$| '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',\\n);|' /var/www/nextcloud/config/config.php
119+
120+
sed -i "s/post_max_size=.*/post_max_size=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini
121+
sed -i "s/upload_max_filesize=.*/upload_max_filesize=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini
122+
sed -i "s/memory_limit=.*/memory_limit=$MAXFILESIZE_/" /var/www/nextcloud/.user.ini
123+
124+
# slow transfers will be killed after this time
125+
cat >> /var/www/nextcloud/.user.ini <<< "max_execution_time=$MAXTRANSFERTIME_"
126+
127+
echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /tmp/crontab_http
128+
crontab -u www-data /tmp/crontab_http
129+
rm /tmp/crontab_http
130+
}
131+
132+
cleanup()
133+
{
134+
[ "$STATE" != "1" ] && return
135+
apt-get autoremove
136+
apt-get clean
137+
rm /var/lib/apt/lists/* -r
138+
rm -f /home/pi/.bash_history
139+
140+
systemctl disable ssh
141+
nohup halt &>/dev/null &
142+
}
143+
# License
144+
#
145+
# This script is free software; you can redistribute it and/or modify it
146+
# under the terms of the GNU General Public License as published by
147+
# the Free Software Foundation; either version 2 of the License, or
148+
# (at your option) any later version.
149+
#
150+
# This script is distributed in the hope that it will be useful,
151+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
152+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153+
# GNU General Public License for more details.
154+
#
155+
# You should have received a copy of the GNU General Public License
156+
# along with this script; if not, write to the
157+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
158+
# Boston, MA 02111-1307 USA
159+

0 commit comments

Comments
 (0)