Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit e0cef1e

Browse files
authored
Addition of New install.sh for linux, macos and install.bat for windows (#134)
* Add bashscript install nitro for linux and macos * Add suggest install necessary dependencies * Add color for suggestion command install jq and unzip * add install.bat for windows * rename uninstall.bat to uninstallnitro.bat --------- Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent ba28108 commit e0cef1e

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

install.bat

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@echo off
2+
setlocal
3+
4+
:: Remove existing nitro directory if it exists
5+
if exist "%APPDATA%\nitro" (
6+
echo Removing existing Nitro installation...
7+
rmdir /S /Q "%APPDATA%\nitro"
8+
)
9+
10+
11+
:: Parse arguments
12+
set "VERSION=latest"
13+
set "GPU=false"
14+
:arg_loop
15+
if "%~1"=="" goto arg_loop_end
16+
if "%~1"=="--gpu" (
17+
set "GPU=true"
18+
shift
19+
goto arg_loop
20+
)
21+
if "%~1"=="--version" (
22+
set "VERSION=%~2"
23+
shift
24+
shift
25+
goto arg_loop
26+
)
27+
shift
28+
goto arg_loop
29+
:arg_loop_end
30+
31+
echo %VERSION%
32+
33+
:: Get the release
34+
if "%VERSION%"=="latest" (
35+
:: If the version is set to "latest", get the latest version number from the Nitro GitHub repository
36+
for /f "delims=" %%i in ('powershell -Command "& {$version = Invoke-RestMethod -Uri 'https://api.github.com/repos/janhq/nitro/releases/latest'; return $version.tag_name.TrimStart('v')}"') do set "VERSION=%%i"
37+
)
38+
39+
:: Construct the download URL
40+
set "URL=https://github.com/janhq/nitro/releases/download/v%VERSION%/nitro-%VERSION%-win-amd64"
41+
if "%GPU%"=="true" (
42+
:: If --gpu option is provided, append -cuda to the URL
43+
set "URL=%URL%-cuda"
44+
)
45+
set "URL=%URL%.zip"
46+
47+
:: Download and extract nitro
48+
echo Downloading Nitro from: %URL%
49+
powershell -Command "Invoke-WebRequest -OutFile '%TEMP%\nitro.zip' '%URL%'"
50+
echo Extracting Nitro...
51+
powershell -Command "Expand-Archive -Path '%TEMP%\nitro.zip' -DestinationPath '%APPDATA%\nitro'"
52+
53+
:: Add nitro to the PATH
54+
setx PATH "%APPDATA%\nitro;%PATH%"
55+
56+
:: Create uninstallnitro.bat
57+
echo @echo off > "%APPDATA%\nitro\uninstallnitro.bat"
58+
echo setx PATH "%PATH:;%APPDATA%\nitro=;%"" >> "%APPDATA%\nitro\uninstallnitro.bat"
59+
echo rmdir /S /Q "%APPDATA%\nitro" >> "%APPDATA%\nitro\uninstallnitro.bat"
60+
61+
:: Clean up
62+
del %TEMP%\nitro.zip
63+
64+
endlocal

install.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/bin/bash
2+
3+
# Check for root privileges
4+
if [ "$(id -u)" != "0" ]; then
5+
echo "This script must be run as root. Please run again with sudo."
6+
exit 1
7+
fi
8+
9+
# Check and suggest installing jq and unzip if not present
10+
check_install_jq_unzip() {
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
NC='\033[0m' # No Color
14+
15+
if ! command -v jq &> /dev/null; then
16+
echo -e "${RED}jq could not be found ...${NC}"
17+
if [[ "$OS" == "Linux" ]]; then
18+
echo -e "${GREEN}Please run the command below to install jq then rerun this script${NC}"
19+
echo "$ sudo apt-get install jq"
20+
exit 1
21+
elif [[ "$OS" == "Darwin" ]]; then
22+
echo -e "${GREEN}Please run the command below to install jq then rerun this script${NC}"
23+
echo "$ brew install jq"
24+
exit 1
25+
fi
26+
fi
27+
28+
if ! command -v unzip &> /dev/null; then
29+
echo -e "${RED}unzip could not be found ...${NC}"
30+
if [[ "$OS" == "Linux" ]]; then
31+
echo -e "${GREEN}Please run the command below to install unzip then rerun this script${NC}"
32+
echo "$ sudo apt-get install unzip"
33+
exit 1
34+
elif [[ "$OS" == "Darwin" ]]; then
35+
echo -e "${GREEN}Please run the command below to install unzip then rerun this script${NC}"
36+
echo "$ brew install unzip"
37+
exit 1
38+
fi
39+
fi
40+
}
41+
42+
# Function to download and install nitro
43+
install_nitro() {
44+
rm -rf /tmp/nitro
45+
rm /tmp/nitro.zip
46+
echo "Downloading Nitro version $VERSION... from $1"
47+
curl -sL "$1" -o /tmp/nitro.zip
48+
unzip /tmp/nitro.zip -d /tmp
49+
ls /tmp/nitro
50+
51+
# Copying files to /usr/local/bin
52+
for file in /tmp/nitro/*; do
53+
chmod +x "$file"
54+
cp "$file" /usr/local/bin/
55+
done
56+
}
57+
58+
# Function to create uninstall script
59+
create_uninstall_script() {
60+
echo '#!/bin/bash' > /tmp/uninstall_nitro.sh
61+
echo 'if [ "$(id -u)" != "0" ]; then' >> /tmp/uninstall_nitro.sh
62+
echo ' echo "This script must be run as root. Please run again with sudo."' >> /tmp/uninstall_nitro.sh
63+
echo ' exit 1' >> /tmp/uninstall_nitro.sh
64+
echo 'fi' >> /tmp/uninstall_nitro.sh
65+
for file in /tmp/nitro/*; do
66+
echo "rm /usr/local/bin/$(basename "$file")" >> /tmp/uninstall_nitro.sh
67+
done
68+
echo "rm /usr/local/bin/uninstall_nitro.sh" >> /tmp/uninstall_nitro.sh
69+
echo 'echo "Nitro remove successfully."' >> /tmp/uninstall_nitro.sh
70+
chmod +x /tmp/uninstall_nitro.sh
71+
mv /tmp/uninstall_nitro.sh /usr/local/bin/
72+
}
73+
74+
# Determine OS and architecture
75+
OS=$(uname -s)
76+
ARCH=$(uname -m)
77+
VERSION="latest"
78+
GPU=""
79+
80+
check_install_jq_unzip
81+
82+
# Parse arguments
83+
for arg in "$@"
84+
do
85+
case $arg in
86+
--gpu)
87+
GPU="-cuda"
88+
shift
89+
;;
90+
--version)
91+
VERSION="$2"
92+
shift
93+
shift
94+
;;
95+
esac
96+
done
97+
98+
# Notify if GPU option is not supported
99+
if [ "$GPU" == "-cuda" ] && [ "$OS" == "Darwin" ]; then
100+
echo "GPU option is only supported on Linux or Windows."
101+
exit 1
102+
fi
103+
104+
# Construct GitHub API URL and get latest version if not specified
105+
if [ "$VERSION" == "latest" ]; then
106+
API_URL="https://api.github.com/repos/janhq/nitro/releases/latest"
107+
VERSION=$(curl -s $API_URL | jq -r ".tag_name" | sed 's/^v//')
108+
fi
109+
110+
# Check if version is empty
111+
if [ -z "$VERSION" ]; then
112+
echo "Failed to fetch latest version."
113+
exit 1
114+
fi
115+
116+
# Construct download URL based on OS, ARCH, GPU and VERSION
117+
case $OS in
118+
Linux)
119+
FILE_NAME="nitro-${VERSION}-linux-amd64${GPU}.zip"
120+
;;
121+
Darwin)
122+
ARCH_FORMAT=$( [[ "$ARCH" == "arm64" ]] && echo "mac-arm64" || echo "mac-amd64")
123+
FILE_NAME="nitro-${VERSION}-${ARCH_FORMAT}.zip"
124+
;;
125+
*)
126+
echo "Unsupported OS."
127+
exit 1
128+
;;
129+
esac
130+
131+
DOWNLOAD_URL="https://github.com/janhq/nitro/releases/download/v${VERSION}/${FILE_NAME}"
132+
133+
# Download, install, and create uninstall script
134+
install_nitro "$DOWNLOAD_URL"
135+
create_uninstall_script
136+
137+
echo "Nitro installed successfully."

0 commit comments

Comments
 (0)