install.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/bash
  2. #
  3. # SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. # SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. # SPDX-License-Identifier: AGPL-3.0-only
  6. #
  7. # @author Thomas Müller
  8. # @copyright 2014 Thomas Müller thomas.mueller@tmit.eu
  9. #
  10. set -e
  11. DATABASENAME=oc_autotest
  12. DATABASEUSER=oc_autotest
  13. ADMINLOGIN=admin
  14. BASEDIR=$PWD
  15. DBCONFIGS="sqlite mysql pgsql oracle"
  16. PHPUNIT=$(which phpunit)
  17. # set oracle home if it is not set
  18. TRAVIS_ORACLE_HOME="/usr/lib/oracle/xe/app/oracle/product/10.2.0/server"
  19. [ -z "$ORACLE_HOME" ] && ORACLE_HOME=$TRAVIS_ORACLE_HOME
  20. if [ $1 ]; then
  21. FOUND=0
  22. for DBCONFIG in $DBCONFIGS; do
  23. if [ $1 = $DBCONFIG ]; then
  24. FOUND=1
  25. break
  26. fi
  27. done
  28. if [ $FOUND = 0 ]; then
  29. echo -e "Unknown database config name \"$1\"\n" >&2
  30. print_syntax
  31. exit 2
  32. fi
  33. fi
  34. # use tmpfs for datadir - should speedup unit test execution
  35. DATADIR=$BASEDIR/data-autotest
  36. echo "Using database $DATABASENAME"
  37. # create autoconfig for sqlite, mysql and postgresql
  38. cat > ./tests/autoconfig-sqlite.php <<DELIM
  39. <?php
  40. \$AUTOCONFIG = array (
  41. 'installed' => false,
  42. 'dbtype' => 'sqlite',
  43. 'dbtableprefix' => 'oc_',
  44. 'adminlogin' => '$ADMINLOGIN',
  45. 'adminpass' => 'admin',
  46. 'directory' => '$DATADIR',
  47. );
  48. DELIM
  49. cat > ./tests/autoconfig-mysql.php <<DELIM
  50. <?php
  51. \$AUTOCONFIG = array (
  52. 'installed' => false,
  53. 'dbtype' => 'mysql',
  54. 'dbtableprefix' => 'oc_',
  55. 'adminlogin' => '$ADMINLOGIN',
  56. 'adminpass' => 'admin',
  57. 'directory' => '$DATADIR',
  58. 'dbuser' => '$DATABASEUSER',
  59. 'dbname' => '$DATABASENAME',
  60. 'dbhost' => 'localhost',
  61. 'dbpass' => 'owncloud',
  62. );
  63. DELIM
  64. cat > ./tests/autoconfig-pgsql.php <<DELIM
  65. <?php
  66. \$AUTOCONFIG = array (
  67. 'installed' => false,
  68. 'dbtype' => 'pgsql',
  69. 'dbtableprefix' => 'oc_',
  70. 'adminlogin' => '$ADMINLOGIN',
  71. 'adminpass' => 'admin',
  72. 'directory' => '$DATADIR',
  73. 'dbuser' => '$DATABASEUSER',
  74. 'dbname' => '$DATABASENAME',
  75. 'dbhost' => 'localhost',
  76. 'dbpass' => '',
  77. );
  78. DELIM
  79. cat > ./tests/autoconfig-oracle.php <<DELIM
  80. <?php
  81. \$AUTOCONFIG = array (
  82. 'installed' => false,
  83. 'dbtype' => 'oci',
  84. 'dbtableprefix' => 'oc_',
  85. 'adminlogin' => '$ADMINLOGIN',
  86. 'adminpass' => 'admin',
  87. 'directory' => '$DATADIR',
  88. 'dbuser' => '$DATABASENAME',
  89. 'dbname' => 'XE',
  90. 'dbhost' => 'localhost',
  91. 'dbpass' => 'owncloud',
  92. 'loglevel' => 0,
  93. );
  94. DELIM
  95. function execute_tests {
  96. echo "Setup environment for $1 testing ..."
  97. # back to root folder
  98. cd $BASEDIR
  99. # revert changes to tests/data
  100. git checkout tests/data/*
  101. # reset data directory
  102. rm -rf $DATADIR
  103. mkdir $DATADIR
  104. cp tests/preseed-config.php config/config.php
  105. if [ "$1" == "oracle" ] ; then
  106. echo "Load Oracle environment variables so that we can run 'sqlplus'."
  107. . $ORACLE_HOME/bin/oracle_env.sh
  108. echo "create the database"
  109. sqlplus -s -l / as sysdba <<EOF
  110. create user $DATABASENAME identified by owncloud;
  111. alter user $DATABASENAME default tablespace users
  112. temporary tablespace temp
  113. quota unlimited on users;
  114. grant create session
  115. , create table
  116. , create procedure
  117. , create sequence
  118. , create trigger
  119. , create view
  120. , create synonym
  121. , alter session
  122. to $DATABASENAME;
  123. exit;
  124. EOF
  125. fi
  126. # copy autoconfig
  127. cp $BASEDIR/tests/autoconfig-$1.php $BASEDIR/config/autoconfig.php
  128. # trigger installation
  129. echo "INDEX"
  130. php -f index.php
  131. echo "END INDEX"
  132. #test execution
  133. cd tests
  134. #php -f enable_all.php
  135. }
  136. #
  137. # start test execution
  138. #
  139. if [ -z "$1" ]
  140. then
  141. # run all known database configs
  142. for DBCONFIG in $DBCONFIGS; do
  143. execute_tests $DBCONFIG
  144. done
  145. else
  146. execute_tests $1 $2 $3
  147. fi
  148. # show environment
  149. echo "owncloud configuration:"
  150. cat $BASEDIR/config/config.php
  151. echo "data directory:"
  152. ls -ll $DATADIR
  153. echo "nextcloud.log:"
  154. [ -f "$DATADIR/nextcloud.log" ] && cat $DATADIR/nextcloud.log
  155. [ -f "$BASEDIR/data/nextcloud.log" ] && cat $BASEDIR/data/nextcloud.log
  156. cd $BASEDIR