Merge commit '3b916f1cdfebe223517290fbecc4a0df5936fb39' as 'nodesource'

This commit is contained in:
Andrew
2025-05-07 20:41:48 -04:00
34 changed files with 5328 additions and 0 deletions
@@ -0,0 +1,49 @@
# Node.js Version Setup Scripts
This repository contains scripts for setting up different versions of Node.js on Debian 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 Debian based Linux distribution.
2. Configures the NodeSource Node.js DEB repository for the specified version of Node.js.
3. Logs a message indicating that the repository is configured and updated, and instructs the user to run `apt-get 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.
## Deploying the Scripts
After generating the scripts, you can deploy them to an S3 bucket using the AWS CLI. Here is the command to do so:
```bash
aws s3 sync scripts/deb/ s3://deb.nodesource.com/ --exclude "*/**"
```
This command syncs all the files in the scripts/deb/ directory (but not its subdirectories) with the s3://deb.nodesource.com/ bucket. Make sure to replace s3://deb.nodesource.com/ with the path to your own S3 bucket.
@@ -0,0 +1,113 @@
#!/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_os() {
if ! [ -f "/etc/debian_version" ]; then
echo "Error: This script is only supported on Debian-based systems."
exit 1
fi
}
# Function to Install the script pre-requisites
install_pre_reqs() {
log "Installing pre-requisites" "info"
# Run 'apt-get update'
if ! apt-get update -y; then
handle_error "$?" "Failed to run 'apt-get update'"
fi
# Run 'apt-get install'
if ! apt-get install -y apt-transport-https ca-certificates curl gnupg; then
handle_error "$?" "Failed to install packages"
fi
if ! mkdir -p /usr/share/keyrings; then
handle_error "$?" "Makes sure the path /usr/share/keyrings exist or run ' mkdir -p /usr/share/keyrings' with sudo"
fi
rm -f /usr/share/keyrings/nodesource.gpg || true
rm -f /etc/apt/sources.list.d/nodesource.list || true
# Run 'curl' and 'gpg' to download and import the NodeSource signing key
if ! curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /usr/share/keyrings/nodesource.gpg; then
handle_error "$?" "Failed to download and import the NodeSource signing key"
fi
# Explicitly set the permissions to ensure the file is readable by all
if ! chmod 644 /usr/share/keyrings/nodesource.gpg; then
handle_error "$?" "Failed to set correct permissions on /usr/share/keyrings/nodesource.gpg"
fi
}
# Function to configure the Repo
configure_repo() {
local node_version=$1
arch=$(dpkg --print-architecture)
if [ "$arch" != "amd64" ] && [ "$arch" != "arm64" ] && [ "$arch" != "armhf" ]; then
handle_error "1" "Unsupported architecture: $arch. Only amd64, arm64, and armhf are supported."
fi
echo "deb [arch=$arch signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$node_version nodistro main" | tee /etc/apt/sources.list.d/nodesource.list > /dev/null
# N|solid Config
echo "Package: nsolid" | tee /etc/apt/preferences.d/nsolid > /dev/null
echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nsolid > /dev/null
echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nsolid > /dev/null
# Nodejs Config
echo "Package: nodejs" | tee /etc/apt/preferences.d/nodejs > /dev/null
echo "Pin: origin deb.nodesource.com" | tee -a /etc/apt/preferences.d/nodejs > /dev/null
echo "Pin-Priority: 600" | tee -a /etc/apt/preferences.d/nodejs > /dev/null
# Run 'apt-get update'
if ! apt-get update -y; then
handle_error "$?" "Failed to run 'apt-get update'"
else
log "Repository configured successfully."
log "To install Node.js, run: apt-get install nodejs -y" "info"
log "You can use N|solid Runtime as a node.js alternative" "info"
log "To install N|solid Runtime, run: apt-get install nsolid -y \n" "success"
fi
}
# Define Node.js version
NODE_VERSION="XX.x"
# Check OS
check_os
# Main execution
install_pre_reqs || handle_error $? "Failed installing pre-requisites"
configure_repo "$NODE_VERSION" || handle_error $? "Failed configuring repository"
@@ -0,0 +1,41 @@
#!/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"
chmod +x "$target_script"
echo "Execute permissions set for: $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" "22" "23" "24")
# 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="22"
current_version="24"
# Create setup_lts and setup_current scripts
create_script "$lts_version" "lts"
create_script "$current_version" "current"