Skip to content

Commit

Permalink
New development environment install script
Browse files Browse the repository at this point in the history
Should work for travis, vagrant, docker and direct installations, so
that when something changes, there's hopefully just one place to touch.

The dist2 files content will be merged into the dist files when the
conversion finishes.
  • Loading branch information
lonemadmax committed Apr 28, 2018
1 parent bd4f229 commit 67f3f69
Show file tree
Hide file tree
Showing 10 changed files with 599 additions and 1 deletion.
4 changes: 4 additions & 0 deletions freeciv-proxy/settings.ini.dist2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Config]
mysql_user = #DB_USER#
mysql_database = #DB_NAME#
mysql_password = #DB_PASSWORD#
3 changes: 3 additions & 0 deletions freeciv-web/flyway.properties.dist2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flyway.user=#DB_USER#
flyway.password=#DB_PASSWORD#
flyway.url=jdbc:mysql://localhost:3306/#DB_NAME#?useSSL=false
15 changes: 15 additions & 0 deletions freeciv-web/src/main/webapp/META-INF/context.xml.dist2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Context>
<!-- Does Freeciv-web fail with a complaint about how your time zone is
"unrecognized or represents more than one time zone"? Change the "url"
attribute so it sets useLegacyDatetimeCode to false and serverTimezone to
your time zone.

Example: the computer is in Norway. Set the "url" attribute to
jdbc:mysql://localhost:3306/freeciv_web?useLegacyDatetimeCode=false&amp;serverTimezone=Europe/Oslo
(inside quatation marks) and rebuild. -->
<Resource name="jdbc/freeciv_mysql" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="#DB_USER#" password="#DB_PASSWORD#" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/#DB_NAME#?useSSL=false"/>

</Context>
13 changes: 13 additions & 0 deletions pbem/settings.ini.dist2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Config]
smtp_login = postmaster@freecivweb.info
smtp_password = password
smtp_host = smtp.mailgun.org
smtp_port = 587
smtp_sender = Freeciv-web <postmaster@freecivweb.info>

mysql_user = #DB_USER#
mysql_database = #DB_NAME#
mysql_password = #DB_PASSWORD#

savegame_directory = /var/lib/tomcat8/webapps/data/savegames/pbem/
ranklog_directory = /var/lib/tomcat8/webapps/data/ranklogs/
19 changes: 18 additions & 1 deletion scripts/configuration.sh.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Configuration used by the scripts
# Configuration used by the scripts and substituted in templates
#
# Keep in mind there's no escaping yet, so some characters like \ or "
# may be problematic in some variables.

# Freeciv-web database
DB_NAME=freeciv_web
DB_USER=$(id -run)
DB_PASSWORD=changeme

# This is the DB manager superuser password.
# Leave it blank to be asked for it when needed.
# The default value is random, which is OK only if you will never mess
# with the DB manager (in a dedicated vm for tests, like the travis install,
# for example), as reading the config again will give another value,
# so it won't be the correct one for this variable, and you are not notified
# of the first one.
DB_ROOT_PASSWORD=${RANDOM}${RANDOM}${RANDOM}

# Freeciv-web MySQL database
MYSQL_USER=root
Expand Down
105 changes: 105 additions & 0 deletions scripts/install/deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (C) 2018 The Freeciv-web project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

dependencies="nginx maven mysql-server openjdk-8-jdk-headless acl procps curl sed tar unzip git gnupg libcurl4-openssl-dev libjansson-dev pngcrush python3-pil python3-dev python3-setuptools python3-wheel libtool patch make automake autoconf autotools-dev python3-minimal libbz2-dev imagemagick python3-pip liblzma-dev libicu-dev pkg-config zlib1g-dev libsqlite3-dev webp libmagickcore.*extra libmagickwand-dev"

export DEBIAN_FRONTEND=noninteractive
INSTALLED_TOMCAT=N
INSTALLED_MYSQLPYCON=N

sudo apt-get -y update

