Skip to content

Commit

Permalink
Release nvml version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Watchdog0x committed Oct 25, 2023
1 parent 0016592 commit 06d5225
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions nvml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

script_version="1.1.0"

# Get the directory of the script, resolving symbolic links
script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"

Expand All @@ -10,6 +12,17 @@ install_version=""
set_version=""
remove_version=""

if [ ! -d "$node_versions_dir" ]; then
if [ -w "$script_dir" ]; then
mkdir "$node_versions_dir"
else
echo "Error: Permission Denied"
echo "You don't have the necessary permissions to create the 'nodejs' directory in $script_dir."
echo "Please run the command with sudo: sudo nvml"
exit 1
fi
fi

check_node_version(){
if [ -n "$(command -v node)" ]; then
current_version=$(node --version | grep -oP '\d.*')
Expand All @@ -18,6 +31,8 @@ check_node_version(){

print_help() {
cat <<EOF
nvml - Node Version Manager Lite (Version $script_version)
Usage: nvml [OPTIONS]
Options:
Expand All @@ -33,11 +48,17 @@ Options:
-r, --remove Remove an installed Node.js version
-v, --version Print the version of nvml
-h, --help Display this help message and exit
EOF
}

print_version() {
echo "nvml - Node Version Manager Lite (Version $script_version)"
}

install() {
if [ -e "$node_versions_dir/$install_version" ]; then
echo "Node.js version $install_version is already installed on your system."
Expand All @@ -49,7 +70,7 @@ install() {
if [ $? -eq 0 ]; then
echo "Node.js version $install_version downloaded successfully to $node_versions_dir"

mkdir -p "$node_versions_dir/$install_version"
mkdir "$node_versions_dir/$install_version"

tar -xf "$node_versions_dir/node-v$install_version-linux-x64.tar.xz" -C "$node_versions_dir/$install_version" --strip-components=1

Expand Down Expand Up @@ -96,7 +117,7 @@ set_nodejs(){
ln -srf "$node_versions_dir/$set_version/bin/node" /usr/bin/node
ln -srf "$node_versions_dir/$set_version/bin/npx" /usr/bin/npx
ln -srf "$node_versions_dir/$set_version/bin/npm" /usr/bin/npm
npm config set prefix /usr/local
npm config set prefix /usr/local -g
echo "Node.js version $set_version has been set successfully."
else
echo "Error: Insufficient privileges. Please run with sudo."
Expand Down Expand Up @@ -241,6 +262,10 @@ while [[ $# -gt 0 ]]; do
exit 2
fi
;;
-v|--version)
print_version
exit 0
;;
-h|--help)
print_help
exit 0
Expand Down

0 comments on commit 06d5225

Please sign in to comment.