Skip to content

Commit

Permalink
Modified the automated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Coder-Harshit committed Sep 13, 2024
1 parent 02e4182 commit 30d2800
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
26 changes: 23 additions & 3 deletions install_ospect.bat
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ if /I not "%confirmation%" == "y" (
:: Check for Rust and Cargo
if not exist "%USERPROFILE%\.cargo\bin\rustc.exe" (
echo Rust is not installed. Installing Rust...
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
curl -sSf https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe -o rustup-init.exe
rustup-init.exe -y
del rustup-init.exe
)

:: Download OSpect pre-built binary (if available) or build from source
Expand All @@ -27,6 +29,7 @@ curl --head --silent --fail https://raw.githubusercontent.com/Coder-Harshit/OSpe
if %errorlevel% == 0 (
echo Downloading pre-built OSpect...
curl -O https://raw.githubusercontent.com/Coder-Harshit/OSpect/main/releases/ospect.exe
curl -O https://raw.githubusercontent.com/Coder-Harshit/OSpect/main/sample_config.toml
) else (
echo Pre-built binary not found. Building OSpect from source...
:: Assuming your OSpect source code is in the current directory
Expand All @@ -49,14 +52,31 @@ if not exist ospect.exe (
:: Install OSpect for the user
echo Adding OSpect to your user's PATH...
set user_bin_dir=%USERPROFILE%\bin
set config_dir=%USERPROFILE%\Appdata\Roaming\ospect
if not exist "%user_bin_dir%" (
echo Creating %user_bin_dir% directory...
mkdir "%user_bin_dir%"
)
move ospect.exe "%user_bin_dir%"
ren sample_config.toml config.toml
if not exist "%config_dir%" (
echo Creating %config_dir% directory...
mkdir "%config_dir%"
)
move config.toml "%config_dir%"

:: Update PATH variable using Windows environment variables
setx PATH "%user_bin_dir%;%PATH%"
for /f "tokens=1,* delims=;" %%a in ("%PATH%") do (
if "%%a" neq "%user_bin_dir%" (
setx PATH "%user_bin_dir%;%PATH%"
)
)

:: Cleanup
cd ..
if exist OSpect (
rmdir /s /q OSpect
)

echo OSpect installation complete for your user!
echo Restart your terminalfor the changes to take effect.
echo Restart your terminalfor the changes to take effect.
32 changes: 30 additions & 2 deletions install_ospect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if curl --output /dev/null --silent --head --fail "https://raw.githubusercontent
# Download pre-built binary (adjust URL if necessary)
echo "Downloading pre-built OSpect..."
curl -O https://raw.githubusercontent.com/Coder-Harshit/OSpect/main/releases/ospect
curl -O https://raw.githubusercontent.com/Coder-Harshit/OSpect/main/sample_config.toml
else
echo "Pre-built binary not found. Building OSpect from source..."
# Assuming your OSpect source code is in the current directory
Expand All @@ -47,30 +48,57 @@ fi
# Install OSpect for the user
echo "Adding OSpect to your user's PATH..."
user_bin_dir="$HOME/bin"
ospect_config_dir="$HOME/.config/ospect"
if [[ ! -d "$user_bin_dir" ]]; then
echo "Creating $user_bin_dir directory..."
mkdir -p "$user_bin_dir"
fi
mv ospect "$user_bin_dir"

if [[ ! -d "$ospect_config_dir" ]]; then
echo "Creating $ospect_config_dir directory..."
mkdir -p "$ospect_config_dir"
fi
mv sample_config.toml "$ospect_config_dir/config.toml"

# Update shell configuration file (handle different shells gracefully)
shell_config_file=""
if [[ -f ~/.bashrc ]]; then
shell_config_file=~/.bashrc
elif [[ -f ~/.zshrc ]]; then
shell_config_file=~/.zshrc
# Add line for zsh (adjust if necessary)
echo 'export PATH="$HOME/bin:$PATH"' >> "$shell_config_file"
else
echo "Warning: Could not find a compatible shell configuration file."
echo "You may need to manually add 'export PATH=\"$HOME/bin:$PATH\"' to your shell configuration file (e.g., ~/.bashrc or ~/.zshrc)."
fi


# Add PATH to the shell configuration file if not already present
if [[ -n "$shell_config_file" ]]; then
if ! grep -q 'export PATH="$HOME/bin:$PATH"' "$shell_config_file"; then
echo 'export PATH="$HOME/bin:$PATH"' >> "$shell_config_file"
echo "Updated $shell_config_file to include $HOME/bin in PATH."
# Source the shell configuration file
echo "Sourcing $shell_config_file..."
source "$shell_config_file"
else
echo "$shell_config_file already includes $HOME/bin in PATH."
fi
fi


# Source the shell configuration file (if applicable)
if [[ ! -z "$shell_config_file" ]]; then
echo "Sourcing $shell_config_file..."
source "$shell_config_file"
fi

# Cleanup
cd ..
if [[ -d OSpect ]]; then
rm -rf OSpect
fi


echo "OSpect installation complete for your user!"
echo "Restart your terminal or run 'source ~/.bashrc' (or your shell's equivalent) for the changes to take effect."

0 comments on commit 30d2800

Please sign in to comment.