if ! apt-cache -qq show openjdk-8-jdk-headless > /dev/null; then
echo "==== Adding openjdk-8 repo ===="
if [ "${FCW_INSTALL_VND}" = Ubuntu ]; then
sudo apt-get -y install --no-install-recommends python3-software-properties software-properties-common
sudo add-apt-repository -y ppa:openjdk-r/ppa
else
echo "deb http://http.debian.net/debian ${FCW_INSTALL_REL}-backports main" | sudo tee --append /etc/apt/sources.list.d/${FCW_INSTALL_REL}-backports.list > /dev/null
fi
sudo apt-get -y update
fi

if apt-cache -qq show tomcat8 > /dev/null; then
dependencies="${dependencies} tomcat8 tomcat8-admin"
INSTALLED_TOMCAT=Y
else
INSTALLED_TOMCAT=N
fi

if [ "${FCW_INSTALL_MODE}" = TEST ]; then
dependencies="${dependencies} xvfb"
fi

apt-cache policy python3-mysql.connector | while IFS= read -r line; do
if [ "${line::13}" = " Candidate: " ]; then
IFS=. v=(${line# Candidate: })
if [ ${v[0]} -lt 2 ]; then
INSTALLED_MYSQLPYCON=N
elif [ ${v[0]} -eq 2 ] && [ ${v[1]} -lt 1 ]; then
INSTALLED_MYSQLPYCON=N
else
dependencies="${dependencies} python3-mysql.connector"
INSTALLED_MYSQLPYCON=Y
fi
fi
done

echo "==== Installing Updates and Dependencies ===="
echo "apt-get upgrade"
sudo apt-get -y upgrade
echo "mysql setup..."
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password ${DB_ROOT_PASSWORD}"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password ${DB_ROOT_PASSWORD}"
echo "apt-get install dependencies"
sudo apt-get -y install --no-install-recommends ${dependencies}

# Where default-jdk is v7, it may be installed with a higher priority than v8
for n in java javac; do
sudo update-alternatives --set $n $(update-alternatives --query $n | sed -n 's/Alternative: \(.*java-8.*\)/\1/p' | head -n 1)
done

if [ "${INSTALLED_TOMCAT}" = N ]; then
ext_install_tomcat8
fi

if [ "${INSTALLED_MYSQLPYCON}" = N ]; then
ext_install_mysql_connector_python
fi

ext_install_tornado

TMPINSTDIR=$(mktemp -d)

echo "==== Installing Wikipedia helper ===="
cd "${TMPINSTDIR}"
sudo -H pip3 install wikipedia

echo "==== Installing Node.js ===="
cd "${TMPINSTDIR}"
curl -LOsS 'https://deb.nodesource.com/setup_8.x'
sudo bash setup_8.x
sudo apt-get -y install --no-install-recommends nodejs
# Populate ~/.config with current user
npm help > /dev/null

echo "==== Installing Handlebars ===="
cd "${TMPINSTDIR}"
sudo -H npm install handlebars -g

if [ "${FCW_INSTALL_MODE}" = TEST ]; then
ext_install_casperjs
fi

87 changes: 87 additions & 0 deletions scripts/install/ext-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (C) 2018 The Freeciv-web project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Installation of out-of-package-manager components

declare -a ext_installed

ext_install_tomcat8 () {
local TOMCAT_URL
local TMPFILE

echo "==== Installing tomcat8 ===="

TOMCAT_URL=$(curl -LsS 'https://tomcat.apache.org/download-80.cgi' | sed -n 's/^.*href="\([^"]*bin\/apache-tomcat-[0-9.]*tar\.gz\)".*/\1/p' | head -n 1)
if [ -z "${TOMCAT_URL}" ]; then
echo >&2 "Couldn't fetch download URL"
exit 1
fi

echo "Downloading tomcat8 from ${TOMCAT_URL}"
TMPFILE=$(mktemp -t tomcat8.XXXX.tar.gz)
curl -LsS -o "${TMPFILE}" "${TOMCAT_URL}"

cd /var/lib
sudo tar -xvzf "${TMPFILE}"
sudo mv apache-tomcat-8.* tomcat8

rm "${TMPFILE}"
echo "export CATALINA_HOME=\"/var/lib/tomcat8\"" >> ~/.bashrc
ext_installed[${#ext_installed[@]}]="tomcat8"
}

ext_install_tornado () {
local TMPINSTDIR

echo "==== Installing Tornado Web Server ===="

TMPINSTDIR=$(mktemp -d)
(
cd "${TMPINSTDIR}"
curl -LOsS 'https://github.com/tornadoweb/tornado/archive/v4.5.3.tar.gz'
tar xvfz v4.5.3.tar.gz
cd tornado-4.5.3
sudo -H python3 setup.py install
)
sudo rm -rf "${TMPINSTDIR}"
ext_installed[${#ext_installed[@]}]="tornado"
}

ext_install_casperjs () {
echo "==== Installing CasperJS for testing ===="
cd "${basedir}/tests"
curl -LOsS 'https://github.com/casperjs/casperjs/archive/1.1.4.zip'
unzip -qo 1.1.4.zip
rm 1.1.4.zip
sudo ln -sf "${basedir}/casperjs-1.1.4/bin/casperjs" /usr/local/bin/casperjs
ext_installed[${#ext_installed[@]}]="casperjs"
}

ext_install_mysql_connector_python () {
local TMPINSTDIR

echo "==== Installing mysql-connector-python ===="

TMPINSTDIR=$(mktemp -d)
(
cd "${TMPINSTDIR}"
curl -LOsS 'https://github.com/mysql/mysql-connector-python/archive/2.1.3.zip'
unzip -qo 2.1.3.zip
cd mysql-connector-python-2.1.3
sudo -H python3 setup.py install
)
sudo rm -rf "${TMPINSTDIR}"
ext_installed[${#ext_installed[@]}]="mysql-connector-python"
}
69 changes: 69 additions & 0 deletions scripts/install/gen-from-templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Copyright (C) 2018 The Freeciv-web project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Substitutes variables from the configuration file in the templates.
# gen-from-templates [configfile [source_dir]]
# When source_dir is not given, configfile's parent is used.
# When configfile is not given, script_src_dir/../configuration.sh is used.

set -e
unset CDPATH

CONFIG="$1"
SRCDIR="$2"

if [ -z "${CONFIG}" ]; then
CONFIG=${BASH_SOURCE%/*}
if [ -z "${CONFIG}" ]; then
echo >&2 "Configuration file not found."
exit 2
fi
CONFIG="${CONFIG}"/../configuration.sh
fi

if [ "${CONFIG:0:1}" = - ]; then
CONFIG=./"${CONFIG}"
fi

if [ ! -f "${CONFIG}" ]; then
echo >&2 "Configuration file not found."
exit 2
fi

if [ -z "${SRCDIR}" ]; then
SRCDIR=${CONFIG%/*}/..
fi

. "${CONFIG}"

TMPFILE=$(mktemp)
while IFS= read -r line; do
left=${line%%=*}
if [ "${#left}" -gt 0 ] && [ "${left:0:1}" != '#' ]; then
right=${!left}
right=${right//\\/\\\\}
right=${right////\\/}
right=${right//&/\\&}
echo -E "s/#${left}#/${right}/g"
fi
done < "${CONFIG}" > "${TMPFILE}"

for f in "${SRCDIR}"/{freeciv-proxy,pbem}/settings.ini "${SRCDIR}"/freeciv-web/flyway.properties "${SRCDIR}"/freeciv-web/src/main/webapp/META-INF/context.xml; do
sed -f "${TMPFILE}" < "$f".dist2 > "$f"
done
rm "${TMPFILE}"

Loading

0 comments on commit 67f3f69

Please sign in to comment.