-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-atlascine.sh
executable file
·202 lines (168 loc) · 7.8 KB
/
install-atlascine.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
#
# This script will install Atlascine on a vanilla install of Ubuntu 18.04
#
#
# REFERENCES:
# - https://github.com/GCRC/nunaliit/wiki/Nunaliit-Documentation-for-Developers
# - https://github.com/GCRC/nunaliit/wiki/Nunaliit-Documentation-for-Atlas-Builders
# - https://github.com/GCRC/nunaliit_tutorial/wiki
#
#############################################################
##
## CONFIGURATION - IMPORT FROM SEPARATE CONFIG FILE
##
#############################################################
# Config file should be located in same directory as this script
SCRIPT_FOLDER="$(dirname $0)"
if [ ! -f "$SCRIPT_FOLDER/config.sh" ]; then
echo "ERROR: need to create config.sh for your environment"
exit 1
fi
. "$SCRIPT_FOLDER/config.sh"
#############################################################
##
## USEFUL DEFINITIONS
##
## Single place to define important commands, small helper
## functions, etc.
##
#############################################################
APT="apt-get -y -q"
## Quit with an err msg, like Perl in the good old days
function die()
{
echo "ERROR1 - $*" >&2
exit 1
}
## Quit if command returns non-zero exit
set -e
############################################################
#
# A. INSTALL PREREQUISITES
#
############################################################
## Make sure we are on Ubuntu 18.04
if [ ! -e /etc/lsb-release ]; then
echo "OS not deteted. Must must this script on Ubuntu 18.04!"
exit 1
fi
source /etc/lsb-release
if [ "$DISTRIB_ID" != "Ubuntu" -o "$DISTRIB_RELEASE" != "18.04" ]; then
echo "OS detected as '$DISTRIB_ID $DISTRIB_RELEASE'. Must run this script on Ubuntu 18.04!"
exit 1
fi
## Setup couchdb apt repository
curl https://couchdb.apache.org/repo/keys.asc | gpg --dearmor > /usr/share/keyrings/couchdb-archive-keyring.gpg || die "couchdb apt key installation failed"
echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ bionic main" > /etc/apt/sources.list.d/couchdb.list || die "couchdb apt repo setup failed"
## Update server packages
$APT update || die "apt update failed"
$APT full-upgrade || die "apt upgrade failed"
## Install misc. packages
echo "Configuring prerequisite packages" # die() causes debconf-set-selections to hang
debconf-set-selections <<EOF
ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula boolean true
EOF
# Java must be installed first, or else other pkgs pull in openjdk-11
$APT install apt-transport-https curl openjdk-8-jdk-headless || die "could not install prerequisite packages (1/2)"
$APT install imagemagick ffmpeg ubuntu-restricted-extras maven ant || die "could not install prerequisite packages (2/2)"
sed -i 's/^assistive_technologies=/#assistive_technologies=/' /etc/java-8-openjdk/accessibility.properties || die "could not configure java 8"
## Expect is only used in this script to automate 'nunaliit config'
$APT install expect || die "could not install prerequisite packages (expect)"
## jq is only used in this script to url-encode gitlab credentials
$APT install jq || die "could not install prerequisite packages (jq)"
## Install couchdb
echo "Configuring couchdb" # die() causes debconf-set-selections to hang
debconf-set-selections <<EOF
couchdb couchdb/adminpass_again password $COUCHDB_PASS
couchdb couchdb/adminpass password $COUCHDB_PASS
couchdb couchdb/bindaddress string 0.0.0.0
couchdb couchdb/mode select standalone
EOF
$APT install couchdb=2.3.1~bionic || die "Could not install couchdb"
apt-mark hold couchdb || die "could not hold couchdb at specific version"
#############################################################
##
## B. DOWNLOAD AND BUILD NUNALIIT
##
#############################################################
## Get Nunaliit source code
mkdir -p "$BASE_FOLDER" || die "Could not create directory BASE_FOLDER='$BASE_FOLDER'"
git clone https://github.com/GCRC/nunaliit.git "$SOURCE_FOLDER" || die "could not download nunaliit"
cd "$SOURCE_FOLDER" || die "SOURCE_FOLDER='$SOURCE_FOLDER' not found"
git checkout $NUNALIIT_BRANCH || die "Could not find Nunaliit branch: NUNALIIT_BRANCH='$NUNALIIT_BRANCH'"
## Build Nunaliit source code
#
# BUG: Nunaliit build (maven's installatino of project dependencies)
# cannot run as root. I believe it is due to this bug:
# https://github.com/npm/cli/issues/624
# so switch to a non-root user for the Nunaliit build:
chown -R "$USER_BUILD_NUNALIIT" "$SOURCE_FOLDER" || die "Could not set source ownership to USER_BUILD_NUNALIIT=$USER_BUILD_NUNALIIT"
su "$USER_BUILD_NUNALIIT" -c "mvn clean install" || die "Failed to build Nunaliit from source code"
## Unpack Nunaliit binaries
cd "$BASE_FOLDER"
tar zxvf "$SOURCE_FOLDER"/nunaliit2-couch-sdk/target/nunaliit_*.tar.gz || die "Could not open Nunaliit"
## Install nunaliit command on the system PATH
NUNALIIT="$BASE_FOLDER"/nunaliit_*/bin/nunaliit
if [ ! -e "$BINDIR/nunaliit" ]; then
ln -s $NUNALIIT "$BINDIR" || die "Could not setup shortcut to nunaliit command"
fi
NUNALIIT="$BINDIR/nunaliit"
#############################################################
##
## C. INSTALL ATLAS TEMPLATE
##
#############################################################
## Get Atlas template
USER_ESCAPED=$(jq -rn --arg var "$GCRC_GITLAB_USER" '$var|@uri')
PASS_ESCAPED=$(jq -rn --arg var "$GCRC_GITLAB_PASS" '$var|@uri')
git clone https://$USER_ESCAPED:$PASS_ESCAPED@gitlab.gcrc.carleton.ca/Atlascine/atlas-template.git "$ATLAS_FOLDER" || die "could not download Atlas templates to ATLAS_FOLDER='$ATLAS_FOLDER'"
cd "$ATLAS_FOLDER"
git checkout "$ATLAS_TEMPLATE_BRANCH" || die "Could not find atlas branch ATLAS_TEMPLATE_BRANCH='$ATLAS_TEMPLATE_BRANCH'"
## At least some atlas templates need this folder. Not sure
## if this folder path is hard-coded, or is configurable somewhere?
mkdir -p "$ATLAS_FOLDER/media"
## Configure Nunaliit
#
# This java code is interactive only - no built-in option to script
# it. So I use an expect 'macro' to hack in automation
cd "$ATLAS_FOLDER"
expect <<EOF
spawn $NUNALIIT config
expect "Enter the name of the atlas" { send "$ATLAS_NAME\n" }
expect "Enter the URL to CouchDB" { send "\n" }
expect "Enter the name of the main database" { send "$DB_NAME\n" }
expect "manually verify each document submission?" { send "Y\n" }
expect "name of the database where submissions will be uploaded" { send "$DB_SUBMISSION_NAME\n" }
expect "admin user for CouchDB" { send "\n" }
expect "password for the admin user" { send "$COUCHDB_PASS\n" }
expect "port where the atlas is served" { send "$URL_PORT\n" }
expect "Google Map API key" { send "\n" }
expect eof
EOF
$NUNALIIT update || die "failed to update Nunaliit atlas"
############################################################
#
# D. IMPORT EXISTING DATA (OPTIONAL)
#
############################################################
if [ "$RESTORE_EXISTING_DB" -ne 0 ]; then
mkdir -p "$DUMP_FOLDER" || die "Could not create folder DUMP_FOLDER='$DUMP_FOLDER'"
cd "$DUMP_FOLDER"
tar zxf "$DUMP_FILE" || die "Could not unpack DUMP_FILE='$DUMP_FILE'"
# I don't know whether this is helpful. Found it here:
# https://github.com/GCRC/nunaliit/issues/862
export JAVA_OPTS="-Xmx6g"
cd "$ATLAS_FOLDER"
$NUNALIIT restore --dump-dir "$DUMP_FOLDER/$UNPACKED_DUMP_NAME" || die "Failed to restore atlas from dump file"
fi
############################################################
#
# E. CONFIGURE SERVICE TO RUN AT BOOT
#
############################################################
cp "$ATLAS_FOLDER/extra/nunaliit-$ATLAS_NAME.service" /etc/systemd/system/ || die "Could not install startup service"
# In future, run as a non-root user?
sed -i 's/User=nunaliit/User=root/' /etc/systemd/system/nunaliit-$ATLAS_NAME.service || die "Could not change service username"
systemctl enable nunaliit-$ATLAS_NAME || die "Could not enable service"
systemctl start nunaliit-$ATLAS_NAME || die "Could not start service"