This repository was archived by the owner on Nov 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodejs-installer.sh
More file actions
executable file
·116 lines (108 loc) · 4.65 KB
/
nodejs-installer.sh
File metadata and controls
executable file
·116 lines (108 loc) · 4.65 KB
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
#!/bin/bash
################################################################################
#
# Installs Node.js (version 14.x) and the required packages and
# dependencies for Botler to run. Node.js is installed using the instructions
# described here:
# https://github.com/nodesource/distributions/blob/master/README.md
#
# Note: All variables not defined in this script, are exported from
# 'linuxPMI.sh', 'linux-master-installer.sh', and 'sub-master-installer.sh'.
#
################################################################################
#
# [ Functions ]
#
################################################################################
#
install_nodejs() {
echo "Downloading the Node.js repo installer..."
if [[ $distro = "rhel" || $distro = "centos" ]]; then
curl -sL https://rpm.nodesource.com/setup_14.x | bash - || {
echo "${red}Failed to download the Node.js installer${nc}" >&2
read -p "Press [Enter] to return to the installer menu"
exit 1
}
else
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - || {
echo "${red}Failed to download the Node.js installer${nc}" >&2
read -p "Press [Enter] to return to the installer menu"
exit 1
}
fi
echo "Installing nodejs..."
$pkg_mng -y install nodejs || {
echo "${red}Failed to install nodejs${nc}" >&2
read -p "Press [Enter] to return to the installer menu"
exit 1
}
}
install_node_module_pkgs() {
while true; do
if hash npm &>/dev/null; then
echo "Installing node_modules..."
npm install --prefix Botler/ --only=prod || {
echo "${red}Failed to install node_modules${nc}" >&2
read -p "Press [Enter] to return to the installer menu"
exit 1
}
echo "Installing typescript globally..."
npm install -g typescript || {
echo "${red}Failed to install typescript globally" >&2
echo "${cyan}Typescript is required to compile the code" \
"to JS${nc}"
read -p "Press [Enter] to return to the installer menu"
exit 1
}
echo "Funding node_module packages"
npm fund --prefix Botler/ || {
echo "${red}Failed to fund npm node_module packages${nc}" >&2
}
break
else
echo "${yellow}npm is not installed${nc}"
# Npm might not exist due to Node.js not being installed
if (! hash node || ! hash nodejs) &>/dev/null; then
echo "${yellow}nodejs is not installed${nc}"
install_nodejs
fi
if ! hash npm &>/dev/null; then
echo "${red}npm is not installed" >&2
# Sometimes npm isn't installed for some reason, and it is
# necessary to reinstall Node.js
echo -e "${cyan}Try reinstalling nodejs, then try again" \
"\nTo reinstall nodejs: sudo $pkg_mng reinstall" \
"nodejs${nc}"
read -p "Press [Enter] to return to the installer menu"
exit 1
fi
fi
done
}
#
################################################################################
#
# [ Main ] code
#
################################################################################
#
if ((option == 3)); then
printf "We will now download and install nodejs and any required packages. "
read -p "Press [Enter] to begin."
install_nodejs
install_node_module_pkgs
echo "Changing ownership of the file(s) added to '/home/botler'..."
chown botler:botler -R /home/botler
echo -e "\n${green}Finished downloading and installing nodejs and any" \
"required packages${nc}"
read -p "Press [Enter] to return to the installer menu"
else
printf "We will now install the required packages and dependencies. "
read -p "Press [Enter] to begin."
install_node_module_pkgs
echo "Changing ownership of the file(s) added to '/home/botler'..."
chown botler:botler -R /home/botler
echo -e "\n${green}Finished installing required packages and" \
"dependencies${nc}"
read -p "Press [Enter] to return to the installer menu"
fi