

Liferay Installation Shell Script
This script is useful to automate installation of Liferay in Linux. Script is created in Bash/Shell.
- It is limited to run on Linux
- Tomcat is used as application server
- MySQL is used as database.
Below are the pre-requisites for same.
- Super-user privileges for System and MySQL.
- Liferay installations repository should be available via Web
#!/bin/bash # Script to add a user to Linux system if [ $(id -u) -eq 0 ]; then read -p “Enter System username : ” username read -p “Enter System password : ” password read -p “Enter Directory path : ” dirpath read -p “Enter mysql root password : ” mysqlpwd read -p “Enter DB Name : ” dbname read -p “Enter DB password : ” dbpwd read -p “Enter Tomcat Port : ” tomcatport read -p “Enter Tomcat Shutdown Port : ” tomcatshutport read -p “Enter DomainName : ” domainname #Request for Liferay Version from Web Server wgetoptions=”wget http://URL/liferay.txt” wgetfile=”liferay.txt” liferayfile=”liferayfile.txt” rm -f $wgetfile $liferayfile $wgetoptions cat $wgetfile | cut -d “.” -f2-10 | sort -rn > liferayfile.txt IFS=” ” select x in $(<./liferayfile.txt) do break done #Verify Username egrep “^$username” /etc/passwd >/dev/null if [ $? -eq 0 ]; then echo “$username exists!” exit 1 else pass=$(perl -e ‘print crypt($ARGV[0], “password”)’ $password) useradd -m -p $password $username [ $? -eq 0 ] && echo “User has been added to system!” || echo “Failed to add a user!” fi else echo “Only root may add a user to the system” exit 2 fi #Verify MySql root login mysql -u root -p”${mysqlpwd}” -e “use mysql;” 2> /dev/null if [ $? -ne 0 ] then echo “Unable to login to MySQL.” exit 1 fi #Verify Directory path if [[ -L ${dirpath} || -e ${dirpath} ]]; then echo “Directory path Exists” exit 1 else mkdir ${dirpath} fi #Verify Tomcat port STAT=`netstat -na | grep :${tomcatport} | awk ‘{print $6}’` if [ “$STAT” = “LISTEN” ]; then echo “TOMCAT PORT IS already LISTENING” exit 1 fi #Download and Unzip Liferay wget -P ${dirpath} http://192.168.102.226/Liferay$x zipfile=$(echo “${x}” | sed ‘s/.*\///’) unzip -q “${dirpath}/${zipfile}” -d ${dirpath} [ $? -ne 0 ] && echo “Failed unzipping $zipfile” >&2 rm -f “${dirpath}/${zipfile}” #Tomcat Locations tomcatlo=”${dirpath}”/$(ls “${dirpath}” | grep liferay-portal) tomcatloc=”${tomcatlo}”/$(ls “${tomcatlo}” | grep tomcat) #Download MySQL jar file wget -P ${tomcatloc}/lib/mysql.jar http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.0.7/mysql-connector-java-5.0.7.jar #Setup MySQL DB for liferay mysql -u “root” -p”${mysqlpwd}” -e “use ${dbname};” 2> /dev/null if [ $? -ne 0 ]; then # Database doesn’t exist. Create it. mysql -u root -p${mysqlpwd} -e “create database ${dbname} character set utf8;” mysql -u root -p${mysqlpwd} -e “GRANT ALL ON ${dbname}.* TO ‘${dbname}’@’localhost’ identified by ‘${dbpwd}';” mysql -u root -p${mysqlpwd} -e “flush privileges;” else echo “Database ‘${dbname}’ already exists.” exit 1 fi #Create Portal-ext.properties echo “jdbc.default.driverClassName=com.mysql.jdbc.Driver jdbc.default.url=jdbc:mysql://localhost/${dbname}?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false jdbc.default.username=${dbname} jdbc.default.password=${dbpwd} schema.run.enabled=true schema.run.minimal=true” > $tomcatlo/portal-ext.properties #Set Tomcat Memory #sed -i ‘3 a export JAVA_OPTS=”-server -Xms512m -Xmx2048m -XX:MaxPermSize=512m -Dfile.encoding=UTF8 -Duser.timezone=GMT”‘ $dirpath/bin/catalina.sh #Set Permissions chown -R ${username}:${username} ${dirpath} chmod -R 777 ${dirpath} #Setup Ports sed -i “s/8080/${tomcatport}/” ${tomcatloc}/conf/server.xml sed -i “s/8005/${tomcatshutport}/” ${tomcatloc}/conf/server.xml #Add Virtualhost in Apache echo ” ServerName ${domainname}.domain.com ServerAdmin admin@domain.com DocumentRoot ${dirpath} ErrorLog logs/${domainname}.domain.com-error_log CustomLog logs/${domainname}.domain.com-access_log common ProxyPreserveHost On ProxyPass / http://localhost:${tomcatport}/ ProxyPassReverse / http://localhost:${tomcatport}/ ” >> /etc/httpd/conf/httpd.conf /etc/init.d/httpd restart #Start liferay/tomcat and wait to finish, clean log first because of greps below echo > $tomcatloc/logs/catalina.out $tomcatloc/bin/startup.sh echo ” Enjoy Liferay!!”
Join our mailing list to get the latest updates! We will not spam you.
Related Blogs



Categories
Related Case Studies






Services
Solutions
Products
Resources
ANZ: +61 423 683 702

APAC: +91 98664 98179
USA: +1 (408) 656-6493