forked from martingabelmann/docker-nextcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnc-install
executable file
·103 lines (86 loc) · 3.48 KB
/
nc-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
# exit if a command fails
set -e
set -o pipefail
##function definitions
start_db() {
mysqld -u mysql --user=mysql --datadir="$DB_DATA_PATH"
}
mkdir -p $DB_DATA_PATH
chmod u=rwx,g-rwx,o-rwx $DB_DATA_PATH
chown -R mysql:mysql $DB_DATA_PATH
if [ ! -f "$DB_DATA_PATH/ibdata1" ]; then
echo '### no local mariadb found ###'
echo '### installing database ###'
mysql_install_db --user=mysql --datadir="$DB_DATA_PATH"
echo '### starting database server ###'
mysqld_safe --datadir="$DB_DATA_PATH" --timezone="$NC_TIME" &
sleep 4
echo '### create NextCloud Database and -user ###'
mysqladmin -u root password $DB_ROOT_PASS
echo -e "DELETE FROM mysql.user WHERE User='';\n
DROP DATABASE test;\n
CREATE USER $DB_USER@localhost IDENTIFIED BY '$DB_PASS';\n
CREATE DATABASE IF NOT EXISTS $DB_NAME;\n
GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_USER@localhost IDENTIFIED BY '$DB_PASS';\n
FLUSH PRIVILEGES;" | mysql -u root --password=$DB_ROOT_PASS
else
echo '### existing postgres database found ###'
sed -i "/\[mysqld\]/a max_allowed_packet = $DB_MAX_ALLOWED_PACKET" /etc/my.cnf
sed -i "/\[mysqld\]/a key_buffer_size = 128M" /etc/my.cnf
sed -i "/\[mysqld\]/a transaction_isolation = READ-COMMITTED" /etc/my.cnf
sed -i "/\[mysqld\]/a binlog_format = ROW" /etc/my.cnf
echo -e "[mysql-dump]\nmax_allowed_packet = $DB_MAX_ALLOWED_PACKET\nquick\nquote-names" >> /etc/my.cnf
echo '### starting database server ###'
mysqld_safe --datadir="$DB_DATA_PATH" --timezone="$NC_TIME" &
sleep 2
fi
if [ -e /etc/coturn/turnserver.conf ]; then
echo '### starting turnserver ###'
turnserver -c /etc/coturn/turnserver.conf -l /var/log/turn.log -o
fi
if [ ! -e /srv/installed ]; then
echo "### set timezone to $NC_TIME ###"
ln -sf /usr/share/zoneinfo/$NC_TIME /etc/localtime
echo '### copying templates from /tpl ###'
# copy /tpl/<path> to /<path>
# substitute {var} by the value of the environment variable $var
for tpl in $(find /tpl -type f); do
destination=${tpl#/tpl}
echo "$tpl >> $destination"
mkdir -p "${destination%/*}"
cp -f $tpl $destination
for i in $(env |grep -E 'NC_|DB_'); do
var="{${i%%=*}}"
val="${i##*=}"
sed -i "s|$var|$val|g" $destination
done
done
echo '### configuring apache ###'
chown -R apache:apache /etc/nextcloud
sed -i 's/ServerAdmin.*$/ServerAdmin '"$NC_EMAIL"'/g' /etc/apache2/httpd.conf
sed -i 's/^#ServerName.*$/ServerName '"$NC_DOMAIN"'/g' /etc/apache2/httpd.conf
echo '### fixing directory permissions ###'
#from https://wiki.archlinux.org/index.php/OwnCloud
mkdir -p $NC_WWW/assets
find $NC_WWW/ -type f -print0 | xargs -0 chmod 0640
find $NC_WWW/ -type d -print0 | xargs -0 chmod 0750
if [ $NC_FIXDATADIR = "yes" ]; then
find $NC_DATADIR/ -type d -print0 | xargs -0 chmod 0750 || true
find $NC_DATADIR/ -type f -print0 | xargs -0 chmod 0640 || true
fi
chown -R apache:apache $NC_WWW/
chown apache:apache $NC_DATADIR/
if [ -f $NC_WWW/.htaccess ]; then
chmod -c 0644 $NC_WWW/.htaccess
chown -c apache:apache $NC_WWW/.htaccess
fi
if [ -f $NC_DATADIR/.htaccess ]; then
chmod -c 0644 $NC_DATADIR/.htaccess
chown -c apache:apache $NC_DATADIR/.htaccess
fi
chmod +x $NC_WWW/occ
touch /srv/installed
fi
echo '### Gratulations! Point your browser to your new nextcloud instance. ###'
exec $@