Advertisement
Guest User

Untitled

a guest
May 18th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ###############################################################################
  4. # #
  5. # S T U D . I P - I N S T A L L S C R I P T #
  6. # #
  7. # This install script is meant to be used by developers to locally install #
  8. # the Stud.IP software. #
  9. # It's implemented to be used on a LAMP system (tested on Ubuntu 15.10). #
  10. # #
  11. # IMPORTANT: This script needs root rights for the OS and the MySQL-Database! #
  12. # #
  13. ###############################################################################
  14.  
  15. if [[ $# -ne 2 ]]
  16. then
  17. echo "Expecting excatly 2 parameters..."
  18. echo "Usage: studip [install | remove] <path/to/version>"
  19. echo "example:"
  20. echo " studip install branches/3.3"
  21. echo
  22. exit
  23. else
  24. svnLocalDir=/usr/local/studip/$2
  25. # substring: delete everything from the BACK to the last '/'
  26. svnLocalParentDir=${svnLocalDir%/*}
  27. svnRemoteDir=svn://develop.studip.de/studip/$2
  28.  
  29. # Check if the repository exists.
  30. if [[ $(svn ls $svnRemoteDir | wc -l) -eq 0 ]]
  31. then
  32. echo "The Repository $svnRemoteDir does not exist."
  33. exit
  34. fi
  35.  
  36. # just get the last part of the directory string
  37. symLink=${svnLocalDir##/*/}
  38. dbName=${2//[^A-Za-z0-9_]/_}
  39. echo "Please enter the MySQL root password: "
  40. mysql_config_editor reset
  41. mysql_config_editor set --login-path=localroot --host=localhost --user=root --password
  42. fi
  43.  
  44. ###########################################################
  45. # #
  46. # I N S T A L L I N G #
  47. # #
  48. ###########################################################
  49.  
  50. #TODO check and install dependencies (LAMP: Apache, MySQL, PHP-Plugins etc.)
  51. #TODO configure server (php.init-settings) .htaccess or apache2.conf
  52.  
  53. if test $1 == "install"
  54. then
  55. echo "Installing..."
  56.  
  57. ###############################
  58. # SVN - CHECKOUT #
  59. ###############################
  60. if test -d $svnLocalDir
  61. then
  62. echo "The repository $svnLocalDir already exists."
  63. exit
  64. else
  65. echo "mkdir $svnLocalDir"
  66. mkdir $svnLocalDir
  67. fi
  68. echo "svn checkout $svnRemoteDir"
  69. echo "Could take some time..."
  70. svn co -q $svnRemoteDir $svnLocalDir
  71.  
  72. ###############################
  73. # MYSQL #
  74. ###############################
  75. echo "Creating and filling the database..."
  76. mysql --login-path=localroot -e "CREATE DATABASE IF NOT EXISTS $dbName DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci"
  77. mysql --login-path=localroot -e "GRANT USAGE ON $dbName.* TO 'studip'@'localhost' IDENTIFIED BY 'studip'"
  78. mysql --login-path=localroot -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON $dbName.* TO 'studip'@'localhost'"
  79. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip.sql
  80. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_root_user.sql
  81. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_default_data.sql
  82. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_resources_default_data.sql
  83. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_demo_data.sql
  84. mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_resources_demo_data.sql
  85.  
  86. ###############################
  87. # CONFIG #
  88. ###############################
  89. echo "Copying config files..."
  90. cp $svnLocalDir/config/config_local.inc.php.dist $svnLocalDir/config/config_local.inc.php
  91. cp $svnLocalDir/config/config.inc.php.dist $svnLocalDir/config/config.inc.php
  92.  
  93. echo "Customizing the 'config_local.inc.php'"
  94. sed -i -e 's/$DB_STUDIP_USER = "";/$DB_STUDIP_USER = "studip";/g' $svnLocalDir/config/config_local.inc.php
  95. sed -i -e 's/$DB_STUDIP_PASSWORD = "";/$DB_STUDIP_PASSWORD = "studip";/g' $svnLocalDir/config/config_local.inc.php
  96. sed -i -e 's/$DB_STUDIP_DATABASE = "";/$DB_STUDIP_DATABASE = "'$dbName'";/g' $svnLocalDir/config/config_local.inc.php
  97. sed -i -e "s/\$CACHING_FILECACHE_PATH = \$TMP_PATH . '\/studip_cache';/\$CACHING_FILECACHE_PATH = \$TMP_PATH . '\/studip_"$dbName"_cache';/g" $svnLocalDir/config/config_local.inc.php
  98.  
  99. # Migration script
  100. echo "Run migration script (php $svnLocalDir/cli/migrate.php)..."
  101. php $svnLocalDir/cli/migrate.php
  102.  
  103. ###############################
  104. # LINKS #
  105. ###############################
  106. # create one main link into the repository
  107. if [[ -L ~/studip ]]
  108. then
  109. echo "The symbolic link '~/studip -> /usr/local/studip' already exists."
  110. else
  111. echo "ln -s /usr/local/studip studip"
  112. sudo ln -s /usr/local/studip ~/studip
  113. fi
  114.  
  115. # symbolic link for the apache server
  116. if [[ -L /var/www/html/$symLink ]]
  117. then
  118. echo "The symbolic link '/var/www/html/$symLink -> $svnLocalDir/public' already exists."
  119. else
  120. echo "ln -s $svnLocalDir/public /var/www/html/$symLink"
  121. sudo ln -s $svnLocalDir/public /var/www/html/$symLink
  122. fi
  123.  
  124. echo "Installation complete!"
  125. echo "You should now reach your Stud.IP-Installation under:"
  126. echo "localhost/$symLink"
  127.  
  128. #TODO install and configure phpMyAdmin
  129.  
  130. ###########################################################
  131. # #
  132. # R E M O V I N G #
  133. # #
  134. ###########################################################
  135. elif test $1 == "remove"
  136. then
  137. echo "Removing..."
  138. if test -d $svnLocalDir
  139. then
  140. echo "rm -rf $svnLocalDir"
  141. rm -rf $svnLocalDir
  142. echo "Repository $2 has been removed."
  143. # if the parent directory is empty now, remove it also
  144. if [[ $(ls -1 $svnLocalParentDir | wc -l) -eq 0 ]]
  145. then
  146. echo "rm -rf $svnLocalParentDir"
  147. rm -rf $svnLocalParentDir
  148. fi
  149. else
  150. echo "The repository $svnLocalDir could not be found."
  151. exit
  152. fi
  153.  
  154. ###############################
  155. # MYSQL #
  156. ###############################
  157. echo "MySQL: dropping the database: $dbName"
  158. mysql --login-path=localroot -e "DROP DATABASE IF EXISTS $dbName"
  159.  
  160. ###############################
  161. # LINKS #
  162. ###############################
  163. echo "Removing the symbolic link in the apache server."
  164. if [[ -L /var/www/html/$symLink ]]
  165. then
  166. echo "rm /var/www/html/$symLink"
  167. sudo rm /var/www/html/$symLink
  168. else
  169. echo "The symbolic link '/var/www/html/$symLink -> $svnLocalDir/public' does not exists."
  170. fi
  171. echo "The Stud.IP checkout $2 should now be removed."
  172.  
  173. else
  174. echo "Unknown command. Use 'studip install' or 'studip remove'."
  175. exit
  176. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement