check and upgrade node.js major version during update if not already installed

This commit is contained in:
ronivay
2020-06-20 11:39:04 +03:00
parent 38719cd17a
commit d1a7f2bda2

View File

@@ -261,22 +261,6 @@ function InstallDependenciesDebian {
printok "Installing setcap" printok "Installing setcap"
fi fi
# only install yarn repo and package if not found
cmdlog "which yarn"
if [[ -z $(which yarn 2>>$LOGFILE) ]]; then
echo
printprog "Installing yarn"
cmdlog "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -"
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >>$LOGFILE 2>&1
cmdlog "echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | tee /etc/apt/sources.list.d/yarn.list"
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list >>$LOGFILE 2>&1
cmdlog "apt-get update"
apt-get update >>$LOGFILE 2>&1
cmdlog "apt-get install -y yarn"
apt-get install -y yarn >>$LOGFILE 2>&1
printok "Installing yarn"
fi
# only run automated node install if executable not found # only run automated node install if executable not found
cmdlog "which node" cmdlog "which node"
@@ -294,7 +278,7 @@ function InstallDependenciesDebian {
# if we run Debian 10 and have default nodejs v10 installed, then replace it with node 12.x # if we run Debian 10 and have default nodejs v10 installed, then replace it with node 12.x
if [[ $OSVERSION == "10" ]]; then if [[ $OSVERSION == "10" ]]; then
NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1) NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
if [[ -n $NODEV ]] && [[ $NODEV < 12 ]]; then if [[ -n $NODEV ]] && [[ $NODEV -lt 12 ]]; then
echo echo
printprog "Installing node.js" printprog "Installing node.js"
cmdlog "curl -sL https://deb.nodesource.com/setup_12.x | bash -" cmdlog "curl -sL https://deb.nodesource.com/setup_12.x | bash -"
@@ -305,6 +289,22 @@ function InstallDependenciesDebian {
fi fi
fi fi
# only install yarn repo and package if not found
cmdlog "which yarn"
if [[ -z $(which yarn 2>>$LOGFILE) ]]; then
echo
printprog "Installing yarn"
cmdlog "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -"
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - >>$LOGFILE 2>&1
cmdlog "echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | tee /etc/apt/sources.list.d/yarn.list"
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list >>$LOGFILE 2>&1
cmdlog "apt-get update"
apt-get update >>$LOGFILE 2>&1
cmdlog "apt-get install -y yarn"
apt-get install -y yarn >>$LOGFILE 2>&1
printok "Installing yarn"
fi
echo echo
printprog "Enabling and starting redis service" printprog "Enabling and starting redis service"
cmdlog "/bin/systemctl enable redis-server && /bin/systemctl start redis-server" cmdlog "/bin/systemctl enable redis-server && /bin/systemctl start redis-server"
@@ -325,19 +325,46 @@ function UpdateNodeYarn {
if [ $OSNAME == "CentOS" ]; then if [ $OSNAME == "CentOS" ]; then
echo echo
printprog "Checking updates for nodejs and yarn" printinfo "Checking current node.js version"
cmdlog "yum update -y nodejs yarn" NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
yum update -y nodejs yarn >>$LOGFILE 2>&1 if [[ -n $NODEV ]] && [[ $NODEV -lt 12 ]]; then
printok "Checking updates for nodejs and yarn" echo
printprog "node.js version is $NODEV, upgrading to 12.x"
cmdlog "curl -sL https://rpm.nodesource.com/setup_12.x | bash -"
curl -sL https://rpm.nodesource.com/setup_12.x | bash - >>$LOGFILE 2>&1
cmdlog "yum clean all"
yum clean all >> $LOGFILE 2>&1
cmdlog "yum install -y nodejs"
yum install -y nodejs >>LOGFILE 2>&1
printok "node.js version is $NODEV, upgrading to 12.x"
else
echo
printprog "node.js version already on $NODEV, checking updates"
cmdlog "yum update -y nodejs yarn"
yum update -y nodejs yarn >>$LOGFILE 2>&1
printok "node.js version already on $NODEV, checking updates"
fi
else else
echo echo
printprog "Checking updates for nodejs and yarn" printinfo "Checking current node.js version"
cmdlog "apt-get install -y --only-upgrade nodejs yarn" NODEV=$(node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1)
apt-get install -y --only-upgrade nodejs yarn >>$LOGFILE 2>&1 if [[ -n $NODEV ]] && [[ $NODEV -lt 12 ]]; then
printok "Checking updates for nodejs and yarn" echo
printprog "node.js version is $NODEV, upgrading to 12.x"
cmdlog "curl -sL https://deb.nodesource.com/setup_12.x | bash -"
curl -sL https://deb.nodesource.com/setup_12.x | bash - >>$LOGFILE 2>&1
cmdlog "apt-get install -y nodejs"
apt-get install -y nodejs >>$LOGFILE 2>&1
printok "node.js version is $NODEV, upgrading to 12.x"
else
echo
printprog "node.js version already on $NODEV, checking updates"
cmdlog "apt-get install -y --only-upgrade nodejs yarn"
apt-get install -y --only-upgrade nodejs yarn >>$LOGFILE 2>&1
printok "node.js version already on $NODEV, checking updates"
fi
fi fi
fi fi
} }
function InstallXOPlugins { function InstallXOPlugins {