This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-apps.sh
86 lines (64 loc) · 3.4 KB
/
update-apps.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
#! /bin/bash -e
echo "+--------------------------------------------+"
echo "| Going to update Shiny Apps |"
echo "+--------------------------------------------+"
scriptpath="$( cd "$(dirname "$0")" && pwd -P || echo "$(dirname "$0") does not exist" && exit )"
echo ""
echo "SOS Credentials"
read -r -p "SOS Admin Username: " sos_admin_username
read -r -s -p "SOS Admin password: " sos_admin_password
echo ""
echo "--------------------"
echo "Database credentials"
read -r -p "Database: " database
read -r -p "Username: " database_user
read -r -s -p "Password: " database_password
echo ""
echo "--------------------"
echo "Server Environment"
read -r -p "FQDN of host: " host_name
documents_dir=/srv/dakamon-uploads
tools_zip="$scriptpath/tools.zip"
r_tools_dir="$scriptpath/tools"
shiny_srv_dir="/srv/shiny-server"
curl --fail --remote-header-name --location --silent --show-error --output "$tools_zip" https://github.com/52north/dakamon-r-tools/zipball/master
echo "$(date): Downloaded to $tools_zip"
echo "$(date): Unzip apps ..."
# delete old tools if present
echo "$(date): Remove old tools at $r_tools_dir"
rm -rv "$r_tools_dir" > /dev/null 2>&1 || :
unzip -q -o "$tools_zip" -d "$r_tools_dir"
echo "$(date): Shiny apps extracted to $(ls "$r_tools_dir")"
# ask for credentials before stopping shiny server
echo "$(date): Stop shiny server before updating apps"
systemctl stop shiny-server
echo "$(date): Copy apps to $shiny_srv_dir"
cp -r "$r_tools_dir/"*"dakamon-r-tools"*"/DaKaMon_viewer" "$shiny_srv_dir"
cp -r "$r_tools_dir/"*"dakamon-r-tools"*"/DaKaMon_importer" "$shiny_srv_dir"
cp -r "$r_tools_dir/"*"dakamon-r-tools"*"/docker/shiny-server.conf" "/etc/shiny-server/shiny-server.conf"
echo "------------------------------"
echo "Configure Importer/Viewer Apps"
echo "------------------------------"
# importer/viewer config
sed -i "s=SOSWebApp.*=SOSWebApp <- 'http://localhost:8080/52n-sos-webapp/'=g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s=feederPath.*=feederPath <- '/usr/local/52n/52n-sos-importer-feeder-bin.jar'=g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s/adminConf.*/adminConf <- authenticate(\"$sos_admin_username\", \"$sos_admin_password\")/g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s/dbHost.*/dbHost <- 'localhost'/g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s/dbPassword.*/dbPassword <- '$database_password'/g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s/dbUser.*/dbUser <- '$database_user'/g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s/dbName.*/dbName <- '$database'/g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s=fileUploadDir.*=fileUploadDir <- '$documents_dir'=g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
sed -i "s=fileDownloadBaseUrl.*=fileDownloadBaseUrl <- '$host_name/documents'=g" "$shiny_srv_dir/DaKaMon_importer/conf.R"
rm -v "$shiny_srv_dir/DaKaMon_viewer/conf.R"
ln -sv "$shiny_srv_dir/DaKaMon_importer/conf.R" "$shiny_srv_dir/DaKaMon_viewer/conf.R"
# create upload dir if not exist yet
mkdir -vp "$documents_dir" > /dev/null 2>&1 || :
chown -Rv shiny:shiny "$documents_dir"
chown -Rv shiny:shiny /srv/shiny-server/DaKaMon_viewer
chown -Rv shiny:shiny /srv/shiny-server/DaKaMon_importer
echo "$(date): Start shiny server after update ..."
systemctl start shiny-server
echo "$(date): Done."
echo "+--------------------------------------------+"
echo "| Shiny Apps Updated |"
echo "+--------------------------------------------+"