From 7181840665090c668bc9107a8e5f149ab10b3b80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20M=C3=BCller?= <thomas.mueller@tmit.eu>
Date: Tue, 10 Mar 2015 15:59:07 +0100
Subject: [PATCH] Use occ to install ownCloud in autotest.sh

---
 autotest-external.sh | 70 +++-----------------------------------
 autotest-hhvm.sh     | 76 ++++++-----------------------------------
 autotest.sh          | 81 ++++++--------------------------------------
 lib/base.php         |  2 +-
 4 files changed, 28 insertions(+), 201 deletions(-)

diff --git a/autotest-external.sh b/autotest-external.sh
index 8254defc9ca..c4d5ffb181f 100755
--- a/autotest-external.sh
+++ b/autotest-external.sh
@@ -4,7 +4,7 @@
 #
 # @author Thomas Müller
 # @author Morris Jobke
-# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
+# @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
 # @copyright 2014 Morris Jobke hey@morrisjobke.de
 #
 
@@ -90,67 +90,6 @@ fi
 
 echo "Using database $DATABASENAME"
 
-# create autoconfig for sqlite, mysql and postgresql
-cat > ./tests/autoconfig-sqlite.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'sqlite',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-);
-DELIM
-
-cat > ./tests/autoconfig-mysql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'mysql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-pgsql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'pgsql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-oci.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'oci',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASENAME',
-  'dbname' => 'XE',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
 function execute_tests {
 	echo "Setup environment for $1 testing ..."
 	# back to root folder
@@ -197,15 +136,16 @@ EOF
 			to $DATABASENAME;
 			exit;
 EOF
+		DATABASEUSER=$DATABASENAME
+		DATABASENAME='XE'
 	fi
 
 	# copy autoconfig
 	cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
 
 	# trigger installation
-	echo "INDEX"
-	php -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101
-	echo "END INDEX"
+	echo "Installing ...."
+	./occ maintenance:install --database=$1 --database-name=$DATABASENAME --database-host=localhost --database-user=$DATABASEUSER --database-pass=owncloud --database-table-prefix=oc_ --admin-user=$ADMINLOGIN --admin-pass=admin --data-dir=$DATADIR
 
 	#test execution
 	echo "Testing with $1 ..."
diff --git a/autotest-hhvm.sh b/autotest-hhvm.sh
index bf96a5133a6..7a8452c7f06 100755
--- a/autotest-hhvm.sh
+++ b/autotest-hhvm.sh
@@ -2,8 +2,14 @@
 #
 # ownCloud
 #
+# @author Vincent Petry
+# @author Morris Jobke
+# @author Robin McCorkell
 # @author Thomas Müller
-# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
+# @author Andreas Fischer
+# @author Joas Schilling
+# @author Lukas Reschke
+# @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
 #
 
 set -e
@@ -95,67 +101,6 @@ fi
 
 echo "Using database $DATABASENAME"
 
-# create autoconfig for sqlite, mysql and postgresql
-cat > ./tests/autoconfig-sqlite.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'sqlite',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-);
-DELIM
-
-cat > ./tests/autoconfig-mysql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'mysql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-pgsql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'pgsql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-oci.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'oci',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASENAME',
-  'dbname' => 'XE',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
 function execute_tests {
 	echo "Setup environment for $1 testing ..."
 	# back to root folder
@@ -202,15 +147,16 @@ EOF
 			to $DATABASENAME;
 			exit;
 EOF
+		DATABASEUSER=$DATABASENAME
+		DATABASENAME='XE'
 	fi
 
 	# copy autoconfig
 	cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
 
 	# trigger installation
-	echo "INDEX"
-	hhvm -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101
-	echo "END INDEX"
+	echo "Installing ...."
+	hhvm ./occ maintenance:install --database=$1 --database-name=$DATABASENAME --database-host=localhost --database-user=$DATABASEUSER --database-pass=owncloud --database-table-prefix=oc_ --admin-user=$ADMINLOGIN --admin-pass=admin --data-dir=$DATADIR
 
 	#test execution
 	echo "Testing with $1 ..."
diff --git a/autotest.sh b/autotest.sh
index 647012ea618..94d63173547 100755
--- a/autotest.sh
+++ b/autotest.sh
@@ -2,8 +2,14 @@
 #
 # ownCloud
 #
+# @author Vincent Petry
+# @author Morris Jobke
+# @author Robin McCorkell
 # @author Thomas Müller
-# @copyright 2012, 2013 Thomas Müller thomas.mueller@tmit.eu
+# @author Andreas Fischer
+# @author Joas Schilling
+# @author Lukas Reschke
+# @copyright 2012-2015 Thomas Müller thomas.mueller@tmit.eu
 #
 
 set -e
@@ -89,67 +95,6 @@ fi
 
 echo "Using database $DATABASENAME"
 
-# create autoconfig for sqlite, mysql and postgresql
-cat > ./tests/autoconfig-sqlite.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'sqlite',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-);
-DELIM
-
-cat > ./tests/autoconfig-mysql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'mysql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-pgsql.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'pgsql',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASEUSER',
-  'dbname' => '$DATABASENAME',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
-cat > ./tests/autoconfig-oci.php <<DELIM
-<?php
-\$AUTOCONFIG = array (
-  'installed' => false,
-  'dbtype' => 'oci',
-  'dbtableprefix' => 'oc_',
-  'adminlogin' => '$ADMINLOGIN',
-  'adminpass' => 'admin',
-  'directory' => '$DATADIR',
-  'dbuser' => '$DATABASENAME',
-  'dbname' => 'XE',
-  'dbhost' => 'localhost',
-  'dbpass' => 'owncloud',
-);
-DELIM
-
 function execute_tests {
 	echo "Setup environment for $1 testing ..."
 	# back to root folder
@@ -162,8 +107,6 @@ function execute_tests {
 	rm -rf "$DATADIR"
 	mkdir "$DATADIR"
 
-	# remove the old config file
-	#rm -rf config/config.php
 	cp tests/preseed-config.php config/config.php
 
 	# drop database
@@ -196,15 +139,13 @@ EOF
 			to $DATABASENAME;
 			exit;
 EOF
+		DATABASEUSER=$DATABASENAME
+		DATABASENAME='XE'
 	fi
 
-	# copy autoconfig
-	cp "$BASEDIR/tests/autoconfig-$1.php" "$BASEDIR/config/autoconfig.php"
-
 	# trigger installation
-	echo "INDEX"
-	php -f index.php | grep -i -C9999 error && echo "Error during setup" && exit 101
-	echo "END INDEX"
+	echo "Installing ...."
+	./occ maintenance:install --database=$1 --database-name=$DATABASENAME --database-host=localhost --database-user=$DATABASEUSER --database-pass=owncloud --database-table-prefix=oc_ --admin-user=$ADMINLOGIN --admin-pass=admin --data-dir=$DATADIR
 
 	#test execution
 	echo "Testing with $1 ..."
diff --git a/lib/base.php b/lib/base.php
index e957d6be089..ea379e429b3 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -566,7 +566,7 @@ class OC {
 				} catch(\Exception $e) {
 					echo('Writing to database failed');
 				}
-				exit();
+				exit(1);
 			} else {
 				OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE);
 				OC_Template::printGuestPage('', 'error', array('errors' => $errors));
-- 
GitLab