diff options
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/config.php | 265 | ||||
-rw-r--r-- | apps/files_external/tests/backends/amazons3.php (renamed from apps/files_external/tests/amazons3.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/dropbox.php (renamed from apps/files_external/tests/dropbox.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/ftp.php (renamed from apps/files_external/tests/ftp.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/google.php (renamed from apps/files_external/tests/google.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/owncloud.php (renamed from apps/files_external/tests/owncloud.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/sftp.php (renamed from apps/files_external/tests/sftp.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/smb.php (renamed from apps/files_external/tests/smb.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/swift.php (renamed from apps/files_external/tests/swift.php) | 0 | ||||
-rw-r--r-- | apps/files_external/tests/backends/webdav.php (renamed from apps/files_external/tests/webdav.php) | 12 | ||||
-rwxr-xr-x | apps/files_external/tests/env/start-webdav-ownCloud.sh | 82 | ||||
-rwxr-xr-x | apps/files_external/tests/env/stop-webdav-ownCloud.sh | 41 |
12 files changed, 291 insertions, 109 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 5742b8f47e2..f09b29a522b 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -1,25 +1,25 @@ <?php /** -* ownCloud -* -* @author Michael Gapczynski -* @copyright 2012 Michael Gapczynski mtgap@owncloud.com -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> -* @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library 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 AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -*/ + * ownCloud + * + * @author Michael Gapczynski + * @copyright 2012 Michael Gapczynski mtgap@owncloud.com + * @copyright 2014 Vincent Petry <pvince81@owncloud.com> + * @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ /** * Class to configure mount.json globally and for users @@ -64,16 +64,17 @@ class OC_Mount_Config { } /** - * Get details on each of the external storage backends, used for the mount config UI - * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded - * If the configuration parameter should be secret, add a '*' to the beginning of the value - * If the configuration parameter is a boolean, add a '!' to the beginning of the value - * If the configuration parameter is optional, add a '&' to the beginning of the value - * If the configuration parameter is hidden, add a '#' to the beginning of the value - * @return array - */ + * Get details on each of the external storage backends, used for the mount config UI + * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded + * If the configuration parameter should be secret, add a '*' to the beginning of the value + * If the configuration parameter is a boolean, add a '!' to the beginning of the value + * If the configuration parameter is optional, add a '&' to the beginning of the value + * If the configuration parameter is hidden, add a '#' to the beginning of the value + * + * @return array + */ public static function getBackends() { - $sortFunc = function($a, $b) { + $sortFunc = function ($a, $b) { return strcasecmp($a['backend'], $b['backend']); }; @@ -100,10 +101,13 @@ class OC_Mount_Config { /** * Hook that mounts the given user's visible mount points + * * @param array $data */ public static function initMountPointsHook($data) { + self::addStorageIdToConfig(null); if ($data['user']) { + self::addStorageIdToConfig($data['user']); $user = \OC::$server->getUserManager()->get($data['user']); if (!$user) { \OC_Log::write( @@ -161,8 +165,9 @@ class OC_Mount_Config { } // Override if priority greater - if ( (!isset($mountPoints[$mountPoint])) - || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) { + if ((!isset($mountPoints[$mountPoint])) + || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) + ) { $options['priority_type'] = self::MOUNT_TYPE_GLOBAL; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -184,8 +189,9 @@ class OC_Mount_Config { } // Override if priority greater - if ( (!isset($mountPoints[$mountPoint])) - || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) { + if ((!isset($mountPoints[$mountPoint])) + || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) + ) { $options['priority_type'] = self::MOUNT_TYPE_GLOBAL; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -208,9 +214,10 @@ class OC_Mount_Config { } // Override if priority greater or if priority type different - if ( (!isset($mountPoints[$mountPoint])) + if ((!isset($mountPoints[$mountPoint])) || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) - || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) ) { + || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) + ) { $options['priority_type'] = self::MOUNT_TYPE_GROUP; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -235,9 +242,10 @@ class OC_Mount_Config { } // Override if priority greater or if priority type different - if ( (!isset($mountPoints[$mountPoint])) + if ((!isset($mountPoints[$mountPoint])) || ($options['priority'] >= $mountPoints[$mountPoint]['priority']) - || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) ) { + || ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) + ) { $options['priority_type'] = self::MOUNT_TYPE_USER; $options['backend'] = $backends[$options['class']]['backend']; $mountPoints[$mountPoint] = $options; @@ -281,22 +289,23 @@ class OC_Mount_Config { /** - * Get details on each of the external storage backends, used for the mount config UI - * Some backends are not available as a personal backend, f.e. Local and such that have - * been disabled by the admin. - * - * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded - * If the configuration parameter should be secret, add a '*' to the beginning of the value - * If the configuration parameter is a boolean, add a '!' to the beginning of the value - * If the configuration parameter is optional, add a '&' to the beginning of the value - * If the configuration parameter is hidden, add a '#' to the beginning of the value - * @return array - */ + * Get details on each of the external storage backends, used for the mount config UI + * Some backends are not available as a personal backend, f.e. Local and such that have + * been disabled by the admin. + * + * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded + * If the configuration parameter should be secret, add a '*' to the beginning of the value + * If the configuration parameter is a boolean, add a '!' to the beginning of the value + * If the configuration parameter is optional, add a '&' to the beginning of the value + * If the configuration parameter is hidden, add a '#' to the beginning of the value + * + * @return array + */ public static function getPersonalBackends() { // Check whether the user has permissions to add personal storage backends // return an empty array if this is not the case - if(OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { + if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { return array(); } @@ -316,10 +325,11 @@ class OC_Mount_Config { } /** - * Get the system mount points - * The returned array is not in the same format as getUserMountPoints() - * @return array - */ + * Get the system mount points + * The returned array is not in the same format as getUserMountPoints() + * + * @return array + */ public static function getSystemMountPoints() { $mountPoints = self::readData(); $backends = self::getBackends(); @@ -329,7 +339,7 @@ class OC_Mount_Config { foreach ($mounts as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); if (!isset($mount['priority'])) { @@ -364,7 +374,7 @@ class OC_Mount_Config { foreach ($mounts as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); if (!isset($mount['priority'])) { @@ -397,10 +407,11 @@ class OC_Mount_Config { } /** - * Get the personal mount points of the current user - * The returned array is not in the same format as getUserMountPoints() - * @return array - */ + * Get the personal mount points of the current user + * The returned array is not in the same format as getUserMountPoints() + * + * @return array + */ public static function getPersonalMountPoints() { $mountPoints = self::readData(OCP\User::getUser()); $backEnds = self::getBackends(); @@ -410,7 +421,7 @@ class OC_Mount_Config { foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) { // Update old classes to new namespace if (strpos($mount['class'], 'OC_Filestorage_') !== false) { - $mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15); + $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); $personal[] = array( @@ -428,6 +439,7 @@ class OC_Mount_Config { /** * Test connecting using the given backend configuration + * * @param string $class backend class name * @param array $options backend configuration options * @return bool true if the connection succeeded, false otherwise @@ -452,16 +464,17 @@ class OC_Mount_Config { } /** - * Add a mount point to the filesystem - * @param string $mountPoint Mount point - * @param string $class Backend class - * @param array $classOptions Backend parameters for the class - * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER - * @param string $applicable User or group to apply mount to - * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page - * @param int|null $priority Mount point priority, null for default - * @return boolean - */ + * Add a mount point to the filesystem + * + * @param string $mountPoint Mount point + * @param string $class Backend class + * @param array $classOptions Backend parameters for the class + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @param string $applicable User or group to apply mount to + * @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page + * @param int|null $priority Mount point priority, null for default + * @return boolean + */ public static function addMountPoint($mountPoint, $class, $classOptions, @@ -488,22 +501,22 @@ class OC_Mount_Config { if ($applicable != OCP\User::getUser() || !isset($allowed_backends[$class])) { return false; } - $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { - $mountPoint = '/$user/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mount = array($applicable => array( $mountPoint => array( 'class' => $class, 'options' => self::encryptPasswords($classOptions)) - ) + ) ); - if (! $isPersonal && !is_null($priority)) { + if (!$isPersonal && !is_null($priority)) { $mount[$applicable][$mountPoint]['priority'] = $priority; } - $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); + $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null); // who else loves multi-dimensional array ? $isNew = !isset($mountPoints[$mountType]) || !isset($mountPoints[$mountType][$applicable]) || @@ -521,7 +534,7 @@ class OC_Mount_Config { } } - self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); + self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints); $result = self::getBackendStatus($class, $classOptions, $isPersonal); if ($result && $isNew) { @@ -539,13 +552,13 @@ class OC_Mount_Config { } /** - * - * @param string $mountPoint Mount point - * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER - * @param string $applicable User or group to remove mount from - * @param bool $isPersonal Personal or system mount point - * @return bool - */ + * + * @param string $mountPoint Mount point + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @param string $applicable User or group to remove mount from + * @param bool $isPersonal Personal or system mount point + * @return bool + */ public static function removeMountPoint($mountPoint, $mountType, $applicable, $isPersonal = false) { // Verify that the mount point applies for the current user $relMountPoints = $mountPoint; @@ -553,12 +566,12 @@ class OC_Mount_Config { if ($applicable != OCP\User::getUser()) { return false; } - $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/' . $applicable . '/files/' . ltrim($mountPoint, '/'); } else { - $mountPoint = '/$user/files/'.ltrim($mountPoint, '/'); + $mountPoint = '/$user/files/' . ltrim($mountPoint, '/'); } $mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint); - $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL); + $mountPoints = self::readData($isPersonal ? OCP\User::getUser() : null); // Remove mount point unset($mountPoints[$mountType][$applicable][$mountPoint]); // Unset parent arrays if empty @@ -568,7 +581,7 @@ class OC_Mount_Config { unset($mountPoints[$mountType]); } } - self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints); + self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints); \OC_Hook::emit( \OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_delete_mount, @@ -604,17 +617,18 @@ class OC_Mount_Config { } /** - * Read the mount points in the config file into an array - * @param string|null $user If not null, personal for $user, otherwise system - * @return array - */ - private static function readData($user = NULL) { + * Read the mount points in the config file into an array + * + * @param string|null $user If not null, personal for $user, otherwise system + * @return array + */ + private static function readData($user = null) { $parser = new \OC\ArrayParser(); if (isset($user)) { - $phpFile = OC_User::getHome($user).'/mount.php'; - $jsonFile = OC_User::getHome($user).'/mount.json'; + $phpFile = OC_User::getHome($user) . '/mount.php'; + $jsonFile = OC_User::getHome($user) . '/mount.json'; } else { - $phpFile = OC::$SERVERROOT.'/config/mount.php'; + $phpFile = OC::$SERVERROOT . '/config/mount.php'; $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); $jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } @@ -633,17 +647,27 @@ class OC_Mount_Config { } /** - * Write the mount points to the config file - * @param string|null $user If not null, personal for $user, otherwise system - * @param array $data Mount points - */ + * Write the mount points to the config file + * + * @param string|null $user If not null, personal for $user, otherwise system + * @param array $data Mount points + */ private static function writeData($user, $data) { if (isset($user)) { - $file = OC_User::getHome($user).'/mount.json'; + $file = OC_User::getHome($user) . '/mount.json'; } else { $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); $file = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); } + + foreach ($data as &$applicables) { + foreach ($applicables as &$mountPoints) { + foreach ($mountPoints as &$options) { + self::addStorageId($options); + } + } + } + $content = json_encode($data, JSON_PRETTY_PRINT); @file_put_contents($file, $content); @chmod($file, 0640); @@ -678,7 +702,7 @@ class OC_Mount_Config { return ''; } - private static function addDependency(&$dependencies, $module, $backend, $message=null) { + private static function addDependency(&$dependencies, $module, $backend, $message = null) { if (!isset($dependencies[$module])) { $dependencies[$module] = array(); } @@ -708,7 +732,7 @@ class OC_Mount_Config { $backends = ''; for ($i = 0; $i < $dependencyGroupCount; $i++) { if ($i > 0 && $i === $dependencyGroupCount - 1) { - $backends .= ' '.$l->t('and').' '; + $backends .= ' ' . $l->t('and') . ' '; } elseif ($i > 0) { $backends .= ', '; } @@ -722,6 +746,7 @@ class OC_Mount_Config { /** * Returns a dependency missing message + * * @param OC_L10N $l * @param string $module * @param string $backend @@ -740,6 +765,7 @@ class OC_Mount_Config { /** * Encrypt passwords in the given config options + * * @param array $options mount options * @return array updated options */ @@ -755,6 +781,7 @@ class OC_Mount_Config { /** * Decrypt passwords in the given config options + * * @param array $options mount options * @return array updated options */ @@ -769,6 +796,7 @@ class OC_Mount_Config { /** * Encrypt a single password + * * @param string $password plain text password * @return string encrypted password */ @@ -781,6 +809,7 @@ class OC_Mount_Config { /** * Decrypts a single password + * * @param string $encryptedPassword encrypted password * @return string plain text password */ @@ -795,6 +824,7 @@ class OC_Mount_Config { /** * Merges mount points + * * @param array $data Existing mount points * @param array $mountPoint New mount point * @param string $mountType @@ -808,7 +838,8 @@ class OC_Mount_Config { // Merge priorities if (isset($data[$mountType][$applicable][$mountPath]) && isset($data[$mountType][$applicable][$mountPath]['priority']) - && !isset($mountPoint[$applicable][$mountPath]['priority'])) { + && !isset($mountPoint[$applicable][$mountPath]['priority']) + ) { $mountPoint[$applicable][$mountPath]['priority'] = $data[$mountType][$applicable][$mountPath]['priority']; } @@ -850,4 +881,32 @@ class OC_Mount_Config { ); return hash('md5', $data); } + + private static function addStorageIdToConfig($user) { + $config = self::readData($user); + + $needUpdate = false; + foreach ($config as &$applicables) { + foreach ($applicables as &$mountPoints) { + foreach ($mountPoints as &$options) { + $needUpdate |= !isset($options['storage_id']); + } + } + } + + if ($needUpdate) { + self::writeData($user, $config); + } + } + + private static function addStorageId(&$options) { + if (isset($options['storage_id'])) { + return false; + } + $class = $options['class']; + /** @var \OC\Files\Storage\Storage $storage */ + $storage = new $class($options['options']); + $options['storage_id'] = $storage->getCache()->getNumericStorageId(); + return true; + } } diff --git a/apps/files_external/tests/amazons3.php b/apps/files_external/tests/backends/amazons3.php index fbb8744bd8d..fbb8744bd8d 100644 --- a/apps/files_external/tests/amazons3.php +++ b/apps/files_external/tests/backends/amazons3.php diff --git a/apps/files_external/tests/dropbox.php b/apps/files_external/tests/backends/dropbox.php index 3f25d5a31e8..3f25d5a31e8 100644 --- a/apps/files_external/tests/dropbox.php +++ b/apps/files_external/tests/backends/dropbox.php diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/backends/ftp.php index 842b7f43fa8..842b7f43fa8 100644 --- a/apps/files_external/tests/ftp.php +++ b/apps/files_external/tests/backends/ftp.php diff --git a/apps/files_external/tests/google.php b/apps/files_external/tests/backends/google.php index 79023fac9e1..79023fac9e1 100644 --- a/apps/files_external/tests/google.php +++ b/apps/files_external/tests/backends/google.php diff --git a/apps/files_external/tests/owncloud.php b/apps/files_external/tests/backends/owncloud.php index ab9101cfe5f..ab9101cfe5f 100644 --- a/apps/files_external/tests/owncloud.php +++ b/apps/files_external/tests/backends/owncloud.php diff --git a/apps/files_external/tests/sftp.php b/apps/files_external/tests/backends/sftp.php index 703b37d93f1..703b37d93f1 100644 --- a/apps/files_external/tests/sftp.php +++ b/apps/files_external/tests/backends/sftp.php diff --git a/apps/files_external/tests/smb.php b/apps/files_external/tests/backends/smb.php index 9e5ab2b331f..9e5ab2b331f 100644 --- a/apps/files_external/tests/smb.php +++ b/apps/files_external/tests/backends/smb.php diff --git a/apps/files_external/tests/swift.php b/apps/files_external/tests/backends/swift.php index d2c884a8b4c..d2c884a8b4c 100644 --- a/apps/files_external/tests/swift.php +++ b/apps/files_external/tests/backends/swift.php diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/backends/webdav.php index 5f53568b91a..c390612810d 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/backends/webdav.php @@ -16,15 +16,15 @@ class DAV extends Storage { parent::setUp(); $id = $this->getUniqueID(); - $this->config = include('files_external/tests/config.php'); - if ( ! is_array($this->config) or ! isset($this->config['webdav']) or ! $this->config['webdav']['run']) { + $config = include('files_external/tests/config.webdav.php'); + if ( ! is_array($config) or !$config['run']) { $this->markTestSkipped('WebDAV backend not configured'); } - if (isset($this->config['webdav']['wait'])) { - $this->waitDelay = $this->config['webdav']['wait']; + if (isset($config['wait'])) { + $this->waitDelay = $config['wait']; } - $this->config['webdav']['root'] .= '/' . $id; //make sure we have an new empty folder to work in - $this->instance = new \OC\Files\Storage\DAV($this->config['webdav']); + $config['root'] .= '/' . $id; //make sure we have an new empty folder to work in + $this->instance = new \OC\Files\Storage\DAV($config); $this->instance->mkdir('/'); } diff --git a/apps/files_external/tests/env/start-webdav-ownCloud.sh b/apps/files_external/tests/env/start-webdav-ownCloud.sh new file mode 100755 index 00000000000..c7267cff341 --- /dev/null +++ b/apps/files_external/tests/env/start-webdav-ownCloud.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# ownCloud +# +# This script start a docker container to test the files_external tests +# against. It will also change the files_external config to use the docker +# container as testing environment. This is reverted in the stop step. +# +# If the environment variable RUN_DOCKER_MYSQL is set the ownCloud will +# be set up using MySQL instead of SQLite. +# +# Set environment variable DEBUG to print config file +# +# @author Morris Jobke +# @copyright 2014 Morris Jobke <hey@morrisjobke.de> +# + +if ! command -v docker >/dev/null 2>&1; then + echo "No docker executable found - skipped docker setup" + exit 0; +fi + +echo "Docker executable found - setup docker" + +echo "Fetch recent morrisjobke/owncloud docker image" +docker pull morrisjobke/owncloud + +# retrieve current folder to place the config in the parent folder +thisFolder=`echo $0 | replace "env/start-webdav-ownCloud.sh" ""` + +if [ -n "$RUN_DOCKER_MYSQL" ]; then + echo "Fetch recent mysql docker image" + docker pull mysql + + echo "Setup MySQL ..." + # user/password will be read by ENV variables in owncloud container (they are generated by docker) + databaseContainer=`docker run -e MYSQL_ROOT_PASSWORD=mysupersecretpassword -d mysql` + containerName=`docker inspect $databaseContainer | grep Name | grep _ | cut -d \" -f 4 | cut -d / -f 2` + + parameter="--link $containerName:db" +fi + +container=`docker run -P $parameter -d -e ADMINLOGIN=test -e ADMINPWD=test morrisjobke/owncloud` + +# TODO find a way to determine the successful initialization inside the docker container +echo "Waiting 30 seconds for ownCloud initialization ... " +sleep 30 + +# get mapped port on host for internal port 80 - output is IP:PORT - we need to extract the port with 'cut' +port=`docker port $container 80 | cut -f 2 -d :` + + +cat > $thisFolder/config.webdav.php <<DELIM +<?php + +return array( + 'run'=>true, + 'host'=>'localhost:$port/owncloud/remote.php/webdav/', + 'user'=>'test', + 'password'=>'test', + 'root'=>'', + // wait delay in seconds after write operations + // (only in tests) + // set to higher value for lighttpd webdav + 'wait'=> 0 +); + +DELIM + +echo "ownCloud container: $container" + +# put container IDs into a file to drop them after the test run (keep in mind that multiple tests run in parallel on the same host) +echo $container >> $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + +if [ -n "$databaseContainer" ]; then + echo "Database container: $databaseContainer" + echo $databaseContainer >> $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav +fi + +if [ -n "$DEBUG" ]; then + echo $thisFolder/config.webdav.php +fi diff --git a/apps/files_external/tests/env/stop-webdav-ownCloud.sh b/apps/files_external/tests/env/stop-webdav-ownCloud.sh new file mode 100755 index 00000000000..2f06eadcf7c --- /dev/null +++ b/apps/files_external/tests/env/stop-webdav-ownCloud.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# +# ownCloud +# +# This script stops the docker container the files_external tests were run +# against. It will also revert the config changes done in start step. +# +# @author Morris Jobke +# @copyright 2014 Morris Jobke <hey@morrisjobke.de> +# + +if ! command -v docker >/dev/null 2>&1; then + echo "No docker executable found - skipped docker stop" + exit 0; +fi + +echo "Docker executable found - stop and remove docker containers" + +# retrieve current folder to remove the config from the parent folder +thisFolder=`echo $0 | replace "env/stop-webdav-ownCloud.sh" ""` + +echo "DEBUG" + +netstat -tlpen + +echo "CONFIG:" + +cat $thisFolder/config.webdav.php +cat $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + +# stopping and removing docker containers +for container in `cat $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav`; do + echo "Stopping and removing docker container $container" + # kills running container and removes it + docker rm -f $container +done; + +# cleanup +rm $thisFolder/config.webdav.php +rm $thisFolder/dockerContainerOwnCloud.$EXECUTOR_NUMBER.webdav + |