-
Notifications
You must be signed in to change notification settings - Fork 402
/
Copy pathsetup_jukebox_webapp.sh
99 lines (83 loc) · 3.5 KB
/
setup_jukebox_webapp.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
#!/usr/bin/env bash
# Constants
GD_ID_COMPILED_WEBAPP="1um-smyfsVPzVZn18hhwuFt97XR3PjAbB" # https://drive.google.com/file/d/1um-smyfsVPzVZn18hhwuFt97XR3PjAbB/view?usp=sharing
# For ARMv7+
NODE_MAJOR=20
# For ARMv6
# To update version, follow these links
# https://github.com/sdesalas/node-pi-zero
# https://github.com/nodejs/unofficial-builds/
NODE_SOURCE_EXPERIMENTAL="https://raw.githubusercontent.com/sdesalas/node-pi-zero/master/install-node-v16.3.0.sh"
_jukebox_webapp_install_node() {
sudo apt-get -y update
if which node > /dev/null; then
echo " Found existing NodeJS. Hence, updating NodeJS" | tee /dev/fd/3
sudo npm cache clean -f
sudo npm install --silent -g n
sudo n --quiet latest
sudo npm update --silent -g
else
echo " Install NodeJS" | tee /dev/fd/3
# Zero and older versions of Pi with ARMv6 only
# support experimental NodeJS
if [[ $(uname -m) == "armv6l" ]]; then
wget -O - ${NODE_SOURCE_EXPERIMENTAL} | sudo bash
sudo apt-get -qq -y install nodejs
sudo npm install --silent -g npm
else
# install NodeJS and npm as recommended in
# https://github.com/nodesource/distributions
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install -y nodejs
fi
fi
}
# TODO: Avoid building the app locally
# Instead implement a Github Action that prebuilds on commititung a git tag
_jukebox_webapp_build() {
echo " Building web application"
cd "${INSTALLATION_PATH}/src/webapp" || exit_on_error
npm ci --prefer-offline --no-audit --production
rm -rf build
# The build wrapper script checks available memory on system and sets Node options accordingly
./run_rebuild.sh
}
_jukebox_webapp_download() {
echo " Downloading web application" | tee /dev/fd/3
local TAR_FILENAME="webapp-build.tar.gz"
cd "${INSTALLATION_PATH}/src/webapp" || exit_on_error
_download_file_from_google_drive ${GD_ID_COMPILED_WEBAPP} ${TAR_FILENAME}
tar -xzf ${TAR_FILENAME}
rm -f ${TAR_FILENAME}
cd "${INSTALLATION_PATH}" || exit_on_error
}
_jukebox_webapp_register_as_system_service_with_nginx() {
echo " Install and configure nginx" | tee /dev/fd/3
sudo apt-get -qq -y update
sudo apt-get -y purge apache2
sudo apt-get -y install nginx
sudo service nginx start
sudo mv -f /etc/nginx/sites-available/default /etc/nginx/sites-available/default.orig
sudo cp -f "${INSTALLATION_PATH}/resources/default-settings/nginx.default" /etc/nginx/sites-available/default
# make sure nginx can access the home directory of the user
sudo chmod o+x /home/pi
sudo service nginx restart
}
setup_jukebox_webapp() {
echo "Install web application" | tee /dev/fd/3
if [[ $ENABLE_WEBAPP_PROD_DOWNLOAD == true || $ENABLE_WEBAPP_PROD_DOWNLOAD == release-only ]] ; then
_jukebox_webapp_download
fi
if [[ $ENABLE_INSTALL_NODE == true ]] ; then
_jukebox_webapp_install_node
# Local Web App build during installation does not work at the moment
# Needs to be done after reboot! There will be a message at the end of the installation process
# _jukebox_webapp_build
fi
_jukebox_webapp_register_as_system_service_with_nginx
echo "DONE: setup_jukebox_webapp"
}