Skip to content

Commit

Permalink
add new scripts in rpm and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusPaz committed Dec 26, 2023
1 parent 4f746d9 commit 3a72e98
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 19 deletions.
17 changes: 0 additions & 17 deletions .github/ISSUE_TEMPLATE/distribution-support-request.md

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Test Installation Scripts'
name: "Test Installation Scripts"

on:
push:
Expand Down Expand Up @@ -81,4 +81,4 @@ jobs:
if [[ ${NODE_VERSION} != "v${{ matrix.version }}" ]]; then
echo "Node version is not ${{ matrix.version }}. It is $NODE_VERSION"
exit 1
fi
fi
File renamed without changes.
40 changes: 40 additions & 0 deletions scripts/rpm/script_generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Node.js Version Setup Scripts

This repository contains scripts for setting up different versions of Node.js on RPM-based Linux systems.

## Modifying the Scripts

Each script in this repository sets up a specific version of Node.js. The version is specified in the line `NODE_VERSION="XX.x"` in each script. To modify the version, simply replace `"XX.x"` with the desired version, e.g., `"18.x"`.

For example, to modify the `setup_18.x` script to install Node.js version 20.x instead, you would change the line to `NODE_VERSION="20.x"`.

## Running the Scripts

To run a script, navigate to the directory containing the script and run the following command:

```bash
sudo bash setup_XX.x
```

Replace `XX.x` with the version number of the script you want to run. For example, to run the `setup_18.x` script, you would use the command `sudo bash setup_18.x`.

## How It Works

Each script in this repository performs the following steps:

1. Checks if the system is an RPM-based Linux distribution.
2. Configures the NodeSource Node.js RPM repository for the specified version of Node.js.
3. Checks if `dnf` or `yum` is available and updates the system using the available package manager.
4. Logs a message indicating that the repository is configured and updated, and instructs the user to run `dnf install nodejs -y` or `yum install nodejs -y` to complete the installation.

The `setup_current` and `setup_latest` scripts are special scripts that install the current and latest versions of Node.js, respectively. The current version is 20.x and the latest version is 21.x.

## Updating the Scripts

If you make a change to the base script, you can regenerate all the version-specific scripts by running the generator script:

```bash
bash generator.sh
```

This script iterates over a list of versions (currently 18.x, 20.x, and 21.x), and creates a new script for each version with the updated base script. It also creates setup_current and setup_latest scripts for the current and latest versions of Node.js, respectively.
75 changes: 75 additions & 0 deletions scripts/rpm/script_generator/base_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Logger Function
log() {
local message="$1"
local type="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local color
local endcolor="\033[0m"

case "$type" in
"info") color="\033[38;5;79m" ;;
"success") color="\033[1;32m" ;;
"error") color="\033[1;31m" ;;
*) color="\033[1;34m" ;;
esac

echo -e "${color}${timestamp} - ${message}${endcolor}"
}

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

# Function to check for command availability
command_exists() {
command -v "$1" &> /dev/null
}

# Check if we are on an RPM-based system
if ! [ -f /etc/redhat-release ] && ! grep -q "Amazon Linux" /etc/system-release 2>/dev/null; then
handle_error 1 "This script is intended for RPM-based systems. Please run it on an RPM-based system."
fi

# Define Node.js version
NODE_VERSION="XX.x"

# Get system architecture
SYS_ARCH=$(uname -m)

# Validate system architecture
case "$SYS_ARCH" in
aarch64|x86_64) log "Supported architecture: $SYS_ARCH" "info" ;;
*) handle_error 1 "Unsupported architecture: $SYS_ARCH. Only aarch64 and x86_64 are supported." ;;
esac

# Repository content
REPO_CONTENT="[nodesource-nodejs]
name=Node.js Packages for Linux RPM based distros - $SYS_ARCH
baseurl=https://rpm.nodesource.com/pub_${NODE_VERSION}/nodistro/nodejs/$SYS_ARCH
priority=9
enabled=1
gpgcheck=1
gpgkey=https://rpm.nodesource.com/gpgkey/ns-operations-public.key
module_hotfixes=1"

echo "$REPO_CONTENT" | tee /etc/yum.repos.d/nodesource-nodistro.repo > /dev/null

# Check for availability of dnf or yum
if command_exists dnf; then
log "dnf available, updating..." "info"
dnf update -y
log "Repository is configured and updated. Run 'dnf install nodejs -y' to complete the installation." "info"
exit 0
elif command_exists yum; then
log "yum available, updating..." "info"
yum update -y
log "Repository is configured and updated. Run 'yum install nodejs -y' to complete the installation." "info"
else
handle_error 1 "Neither yum nor dnf package manager was found. Please update your system using your package manager."
fi
39 changes: 39 additions & 0 deletions scripts/rpm/script_generator/generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Function to create a script for a given Node.js version
create_script() {
local version=$1
local script_name=$2
local target_script="../setup_$script_name.x"

echo "Creating script for Node.js version $version.x"
if sed "s/NODE_VERSION=\"XX.x\"/NODE_VERSION=\"$version.x\"/g" "$base_script" > "$target_script"; then
echo "Script created successfully: $target_script"
else
echo "Error: Failed to create script for version $version.x"
return 1
fi
}

