forked from nodesource/distributions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
531 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.