Skip to content

Commit

Permalink
allow to change the location of Nextclouds datadir
Browse files Browse the repository at this point in the history
Signed-off-by: szaimen <szaimen@e.mail.de>
  • Loading branch information
szaimen committed Mar 8, 2022
1 parent b929d57 commit 73174de
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Containers/mastercontainer/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ else
fi

# Check for other options
if [ -n "$NEXTCLOUD_DATADIR" ]; then
if ! echo "$NEXTCLOUD_DATADIR" | grep -q "^/mnt/" \
&& ! echo "$NEXTCLOUD_DATADIR" | grep -q "^/media/"
then
echo "You've set NEXTCLOUD_DATADIR but not to an allowed value.
The string must start with '/mnt/' or '/media/'. E.g. '/mnt/ncdata'"
exit 1
elif [ "$NEXTCLOUD_DATADIR" = "/mnt/" ] || [ "$NEXTCLOUD_DATADIR" = "/media/" ]; then
echo "You've set NEXTCLOUD_DATADIR but not to an allowed value.
The string must start with '/mnt/' or '/media/' and not be equal to these."
exit 1
fi
fi
if [ -n "$NEXTCLOUD_MOUNT" ]; then
if ! echo "$NEXTCLOUD_MOUNT" | grep -q "^/mnt/" \
&& ! echo "$NEXTCLOUD_MOUNT" | grep -q "^/media/" \
Expand Down
7 changes: 7 additions & 0 deletions Containers/nextcloud/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ if ! [ -f "/mnt/ncdata/skip.update" ]; then
fi
fi

# Check if appdata is present
# If not, something broke (e.g. changing ncdatadir after aio was first started)
if [ -z "$(find "/mnt/ncdata/" -maxdepth 1 -mindepth 1 -type d -name "appdata_*")" ]; then
echo "Appdata is not present. Did you maybe change the datadir after aio was first started?"
exit 1
fi

# Apply one-click-instance settings
echo "Applying one-click-instance settings..."
php /var/www/html/occ config:system:set one-click-instance --value=true --type=bool
Expand Down
4 changes: 2 additions & 2 deletions php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"writeable": true
},
{
"name": "nextcloud_aio_nextcloud_data",
"name": "%NEXTCLOUD_DATADIR%",
"location": "/mnt/ncdata",
"writeable": true
},
Expand Down Expand Up @@ -215,7 +215,7 @@
"writeable": true
},
{
"name": "nextcloud_aio_nextcloud_data",
"name": "%NEXTCLOUD_DATADIR%",
"location": "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data",
"writeable": true
},
Expand Down
5 changes: 5 additions & 0 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ private function GetDefinition(bool $latest): array
if($value['name'] === '') {
continue;
}
} elseif ($value['name'] === '%NEXTCLOUD_DATADIR%') {
$value['name'] = $this->configurationManager->GetNextcloudDatadirMount();
if ($value['name'] === '') {
$value['name'] = 'nextcloud_aio_nextcloud_data';
}
}
if($value['location'] === '%NEXTCLOUD_MOUNT%') {
$value['location'] = $this->configurationManager->GetNextcloudMount();
Expand Down
23 changes: 23 additions & 0 deletions php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,27 @@ public function GetNextcloudMount() : string {
return $mount;
}
}

public function GetNextcloudDatadirMount() : string {
$mount = getenv('NEXTCLOUD_DATADIR');
if ($mount === false) {
$config = $this->GetConfig();
if (!isset($config['nextcloud_datadir'])) {
$config['nextcloud_datadir'] = '';
}
return $config['nextcloud_datadir'];
} else {
if(file_exists(DataConst::GetConfigFile())) {
$config = $this->GetConfig();
if (!isset($config['nextcloud_datadir'])) {
$config['nextcloud_datadir'] = '';
}
if ($mount !== $config['nextcloud_datadir']) {
$config['nextcloud_datadir'] = $mount;
$this->WriteConfig($config);
}
}
return $mount;
}
}
}

0 comments on commit 73174de

Please sign in to comment.