-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnextcloud-init.sh
More file actions
62 lines (46 loc) · 1.8 KB
/
nextcloud-init.sh
File metadata and controls
62 lines (46 loc) · 1.8 KB
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
#!/bin/bash
set -ea
source /usr/local/bin/nextcloud.env
# Set admin password
NEXTCLOUD_ADMIN_PASSWORD=$(cat /dev/urandom | base64 | head -c 24)
echo "$NEXTCLOUD_ADMIN_PASSWORD" > "$PASSWORD_FILE"
# Clean slate
rm -rf $NEXTCLOUD_PATH/{*,.[^.]*}
rm -rf $PGDATA/{*,.[^.]*}
# Initialize PostgreSQL
echo 'Initializing PostgreSQL database server...'
mkdir -p $PGDATA
chown -R postgres:postgres /var/lib/postgresql
echo "Initializing PostgreSQL database..."
su -c "$PG_BIN/pg_ctl initdb -D $PGDATA" postgres
# Start PG server
echo "Starting PostgreSQL db server..."
su -c "$PG_BIN/pg_ctl start -D $PGDATA" postgres
# Create db user & db, set password
echo "Setting up database..."
su -c "createuser --superuser $POSTGRES_USER" postgres
su -c "createdb $POSTGRES_DB" postgres
su - postgres -c "psql -c \"ALTER USER $POSTGRES_USER WITH ENCRYPTED PASSWORD '$POSTGRES_PASSWORD';\""
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;\""
# Start Nextcloud, which will install
echo "Initializing Nextcloud for the first time..."
/entrypoint.sh php-fpm &
NCPID=$!
while ! runuser -u www-data -- php /var/www/html/occ status | grep "installed: true"; do
echo "Awaiting Nextcloud installation..."
sleep 10
done
# Install default apps
echo "Installing default apps..."
runuser -u www-data -- php /var/www/html/occ app:install calendar
runuser -u www-data -- php /var/www/html/occ app:install contacts
# Install missing indices
runuser -u www-data -- php /var/www/html/occ db:add-missing-indices
# Perform any missing migrations
runuser -u www-data -- php /var/www/html/occ maintenance:repair --include-expensive
# Set background tasks to Cron
runuser -u www-data -- php /var/www/html/occ background:cron
kill -TERM $NCPID
sleep 60 &
wait -n $NCPID $!
su -c "$PG_BIN/pg_ctl stop -D $PGDATA" postgres