Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ###############################################################################
- # #
- # S T U D . I P - I N S T A L L S C R I P T #
- # #
- # This install script is meant to be used by developers to locally install #
- # the Stud.IP software. #
- # It's implemented to be used on a LAMP system (tested on Ubuntu 15.10). #
- # #
- # IMPORTANT: This script needs root rights for the OS and the MySQL-Database! #
- # #
- ###############################################################################
- if [[ $# -ne 2 ]]
- then
- echo "Expecting excatly 2 parameters..."
- echo "Usage: studip [install | remove] <path/to/version>"
- echo "example:"
- echo " studip install branches/3.3"
- echo
- exit
- else
- svnLocalDir=/usr/local/studip/$2
- # substring: delete everything from the BACK to the last '/'
- svnLocalParentDir=${svnLocalDir%/*}
- svnRemoteDir=svn://develop.studip.de/studip/$2
- # Check if the repository exists.
- if [[ $(svn ls $svnRemoteDir | wc -l) -eq 0 ]]
- then
- echo "The Repository $svnRemoteDir does not exist."
- exit
- fi
- # just get the last part of the directory string
- symLink=${svnLocalDir##/*/}
- dbName=${2//[^A-Za-z0-9_]/_}
- echo "Please enter the MySQL root password: "
- mysql_config_editor reset
- mysql_config_editor set --login-path=localroot --host=localhost --user=root --password
- fi
- ###########################################################
- # #
- # I N S T A L L I N G #
- # #
- ###########################################################
- #TODO check and install dependencies (LAMP: Apache, MySQL, PHP-Plugins etc.)
- #TODO configure server (php.init-settings) .htaccess or apache2.conf
- if test $1 == "install"
- then
- echo "Installing..."
- ###############################
- # SVN - CHECKOUT #
- ###############################
- if test -d $svnLocalDir
- then
- echo "The repository $svnLocalDir already exists."
- exit
- else
- echo "mkdir $svnLocalDir"
- mkdir $svnLocalDir
- fi
- echo "svn checkout $svnRemoteDir"
- echo "Could take some time..."
- svn co -q $svnRemoteDir $svnLocalDir
- ###############################
- # MYSQL #
- ###############################
- echo "Creating and filling the database..."
- mysql --login-path=localroot -e "CREATE DATABASE IF NOT EXISTS $dbName DEFAULT CHARACTER SET latin1 COLLATE latin1_german1_ci"
- mysql --login-path=localroot -e "GRANT USAGE ON $dbName.* TO 'studip'@'localhost' IDENTIFIED BY 'studip'"
- mysql --login-path=localroot -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON $dbName.* TO 'studip'@'localhost'"
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip.sql
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_root_user.sql
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_default_data.sql
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_resources_default_data.sql
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_demo_data.sql
- mysql --login-path=localroot --default-character-set='latin1' $dbName < $svnLocalDir/db/studip_resources_demo_data.sql
- ###############################
- # CONFIG #
- ###############################
- echo "Copying config files..."
- cp $svnLocalDir/config/config_local.inc.php.dist $svnLocalDir/config/config_local.inc.php
- cp $svnLocalDir/config/config.inc.php.dist $svnLocalDir/config/config.inc.php
- echo "Customizing the 'config_local.inc.php'"
- sed -i -e 's/$DB_STUDIP_USER = "";/$DB_STUDIP_USER = "studip";/g' $svnLocalDir/config/config_local.inc.php
- sed -i -e 's/$DB_STUDIP_PASSWORD = "";/$DB_STUDIP_PASSWORD = "studip";/g' $svnLocalDir/config/config_local.inc.php
- sed -i -e 's/$DB_STUDIP_DATABASE = "";/$DB_STUDIP_DATABASE = "'$dbName'";/g' $svnLocalDir/config/config_local.inc.php
- 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
- # Migration script
- echo "Run migration script (php $svnLocalDir/cli/migrate.php)..."
- php $svnLocalDir/cli/migrate.php
- ###############################
- # LINKS #
- ###############################
- # create one main link into the repository
- if [[ -L ~/studip ]]
- then
- echo "The symbolic link '~/studip -> /usr/local/studip' already exists."
- else
- echo "ln -s /usr/local/studip studip"
- sudo ln -s /usr/local/studip ~/studip
- fi
- # symbolic link for the apache server
- if [[ -L /var/www/html/$symLink ]]
- then
- echo "The symbolic link '/var/www/html/$symLink -> $svnLocalDir/public' already exists."
- else
- echo "ln -s $svnLocalDir/public /var/www/html/$symLink"
- sudo ln -s $svnLocalDir/public /var/www/html/$symLink
- fi
- echo "Installation complete!"
- echo "You should now reach your Stud.IP-Installation under:"
- echo "localhost/$symLink"
- #TODO install and configure phpMyAdmin
- ###########################################################
- # #
- # R E M O V I N G #
- # #
- ###########################################################
- elif test $1 == "remove"
- then
- echo "Removing..."
- if test -d $svnLocalDir
- then
- echo "rm -rf $svnLocalDir"
- rm -rf $svnLocalDir
- echo "Repository $2 has been removed."
- # if the parent directory is empty now, remove it also
- if [[ $(ls -1 $svnLocalParentDir | wc -l) -eq 0 ]]
- then
- echo "rm -rf $svnLocalParentDir"
- rm -rf $svnLocalParentDir
- fi
- else
- echo "The repository $svnLocalDir could not be found."
- exit
- fi
- ###############################
- # MYSQL #
- ###############################
- echo "MySQL: dropping the database: $dbName"
- mysql --login-path=localroot -e "DROP DATABASE IF EXISTS $dbName"
- ###############################
- # LINKS #
- ###############################
- echo "Removing the symbolic link in the apache server."
- if [[ -L /var/www/html/$symLink ]]
- then
- echo "rm /var/www/html/$symLink"
- sudo rm /var/www/html/$symLink
- else
- echo "The symbolic link '/var/www/html/$symLink -> $svnLocalDir/public' does not exists."
- fi
- echo "The Stud.IP checkout $2 should now be removed."
- else
- echo "Unknown command. Use 'studip install' or 'studip remove'."
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement