-
Notifications
You must be signed in to change notification settings - Fork 12
/
requirements
executable file
·82 lines (67 loc) · 2.43 KB
/
requirements
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
#!/usr/bin/env bash
set -e
if [[ -f /System/Library/CoreServices/SystemVersion.plist ]]; then
# macOS
PKG_MANAGER=$(command -v brew) || { echo "Homebrew is not installed. https://brew.sh/"; exit 1; }
else
PKG_MANAGER=$(command -v yum || command -v apt) || { echo "Platform not supported, check README and Prerequisite docs."; exit 1; }
fi
cd $(dirname $0)
echo "Setting up the prerequisites..."
echo
if [[ -f /etc/os-release ]]; then
OS_NAME=`(grep -o '^NAME=.*' /etc/os-release | cut -f2 -d\" | sed 's/"//g')`
PKG_MANAGER="apt";
PKG_TYPE="deb";
# Check if OS is RHEL/CentOS
# In case we have yum and apt-get installed on same machine then set PKG_MANAGER based on OS
if [[ ${OS_NAME} == *"Red Hat"* || ${OS_NAME} == *"CentOS"* ]]; then
PKG_MANAGER="yum";
PKG_TYPE="rpm";
fi
fi
install_nodejs () {
isNodeInstalled=`which node` && currentNodeVer=`node -v` || echo ''
requiredNodeVer="v16.14.0"
# Check if Node.js is not installed or the installed version is lesser than the ${requiredNodeVer}
if [[ "$isNodeInstalled" = "" ]] || [[ "$(printf '%s\n' "$requiredNodeVer" "$currentNodeVer" | sort -V | head -n1)" != "$requiredNodeVer" ]]; then
if [[ "$PKG_MANAGER" == *"brew"* ]]; then
$1 install node@16
$1 unlink node
$1 link --overwrite node@16
else
curl -L https://${PKG_TYPE}.nodesource.com/setup_16.x | sudo -E bash -
sudo $1 install -y nodejs
fi
fi
}
install_yarn () {
isYarnInstalled=`which yarn` && currentYarnVer=`yarn -v` || echo ''
requiredYarnVer="1.22.19"
# Check if yarn is not installed or the installed version is lesser than the ${requiredYarnVer}
if [[ "$isYarnInstalled" = "" ]] || [[ "$(printf '%s\n' "$requiredYarnVer" "$currentYarnVer" | sort -V | head -n1)" != "$requiredYarnVer" ]]; then
sudo npm install -g yarn
fi
}
case $PKG_MANAGER in
*yum*)
sudo yum install -y curl
install_nodejs "yum"
install_yarn
;;
*apt*)
sudo apt install -y curl
install_nodejs "apt"
install_yarn
;;
*brew*)
install_nodejs "brew"
install_yarn
;;
esac
# Don't run yarn build as root; if you had done, reclaim ownership for .npm and .config files
#sudo chown -R $USER:$GROUP $(sudo find / -type d -name .npm 2>/dev/null)
#sudo chown -R $USER:$GROUP $(sudo find / -type d -name .config 2>/dev/null)
echo "Node.js version: `node -v`"
echo "npm version: `npm -v`"
echo "yarn version: `yarn -v`"