Skip to content

Instantly share code, notes, and snippets.

@josch
Created August 28, 2018 11:10
Show Gist options
  • Save josch/25fd5e3336760cb346f327111382ca0a to your computer and use it in GitHub Desktop.
Save josch/25fd5e3336760cb346f327111382ca0a to your computer and use it in GitHub Desktop.
Setting up phenotips on Ubuntu Xenial with Tomcat and MySQL
#!/bin/sh
set -exu
directory=ubuntu-xenial-robot
debootstrap --variant=minbase --include=dbus,systemd-sysv xenial "$directory" http://archive.ubuntu.com/ubuntu/
systemd-nspawn --boot --resolv-conf=copy-host --directory="$directory" &
pid=$!
sleep 10 # wait for the system to boot
machinectl shell "$directory" /bin/sh -c "
set -exu
apt update
apt install --yes tomcat8
mkdir /var/lib/phenotips
chown -R tomcat8:tomcat8 /var/lib/phenotips
cat << END > /tmp/preseed
mysql-server mysql-server/root_password password password
mysql-server mysql-server/root_password_again password password
END
debconf-set-selections /tmp/preseed
rm /tmp/preseed
apt install --yes mysql-server
mysql -u root -ppassword -e 'create database phenotips default character set utf8 default collate utf8_bin;'
mysql -u root -ppassword -e 'grant all privileges on phenotips.* to phenotips@localhost identified by \"password\";'
"
mkdir "$directory"/var/lib/tomcat8/webapps/phenotips
if [ ! -e phenotips-war-1.3.7.war ]; then
curl https://nexus.phenotips.org/nexus/content/repositories/releases/org/phenotips/phenotips-war/1.3.7/phenotips-war-1.3.7.war > phenotips-war-1.3.7.war
fi
echo 0f1b9e1bea6ad479e46a6fbda253ad45 phenotips-war-1.3.7.war | md5sum --check
unzip -d "$directory"/var/lib/tomcat8/webapps/phenotips phenotips-war-1.3.7.war
xmlstarlet edit --inplace --pf \
--update "//session-factory/property[@name='connection.url']" --expr "string('jdbc:mysql://localhost/phenotips')" \
--update "//session-factory/property[@name='connection.username']" --expr "string('phenotips')" \
--update "//session-factory/property[@name='connection.password']" --expr "string('password')" \
--update "//session-factory/property[@name='connection.driver_class']" --expr "string('com.mysql.jdbc.Driver')" \
--update "//session-factory/property[@name='dialect']" --expr "string('org.hibernate.dialect.MySQL5InnoDBDialect')" \
--subnode "//session-factory" -t elem -n myprop -v true \
--insert "//myprop" -t attr -n "name" -v dbcp.poolPreparedStatements \
--rename "//myprop" -v "property" \
--subnode "//session-factory" -t elem -n myprop -v 20 \
--insert "//myprop" -t attr -n "name" -v dbcp.maxOpenPreparedStatements \
--rename "//myprop" -v "property" \
"$directory"/var/lib/tomcat8/webapps/phenotips/WEB-INF/hibernate.cfg.xml
echo xwiki.db=phenotips >> "$directory"/var/lib/tomcat8/webapps/phenotips/WEB-INF/xwiki.cfg
machinectl poweroff "$directory"
wait $pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment