Skip to content

Commit

Permalink
chore: Add installation scripts
Browse files Browse the repository at this point in the history
chore: Add installation scripts
  • Loading branch information
Jefferson authored and riosje committed Oct 27, 2023
1 parent b84e91a commit 4f746d9
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 0 deletions.
84 changes: 84 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: 'Test Installation Scripts'

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
deb:
name: "NodeJS ${{ matrix.version }}(${{ matrix.os }})"
runs-on: ubuntu-latest
strategy:
matrix:
version: [18, 20, 21]
os: ["ubuntu:22.04", "debian:10"]
container:
image: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Update and Install Dependencies
run: |
apt-get update -y
apt-get install curl git -y
- name: Checkout Repo
uses: actions/checkout@v4

- name: Run Istallation Script
run: ./scripts/nsolid_setup_deb.sh ${{ matrix.version }}

- name: Install Nodejs
run: |
apt-get install nodejs -y
- name: Validate Node Version
run: |
node -e "console.log(process.version)"
NODE_VERSION=$(node -e "console.log((process.version).split('.')[0])")
if [[ ${NODE_VERSION} != "v${{ matrix.version }}" ]]; then
echo "Node version is not ${{ matrix.version }}. It is $NODE_VERSION"
exit 1
fi
rpm:
name: "NodeJS ${{ matrix.version }}(${{ matrix.os }})"
runs-on: ubuntu-latest
strategy:
matrix:
version: [18, 20, 21]
os: ["fedora:36", "amazonlinux:2023"]
container:
image: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Update and Install Dependencies
run: |
yum update -y
yum install git -y
- name: Checkout Repo
uses: actions/checkout@v4

- name: Run Istallation Script
run: ./scripts/nsolid_setup_rpm.sh ${{ matrix.version }}

- name: Install Nodejs
run: |
yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
- name: Validate Node Version
run: |
node -e "console.log(process.version)"
NODE_VERSION=$(node -e "console.log((process.version).split('.')[0])")
if [[ ${NODE_VERSION} != "v${{ matrix.version }}" ]]; then
echo "Node version is not ${{ matrix.version }}. It is $NODE_VERSION"
exit 1
fi
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

