Last active
May 3, 2017 19:46
-
-
Save dgauche/a929f7eb8d813a84048b0c501625e956 to your computer and use it in GitHub Desktop.
Installation script to install ThingWorx Platform 7.4 on Ubuntu Linux 14.04 LTS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Prepared for ThingWorx Platform v7.4 | |
###### - EDIT to reflect your environment - ####### | |
StdPassword="Y0urP@ssw0rd" | |
ThingWorxPSQLToInstall="ThingWorx Potgress Download URL" | |
ThingWorxH2ToInstall="ThingWorx H2 Download URL" | |
ThingWorxHANAToInstall="ThingWorx Hana Download URL" | |
email="me@mydomain.com" | |
################################################### | |
###### - You probably dont need to change anything here - ####### | |
UBUNTUVERSION="14.04 LTS" | |
JavaToInstall="http://download.oracle.com/otn-pub/java/jdk/8u92-b14/jdk-8u92-linux-x64.tar.gz" | |
TomcatToInstall="http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.33/bin/apache-tomcat-8.0.33.tar.gz" | |
CertificateProvider="self" | |
UserID="" | |
FQDN="" | |
################################################### | |
######## Functions | |
configure_host() | |
{ | |
##### | |
#In some instances Ubuntu has a problem running sudo unless the ubuntu host is listed. This fixes that. | |
##### | |
echo "--Fixing host name resolution" | |
fixhost=$(grep ubuntu /etc/hosts) | |
if [[ $fixhost = "" ]]; then | |
cat <<- _EOF_ >> /etc/hosts | |
127.0.0.1 ubuntu | |
_EOF_ | |
fi | |
} | |
install_prereqs() | |
{ | |
echo "#####################################################################################" | |
echo "--Installing prerequisites NTP and Authbind" | |
echo "#####################################################################################" | |
sudo apt-get update | |
sudo apt-get --assume-yes install ntp | |
sudo apt-get --assume-yes install authbind | |
echo "*************************************************************************************" | |
echo "--Done installing prerequisites." | |
echo "*************************************************************************************" | |
} | |
install_java() | |
{ | |
echo "#####################################################################################" | |
echo "--Downloading and installing Java" | |
echo "#####################################################################################" | |
wget -O jdk.tar.gz --no-check-certificate -c --header "Cookie: oraclelicense=accept- securebackup-cookie" $JavaToInstall | |
tar -xf jdk.tar.gz | |
JAVA_LOCATION=$(ls -d *jdk1.8.* | tail -1) | |
JAVA_HOME=/usr/lib/jvm/$JAVA_LOCATION | |
sudo mkdir -p /usr/lib/jvm | |
sudo mv $JAVA_LOCATION/ /usr/lib/jvm/ | |
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/$JAVA_LOCATION/bin/java" 1 | |
sudo update-alternatives --install "/usr/bin/keytool" "keytool" "/usr/lib/jvm/$JAVA_LOCATION/bin/keytool" 1 | |
sudo chmod a+x /usr/bin/java | |
sudo chmod a+x /usr/bin/keytool | |
sudo chown -R root:root /usr/lib/jvm/$JAVA_LOCATION/ | |
sudo update-alternatives --config java | |
sudo update-alternatives --config keytool | |
java -version | |
echo "*************************************************************************************" | |
echo "--Done installing Java" | |
echo "*************************************************************************************" | |
} | |
install_tomcat() | |
{ | |
echo "#####################################################################################" | |
echo "--Downloading and installing Tomcat" | |
echo "#####################################################################################" | |
wget -O apache-tomcat.tar.gz $TomcatToInstall | |
tar -xf apache-tomcat.tar.gz | |
TOMCAT_LOCATION=$(ls -d *apache-tomcat-* | tail -1) | |
TOMCAT_VERSION=$(echo $TOMCAT_LOCATION | sed 's/apache-tomcat-//') | |
CATALINA_HOME=/usr/share/tomcat8/$TOMCAT_VERSION | |
sudo mkdir -p /usr/share/tomcat8 | |
sudo mv $TOMCAT_LOCATION /usr/share/tomcat8/$TOMCAT_VERSION | |
cat <<- _EOF_ >> /etc/environment | |
export JAVA_HOME=/usr/lib/jvm/$JAVA_LOCATION | |
export CATALINA_HOME=/usr/share/tomcat8/$TOMCAT_VERSION | |
_EOF_ | |
cd $CATALINA_HOME | |
sudo addgroup --system tomcat8 --quiet | |
sudo adduser --system --home /usr/share/tomcat8/ --no-create-home --ingroup tomcat8 --disabled-password --shell /bin/false tomcat8 | |
sudo chown -Rh tomcat8:tomcat8 bin/ lib/ webapps/ | |
sudo chmod 775 bin/ lib/ webapps/ | |
sudo chown -Rh root:tomcat8 conf/ | |
sudo chmod 640 conf/* | |
sudo chown -R tomcat8:adm logs/ temp/ work/ | |
sudo chmod 750 logs/ temp/ work/ | |
sudo cat <<- _EOF_ >> $CATALINA_HOME/bin/setenv.sh | |
export JAVA_OPTS="-Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dserver -Dd64 -XX:+UseNUMA -XX:+UseConcMarkSweepGC -Dfile.encoding=UTF-8 -Djava.library.path=$CATALINA_HOME/webapps/Thingworx/WEB-INF/extensions" | |
export JRE_HOME=/usr/lib/jvm/$JAVA_LOCATION/jre | |
_EOF_ | |
sudo chown tomcat8:tomcat8 bin/setenv.sh | |
sudo chmod 775 bin/setenv.sh | |
echo "*************************************************************************************" | |
echo "--Done installing Tomcat" | |
echo "*************************************************************************************" | |
} | |
Install_selfSigned() | |
{ | |
echo "#####################################################################################" | |
echo "Setting up self signed certificate" | |
echo "#####################################################################################" | |
sudo $JAVA_HOME/bin/keytool -genkey -alias tomcat8 -keyalg RSA -keystore $CATALINA_HOME/conf/.keystore -storepass $StdPassword -dname "CN=TwXInstall, OU=TwX, O=TwX, L=Johannesburg, | |
S=Gauteng, C=ZA" -keypass $StdPassword | |
sudo chown root:tomcat8 $CATALINA_HOME/conf/.keystore | |
sudo chmod 640 $CATALINA_HOME/conf/.keystore | |
sed -i.bak0 '/<!-- Uncomment this to disable session persistence across Tomcat restarts -->/,+3d' $CATALINA_HOME/conf/context.xml | |
sed -i.bak1 '/<WatchedResource>${catalina.base}/a <Manager pathname="" />' $CATALINA_HOME/conf/context.xml | |
sed -i.bak0 's/<Server port="8005" shutdown="SHUTDOWN">/<Server port="8005" shutdown="TH!nGW0rX">/g' $CATALINA_HOME/conf/server.xml | |
sed -i.bak1 '/<Connector port="8080" protocol="HTTP/i <!--' $CATALINA_HOME/conf/server.xml | |
sed -i.bak2 '/<!-- A "Connector" using the shared thread pool-->/i -->' $CATALINA_HOME/conf/server.xml | |
sed -i.bak3 '/<!-- A "Connector" using the shared thread pool-->/i <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" keystoreFile="${user.home}\/'"$TOMCAT_VERSION"'\/conf\/.keystore" keystorePass="'"$StdPassword"'" clientAuth="false" sslProtocol="TLS" \/>' $CATALINA_HOME/conf/server.xml | |
echo "*************************************************************************************" | |
echo "--Done installing self signed Certificate" | |
echo "*************************************************************************************" | |
} | |
Install_LetsEncrypt() | |
{ | |
echo "#####################################################################################" | |
echo "Downloading and installing LetsEncrypt" | |
echo "#####################################################################################" | |
rm $CATALINA_HOME/conf/.keystore | |
wget https://dl.eff.org/certbot-auto | |
chmod a+x certbot-auto | |
sudo ./certbot-auto | |
sudo service tomcat8 stop | |
sudo ./certbot-auto certonly --standalone -d $FQDN --email $email | |
cd /etc/letsencrypt/live/$FQDN/ | |
echo "=================================================" | |
echo "use password: $StdPassword for the export" | |
echo "=================================================" | |
openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out pkcs.p12 -name tomcat | |
keytool -importkeystore -deststorepass $StdPassword -destkeypass $StdPassword -destkeystore MyDSKeyStore.jks -srckeystore pkcs.p12 -srcstoretype PKCS12 -srcstorepass $StdPassword -alias tomcat | |
sudo cp ./MyDSKeyStore.jks $CATALINA_HOME/conf/.keystore | |
sudo chown root:tomcat8 $CATALINA_HOME/conf/.keystore | |
sudo chmod 640 $CATALINA_HOME/conf/.keystore | |
sudo service tomcat8 restart | |
echo "*************************************************************************************" | |
echo "--Done installing LetsEncrypt Certificate" | |
echo "*************************************************************************************" | |
} | |
Configure_Tomcat() | |
{ | |
echo "#####################################################################################" | |
echo "--Performing Tomcat configuration" | |
echo "#####################################################################################" | |
UserID=$(id -u tomcat8) | |
echo "0.0.0.0/0:1,1023" >> /etc/authbind/byuid/$UserID | |
sudo chown tomcat8:tomcat8 /etc/authbind/byuid/$UserID | |
sudo chmod 700 /etc/authbind/byuid/$UserID | |
sed -i.bak 's/exec "$PRGDIR"\/"$EXECUTABLE" start "$@"/ #exec "$PRGDIR"\/"$EXECUTABLE" start "$@"/g' $CATALINA_HOME/bin/startup.sh | |
sed -i.bak1 '/exec "$PRGDIR"\/"$EXECUTABLE" start "$@"/a exec authbind --deep "$PRGDIR"\/"$EXECUTABLE" start "$@"' $CATALINA_HOME/bin/startup.sh | |
echo "CATALINA_HOME=/usr/share/tomcat8/$TOMCAT_VERSION | |
case "'$1'" in | |
start) | |
/bin/su -p -s /bin/sh tomcat8 $CATALINA_HOME/bin/startup.sh | |
;; | |
stop) | |
/bin/su -p -s /bin/sh tomcat8 $CATALINA_HOME/bin/shutdown.sh | |
;; | |
restart) | |
/bin/su -p -s /bin/sh tomcat8 $CATALINA_HOME/bin/shutdown.sh | |
/bin/su -p -s /bin/sh tomcat8 $CATALINA_HOME/bin/startup.sh | |
;; | |
esac | |
exit 0 " >> /etc/init.d/tomcat8 | |
sudo chmod 755 /etc/init.d/tomcat8 | |
sudo ln -s /etc/init.d/tomcat8 /etc/rc1.d/K99tomcat | |
sudo ln -s /etc/init.d/tomcat8 /etc/rc2.d/S99tomcat | |
sed -i.bak1 '/<context>/a <Resources cacheMaxSize="501200" cacheObjectMaxSize="2048" cacheTtl="60000"\/>' $CATALINA_HOME/conf/context.xml | |
echo "*************************************************************************************" | |
echo "--Done configuring Tomcat" | |
echo "*************************************************************************************" | |
} | |
Install_postgress() | |
{ | |
echo "#####################################################################################" | |
echo "Downloading and installing Postgres" | |
echo "#####################################################################################" | |
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | |
sudo wget -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - | |
sudo apt-get update | |
sudo apt-get --assume-yes install postgresql-9.4 -y | |
echo "=================================================" | |
echo -e "$StdPassword\n$StdPassword" | passwd postgres | |
echo "=================================================" | |
sudo -u postgres psql -c "ALTER ROLE postgres WITH password '$StdPassword'" | |
sed -i.bak "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/9.4/main/postgresql.conf | |
sudo service postgresql restart | |
sudo -u postgres psql -c "CREATE USER twadmin WITH PASSWORD '$StdPassword';" | |
sudo service postgresql status | |
sudo mkdir /ThingworxPostgresqlStorage | |
sudo chown postgres:postgres /ThingworxPostgresqlStorage | |
sudo chmod 755 /ThingworxPostgresqlStorage | |
echo "*************************************************************************************" | |
echo "--Done installing PostgresSQL" | |
echo "*************************************************************************************" | |
} | |
Clean_Tomcat() | |
{ | |
echo "#####################################################################################" | |
echo "Cleaning up and securing Tomcat" | |
echo "#####################################################################################" | |
rm -rf $CATALINA_HOME/webapps/docs | |
rm -rf $CATALINA_HOME/webapps/examples | |
rm -rf $CATALINA_HOME/webapps/host-manager | |
rm -rf $CATALINA_HOME/webapps/manager | |
rm -rf $CATALINA_HOME/webapps/docs | |
rm -rf $CATALINA_HOME/webapps/ROOT/* | |
echo "*************************************************************************************" | |
echo "--Done cleaning up Tomcat webapps folder" | |
echo "*************************************************************************************" | |
} | |
Set_ThingWorxAsBase() | |
{ | |
echo "#####################################################################################" | |
echo "Setting ThingWorx as Tomcat's ROOT application" | |
echo "#####################################################################################" | |
# Reference https://oracle-base.com/articles/linux/tomcat-default-redirect | |
cat <<- _EOF_ >> $CATALINA_HOME/webapps/ROOT/index.jsp | |
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> | |
<html> | |
<head> | |
<title>JSP Redirect</title> | |
</head> | |
<body> | |
<% | |
String redirectURL = "https://$FQDN/Thingworx"; | |
response.sendRedirect(redirectURL); | |
%> | |
</body> | |
</html> | |
_EOF_ | |
echo "*************************************************************************************" | |
echo "--Done with redirect" | |
echo "*************************************************************************************" | |
} | |
TWXH2() | |
{ | |
echo "#####################################################################################" | |
echo "Installing ThingWorx with H2 Database" | |
echo "#####################################################################################" | |
install_prereqs | |
JAVATOMCAT | |
sudo apt-get --assume-yes install unzip | |
wget -O ThingWorx.zip $ThingWorxH2ToInstall | |
sudo unzip ThingWorx.zip | |
sudo mkdir /ThingworxStorage /ThingworxBackupStorage | |
sudo chown tomcat8:tomcat8 /ThingworxStorage /ThingworxBackupStorage | |
sudo chmod 775 /ThingworxStorage /ThingworxBackupStorage | |
sudo cp Thingworx.war $CATALINA_HOME/webapps | |
sudo cp license.bin /ThingworxPlatform | |
sudo chown tomcat8:tomcat8 $CATALINA_HOME/webapps/Thingworx.war | |
sudo chmod 775 $CATALINA_HOME/webapps/Thingworx.war | |
Install_selfSigned | |
Clean_Tomcat | |
Set_ThingWorxAsBase | |
echo "*************************************************************************************" | |
echo "--Done installing ThingWorx with H2 Database" | |
echo "*************************************************************************************" | |
} | |
TWXPSQL() | |
{ | |
echo "#####################################################################################" | |
echo "Installing ThingWorx with PostgresSQL Database" | |
echo "#####################################################################################" | |
install_prereqs | |
JAVATOMCAT | |
Install_postgress | |
sudo apt-get --assume-yes install unzip | |
wget -O ThingWorx.zip $ThingWorxPSQLToInstall | |
sudo unzip ThingWorx.zip | |
cd install | |
echo "=================================================" | |
echo "When prompted enter $StdPassword as your password" | |
echo "=================================================" | |
sudo sh ./thingworxPostgresDBSetup.sh -a postgres -u twadmin -l /ThingworxPostgresqlStorage | |
echo "=================================================" | |
echo "When prompted enter $StdPassword as your password" | |
echo "=================================================" | |
sudo sh ./thingworxPostgresSchemaSetup.sh | |
sudo mkdir /ThingworxPlatform | |
cd .. | |
sed -i.bak 's/"password": "password",/"password": "'$StdPassword'",/' platform-settings.json | |
sudo cp platform-settings.json /ThingworxPlatform/ | |
sudo cp license.bin /ThingworxPlatform/ | |
sudo mkdir /ThingworxStorage /ThingworxBackupStorage | |
sudo chown tomcat8:tomcat8 /ThingworxStorage /ThingworxBackupStorage | |
sudo chmod 775 /ThingworxStorage /ThingworxBackupStorage | |
sudo cp Thingworx.war $CATALINA_HOME/webapps | |
sudo chown tomcat8:tomcat8 $CATALINA_HOME/webapps/Thingworx.war | |
sudo chmod 775 $CATALINA_HOME/webapps/Thingworx.war | |
Install_selfSigned | |
Clean_Tomcat | |
Set_ThingWorxAsBase | |
echo "*************************************************************************************" | |
echo "--Done installing ThingWorx with PostgresSQL Database" | |
echo "--RESTART NOW" | |
echo "*************************************************************************************" | |
} | |
TWXHANA() | |
{ | |
echo "Installing ThingWorx with HANA Database" | |
install_prereqs | |
echo "not yet supported" | |
} | |
JAVATOMCAT() | |
{ | |
echo "#####################################################################################" | |
echo "Installing Java and then Tomcat" | |
echo "#####################################################################################" | |
install_java | |
install_tomcat | |
Configure_Tomcat | |
} | |
OnlyJava() | |
{ | |
echo "#####################################################################################" | |
echo "Installing Only Java" | |
echo "#####################################################################################" | |
install_java | |
} | |
OnlyTomcat() | |
{ | |
echo "#####################################################################################" | |
echo "Installing Only Tomcat" | |
echo "#####################################################################################" | |
install_tomcat | |
Configure_Tomcat | |
} | |
####### Main | |
configure_host | |
clear | |
echo "Welcome to the ThingWorx Installation script. This script will install the ThingWorx Platform. | |
Please note that this script is designed to be used on $UBUNTUVERSION and may not function as intended in other environments." | |
echo "" | |
echo " -----------------------------------------------------------------------" | |
echo " Please enter your Fully Qualified Domain name (FQDN) eg. www.mysite.com" | |
echo " -----------------------------------------------------------------------" | |
echo -n "Enter selection: " | |
read FQDN | |
clear | |
selection= | |
until [ "$selection" = "0" ]; do | |
echo " | |
THINGWORX INSTALL MENU - Slect what you would like to install: | |
Selecting 1 - 3 will automatically install Java and Tomcat | |
1 - ThingWorx with H2 Database | |
2 - ThingWorx with PostgresSQL Database | |
3 - ThingWorx with HANA Database | |
4 - Only Java and Tomcat | |
5 - Only Java | |
6 - Only Tomcat | |
7 - Install LetsEncrypt Signed Certificate (First install 1, 2 or 3) | |
0 - Exit | |
" | |
echo -n "Enter selection: " | |
read selection | |
echo "" | |
case $selection in | |
1 ) TWXH2 ;; | |
2 ) TWXPSQL ;; | |
3 ) TWXHANA ;; | |
4 ) JAVATOMCAT ;; | |
5 ) OnlyJava ;; | |
6 ) OnlyTomcat ;; | |
7 ) Install_LetsEncrypt ;; | |
0 ) exit ;; | |
* ) echo "Please enter an option 0 - 7" | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment