-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnc-install
executable file
·111 lines (94 loc) · 3.72 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
104
105
106
107
108
109
110
111
#!/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"
}
link() {
if [ ! -L "$1" ]; then
if [ ! -d "$2" ] && [ -d "$1" ]; then
mv "$1" "$2"
fi
rm -rf "$1"
ln -s "$2" "$1"
fi
}
if [ "$DB_EXTERNAL" = false ]; then
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 "s|max_allowed_packet\s*=\s*1M|max_allowed_packet = $MAX_ALLOWED_PACKET|g" /etc/mysql/my.cnf
sed -i "s|max_allowed_packet\s*=\s*16M|max_allowed_packet = $MAX_ALLOWED_PACKET|g" /etc/mysql/my.cnf
echo '### starting database server ###'
mysqld_safe --datadir="$DB_DATA_PATH" --timezone="$NC_TIME" &
sleep 2
fi
fi
if [ ! -e /srv/installed ]; then
echo "### set timezone to $NC_TIME ###"
ln -sf /usr/share/zoneinfo/$NC_TIME /etc/localtime
echo '### symlinking mounts ###'
mkdir -m 0750 -p /nextcloud/data /nextcloud/apps /nextcloud/config
link /var/www/localhost/htdocs/data /nextcloud/data
link /var/www/localhost/htdocs/apps2 /nextcloud/apps
link /var/www/localhost/htdocs/config /nextcloud/config
echo '### copying templates from /tpl ###'
# usethis variable to write he dollar e.g.:
# $config = $bash_var;
# goes to
# ${D}config = $bash_var;
# where config is a php variable set to the content of the bash variable "$bash_var"
export D='$'
if [ -e "/nextcloud/config/config.php" ]; then
# dont copy configs if they are already mounted
rm -f "/tpl/$NC_WWW/config/config.php"
rm -f "/tpl/$NC_WWW/config/autoconfig.php"
fi
for tpl in $(find /tpl -type f); do
destination=${tpl#/tpl}
echo "$tpl >> $destination"
mkdir -p "${destination%/*}"
echo "$(envsubst < $tpl)" > "$destination"
done
echo '### configuring apache ###'
chown -R apache:apache /nextcloud/data /nextcloud/apps /nextcloud/config
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
chown -R apache:apache $NC_WWW/
chmod +x $NC_WWW/occ
if [ -f $NC_WWW/.htaccess ]; then
chmod -c 0644 $NC_WWW/.htaccess
chown -c apache:apache $NC_WWW/.htaccess
fi
if [ -f $NC_WWW/data/.htaccess ]; then
chmod -c 0644 $NC_WWW/data/.htaccess
chown -c apache:apache $NC_WWW/data/.htaccess
fi
echo '### Gratulations! Point your browser to your new nextcloud instance. ###'
touch /srv/installed
fi
exec $@