# Check if the base script exists
base_script="./base_script.sh"
if [ ! -f "$base_script" ]; then
echo "Error: Base script not found at $base_script"
exit 1
fi

# List of versions
versions=("18" "20" "21")

# Iterate over the versions and create scripts
for version in "${versions[@]}"; do
create_script "$version" "$version"
done

# Define LTS and current Node.js versions
lts_version="20"
current_version="21"

# Create setup_lts and setup_current scripts
create_script "$lts_version" "lts"
create_script "$current_version" "current"
75 changes: 75 additions & 0 deletions scripts/rpm/setup_18.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Logger Function
log() {
local message="$1"
local type="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local color
local endcolor="\033[0m"

case "$type" in
"info") color="\033[38;5;79m" ;;
"success") color="\033[1;32m" ;;
"error") color="\033[1;31m" ;;
*) color="\033[1;34m" ;;
esac

echo -e "${color}${timestamp} - ${message}${endcolor}"
}

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

# Function to check for command availability
command_exists() {
command -v "$1" &> /dev/null
}

# Check if we are on an RPM-based system
if ! [ -f /etc/redhat-release ] && ! grep -q "Amazon Linux" /etc/system-release 2>/dev/null; then
handle_error 1 "This script is intended for RPM-based systems. Please run it on an RPM-based system."
fi

# Define Node.js version
NODE_VERSION="18.x"

# Get system architecture
SYS_ARCH=$(uname -m)

# Validate system architecture
case "$SYS_ARCH" in
aarch64|x86_64) log "Supported architecture: $SYS_ARCH" "info" ;;
*) handle_error 1 "Unsupported architecture: $SYS_ARCH. Only aarch64 and x86_64 are supported." ;;
esac

# Repository content
REPO_CONTENT="[nodesource-nodejs]
name=Node.js Packages for Linux RPM based distros - $SYS_ARCH
baseurl=https://rpm.nodesource.com/pub_${NODE_VERSION}/nodistro/nodejs/$SYS_ARCH
priority=9
enabled=1
gpgcheck=1
gpgkey=https://rpm.nodesource.com/gpgkey/ns-operations-public.key
module_hotfixes=1"

echo "$REPO_CONTENT" | tee /etc/yum.repos.d/nodesource-nodistro.repo > /dev/null

# Check for availability of dnf or yum
if command_exists dnf; then
log "dnf available, updating..." "info"
dnf update -y
log "Repository is configured and updated. Run 'dnf install nodejs -y' to complete the installation." "info"
exit 0
elif command_exists yum; then
log "yum available, updating..." "info"
yum update -y
log "Repository is configured and updated. Run 'yum install nodejs -y' to complete the installation." "info"
else
handle_error 1 "Neither yum nor dnf package manager was found. Please update your system using your package manager."
fi
75 changes: 75 additions & 0 deletions scripts/rpm/setup_20.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# Logger Function
log() {
local message="$1"
local type="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local color
local endcolor="\033[0m"

case "$type" in
"info") color="\033[38;5;79m" ;;
"success") color="\033[1;32m" ;;
"error") color="\033[1;31m" ;;
*) color="\033[1;34m" ;;
esac

echo -e "${color}${timestamp} - ${message}${endcolor}"
}

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

# Function to check for command availability
command_exists() {
command -v "$1" &> /dev/null
}

# Check if we are on an RPM-based system
if ! [ -f /etc/redhat-release ] && ! grep -q "Amazon Linux" /etc/system-release 2>/dev/null; then
handle_error 1 "This script is intended for RPM-based systems. Please run it on an RPM-based system."
fi

# Define Node.js version
NODE_VERSION="20.x"

# Get system architecture
SYS_ARCH=$(uname -m)

# Validate system architecture
case "$SYS_ARCH" in
aarch64|x86_64) log "Supported architecture: $SYS_ARCH" "info" ;;
*) handle_error 1 "Unsupported architecture: $SYS_ARCH. Only aarch64 and x86_64 are supported." ;;
esac

# Repository content
REPO_CONTENT="[nodesource-nodejs]
name=Node.js Packages for Linux RPM based distros - $SYS_ARCH
baseurl=https://rpm.nodesource.com/pub_${NODE_VERSION}/nodistro/nodejs/$SYS_ARCH
priority=9
enabled=1
gpgcheck=1
gpgkey=https://rpm.nodesource.com/gpgkey/ns-operations-public.key
module_hotfixes=1"

echo "$REPO_CONTENT" | tee /etc/yum.repos.d/nodesource-nodistro.repo > /dev/null

# Check for availability of dnf or yum
if command_exists dnf; then
log "dnf available, updating..." "info"
dnf update -y
log "Repository is configured and updated. Run 'dnf install nodejs -y' to complete the installation." "info"
exit 0
elif command_exists yum; then
log "yum available, updating..." "info"
yum update -y
log "Repository is configured and updated. Run 'yum install nodejs -y' to complete the installation." "info"
else
handle_error 1 "Neither yum nor dnf package manager was found. Please update your system using your package manager."
fi
Loading

0 comments on commit 3a72e98

Please sign in to comment.