generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 5
/
40migrate
executable file
·152 lines (135 loc) · 4.05 KB
/
40migrate
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#
# Copyright (C) 2022 Nethesis S.r.l.
# http://www.nethesis.it - nethserver@nethesis.it
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see COPYING.
#
exec 1>&2
# No migration required
if [ ! -f config.php ]; then
exit 0
fi
# Prepare the script that stops the container
# The .sh file is sourced by the Bash entrypoint script
# because it is not an executable file:
cat <<EOF > restore/zz_stop.sh
docker_temp_server_stop # function defined by the entrypoint script
exit 0 # exit the entrypoint immediately: do not start the real DB server
EOF
# Execute database restore
# The cointainer will be stopped at the end
podman run --rm --replace --name=restore_db \
--env-file=./environment \
--env-file=./database.env \
--volume=nextcloud-db-data:/var/lib/mysql \
--volume=./restore:/docker-entrypoint-initdb.d:z \
${MARIADB_IMAGE}
# Cleanup database data
rm -f restore/zz_stop.sh restore/dump.sql
# Start services
systemctl --user start nextcloud
systemctl --user start nextcloud-db nextcloud-redis
systemctl --user start nextcloud-app nextcloud-nginx
# Wait a bit for container initialization
sleep 5
# Read vars from the old config file
vars="passwordsalt secret instanceid ldapProviderFactory version"
for var in $vars
do
val=$(grep $var config.php | awk -F '=>' '{print $2}' | tr -d "', ")
eval $var=$val
done
host=$(cat config.json | jq -r .host)
# Generate a migrated config file
cat << EOF > config.php
<?php
\$CONFIG = array (
'memcache.local' => '\\\OC\\\Memcache\\\APCu',
'apps_paths' =>
array (
0 =>
array (
'path' => '/var/www/html/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/www/html/custom_apps',
'url' => '/custom_apps',
'writable' => true,
),
),
'memcache.distributed' => '\\\OC\\Memcache\\\Redis',
'memcache.locking' => '\\\OC\\\Memcache\\\Redis',
'redis' =>
array (
'host' => '127.0.0.1',
'password' => '',
'port' => 6379,
),
'overwriteprotocol' => 'https',
'passwordsalt' => '$passwordsalt',
'secret' => '$secret',
'datadirectory' => '/var/www/html/data',
'dbtype' => 'mysql',
'version' => '$version',
'overwrite.cli.url' => 'http://localhost',
'dbname' => 'nextcloud',
'dbhost' => '127.0.0.1',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'nextcloud',
'dbpassword' => 'nextcloud',
'installed' => true,
'instanceid' => '$instanceid',
'ldapProviderFactory' => 'OCA\\\User_LDAP\\\LDAPProviderFactory',
'trusted_domains' =>
array (
0 => 'localhost',
1 => '$host',
),
'mail_smtpmode' => 'smtp',
'mail_smtpsecure' => '',
'mail_smtpauthtype' => 'LOGIN',
'mail_from_address' => 'no-reply',
'mail_domain' => 'local',
'mail_smtphost' => 'localhost',
'mail_smtpport' => '25',
);
EOF
# Wait for the container
while ! podman ps | grep -q nextcloud-app
do
echo "Waiting for nextcloud-app"
sleep 1
done
# Wait a bit for container initialization
sleep 2
# Copy the new config file and make it writable
podman exec nextcloud-app mkdir /var/www/html/config/
podman cp --archive config.php nextcloud-app:/var/www/html/config/config.php
podman exec nextcloud-app chown -R www-data:www-data /var/www/html/config/
# Wait for nextcloud install
while [[ $(podman exec --user www-data nextcloud-app ./occ status --output json | jq -r .installed) != "true" ]]
do
sleep 5
done
# Always update data fingerprint (required for restore and migration)
occ maintenance:data-fingerprint
# Cleanup migration data
rm -f config.php