[![CircleCI](https://circleci.com/gh/nodesource/distributions/tree/master.svg?style=svg)](https://circleci.com/gh/nodesource/distributions/tree/master)

[![Github Actions Test](https://github.com/nodesource/distributions/actions/workflows/CI.yaml/badge.svg)](https://github.com/nodesource/distributions/actions/workflows/CI.yaml)

This repository contains the instructions to install the **[NodeSource](https://nodesource.com)** **[Node.js](http://nodejs.org)** Binary Distributions via .rpm and .deb as well as their setup and support scripts.

If you're looking for NodeSource's low-impact Node.js performance monitoring platform, please **[get started here](https://accounts.nodesource.com/sign-up-linuxdistro).**
Expand Down Expand Up @@ -216,6 +218,34 @@ rm -r /etc/yum.repos.d/nodesource*.repo &&\
yum clean all
```

## Installation Scripts

We've created some scripts to make easy the repo configuration.
> This only works from Node16 forwards
#### DEB

> change the version as needed `./nsolid_setup_deb.sh 20`
```SHELL
curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh
chmod 500 nsolid_setup_deb.sh
./nsolid_setup_deb.sh 21
apt-get install nodejs -y
```


#### RPM

> change the version as needed `./nsolid_setup_deb.sh 20`
```SHELL
curl -SLO https://rpm.nodesource.com/nsolid_setup_rpm.sh
chmod 500 nsolid_setup_rpm.sh
./nsolid_setup_rpm.sh 21
yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
```

## Nodejs Release Calendar

[![Node Releases Calendar](https://raw.githubusercontent.com/nodejs/Release/main/schedule.svg?sanitize=true)](https://nodejs.dev/en/about/releases)
Expand Down
109 changes: 109 additions & 0 deletions scripts/nsolid_setup_deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/sh
set -e

NSOLID_VERSION=$1

################################
## Logger Function ##
################################
logger() {
local message="$1"
local type="$2"
local length=${#message}
local line=$(printf "%-${length}s" | tr ' ' '-')
echo ""
case "$type" in
"info")
echo "\033[38;5;79m$line\033[0m"
echo "\033[38;5;79m$message\033[0m"
echo "\033[38;5;79m$line\033[0m"
;;
"success")
echo "\033[1;32m$line\033[0m"
echo "\033[1;32m$message\033[0m"
echo "\033[1;32m$line\033[0m"
;;
"error")
echo "\033[1;31m$line\033[0m"
echo "\033[1;31m$message\033[0m"
echo "\033[1;31m$line\033[0m"
;;
*)
echo "\033[1;34m$line\033[0m"
echo "\033[1;34m$message\033[0m"
echo "\033[1;34m$line\033[0m"
;;
esac
echo ""
}


################################
## Error handler function ##
################################
handleError() {
local exit_code=$1
local error_message="$2"
logger "Error: $error_message (Exit Code: $exit_code)" "error"
exit $exit_code
}

################################
##Function to validate version##
################################
getVersion() {
local NSOLID_VERSION=$1
regex='^[0-9][0-9]$'
if ! expr "$NSOLID_VERSION" : "$regex" > /dev/null; then
return 1
fi
logger "Info: Configuring repository for N|solid $NSOLID_VERSION" "info"
}

#################################################
##Function to Install the script pre-requisites##
#################################################
installPreReqs() {
logger "Info: Installing pre-requisites" "info"

# Run 'apt-get update'
if ! apt-get update -y; then
handleError "$?" "Failed to run 'apt-get update'"
fi

# Run 'apt-get install'
if ! apt-get install -y ca-certificates curl gnupg; then
handleError "$?" "Failed to install packages"
fi

mkdir -p /usr/share/keyrings

# Run 'curl' and 'gpg'
if ! curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg; then
handleError "$?" "Failed to download and import the NodeSource signing key"
fi
}

##################################
##Function to configure the Repo##
##################################
configureRepo() {
local NSOLID_VERSION=$1
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NSOLID_VERSION.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
# N|solid Config
echo "Package: nsolid" > /etc/apt/preferences.d/nsolid
echo "Pin: origin deb.nodesource.com" >> /etc/apt/preferences.d/nsolid
echo "Pin-Priority: 600" >> /etc/apt/preferences.d/nsolid
# Nodejs Config
echo "Package: nodejs" > /etc/apt/preferences.d/nodejs
echo "Pin: origin deb.nodesource.com" >> /etc/apt/preferences.d/nodejs
echo "Pin-Priority: 600" >> /etc/apt/preferences.d/nodejs
# Run 'apt-get update'
if ! apt-get update -y; then
handleError "$?" "Failed to run 'apt-get update'"
fi
}

getVersion $NSOLID_VERSION || handleError $? "Must define a valid N|solid version"
installPreReqs || handleError $? "Failed installing pre-requisites"
configureRepo $NSOLID_VERSION || handleError $? "Failed configuring repository"
75 changes: 75 additions & 0 deletions scripts/nsolid_setup_rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/sh
set -e

NSOLID_VERSION=$1

################################
## Logger Function ##
################################
logger() {
local message="$1"
local type="$2"
local length=${#message}
local line=$(printf "%-${length}s" | tr ' ' '-')
echo ""
case "$type" in
"info")
echo "\033[38;5;79m$line\033[0m"
echo "\033[38;5;79m$message\033[0m"
echo "\033[38;5;79m$line\033[0m"
;;
"success")
echo "\033[1;32m$line\033[0m"
echo "\033[1;32m$message\033[0m"
echo "\033[1;32m$line\033[0m"
;;
"error")
echo "\033[1;31m$line\033[0m"
echo "\033[1;31m$message\033[0m"
echo "\033[1;31m$line\033[0m"
;;
*)
echo "\033[1;34m$line\033[0m"
echo "\033[1;34m$message\033[0m"
echo "\033[1;34m$line\033[0m"
;;
esac
echo ""
}


################################
## Error handler function ##
################################
handleError() {
local exit_code=$1
local error_message="$2"
logger "Error: $error_message (Exit Code: $exit_code)" "error"
exit $exit_code
}

################################
##Function to validate version##
################################
getVersion() {
local NSOLID_VERSION=$1
regex='^[0-9][0-9]$'
if ! expr "$NSOLID_VERSION" : "$regex" > /dev/null; then
return 1
fi
logger "Info: Configuring repository for N|solid $NSOLID_VERSION" "info"
}

##################################
##Function to configure the Repo##
##################################
configureRepo() {
local NSOLID_VERSION=$1
# Run 'yum install'
if ! yum install https://rpm.nodesource.com/pub_$NSOLID_VERSION.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y; then
handleError "$?" "Failed to run yum install https://rpm.nodesource.com/pub_$NSOLID_VERSION.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y"
fi
}

getVersion $NSOLID_VERSION || handleError $? "Must define a valid N|solid version"
configureRepo $NSOLID_VERSION || handleError $? "Failed configuring repository"

2 comments on commit 4f746d9

@Farmacos76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A

@Farmacos76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LL

Please sign in to comment.