Inital Commit
This commit is contained in:
69
README.md
Normal file
69
README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# PSn00bSDK Manager Scripts
|
||||
|
||||
Automated installer scripts for PSn00bSDK that handle installation, uninstallation, and update checking.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Linux/macOS
|
||||
```bash
|
||||
chmod +x psn00bsdk_manager.sh
|
||||
./psn00bsdk_manager.sh
|
||||
```
|
||||
|
||||
### Windows
|
||||
```cmd
|
||||
psn00bsdk_manager.bat
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Install/Uninstall PSn00bSDK
|
||||
- Check for updates via GitHub API
|
||||
- Automatic environment setup
|
||||
- Interactive menu interface
|
||||
- Cross-platform support
|
||||
|
||||
## Requirements
|
||||
|
||||
**Linux/macOS**: CMake 3.21+, wget, unzip, curl, jq, sudo
|
||||
|
||||
**Windows**: Windows 7+, PowerShell, internet connection
|
||||
|
||||
## Default Paths
|
||||
|
||||
- Linux/macOS: `/opt/psn00bsdk`
|
||||
- Windows: `C:\psn00bsdk`
|
||||
|
||||
## Menu
|
||||
|
||||
```
|
||||
1) Install PSn00bSDK - Download and install
|
||||
2) Uninstall PSn00bSDK - Remove installation
|
||||
3) Check for updates - Compare with GitHub releases
|
||||
4) Exit - Quit script
|
||||
```
|
||||
|
||||
## Platform Details
|
||||
|
||||
| | Linux/macOS | Windows |
|
||||
|---|-------------|---------|
|
||||
| **Script** | `.sh` | `.bat` |
|
||||
| **Download** | `*-Linux.zip` | `*-win32.zip` |
|
||||
| **Environment** | Shell profile | Registry |
|
||||
| **Tools** | curl + jq | PowerShell |
|
||||
|
||||
## After Installation
|
||||
|
||||
**Linux/macOS**: `source ~/.bashrc`
|
||||
|
||||
**Windows**: Restart Command Prompt or computer
|
||||
|
||||
Verify:
|
||||
```bash
|
||||
mipsel-none-elf-gcc --version
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [PSn00bSDK Repository](https://github.com/Lameguy64/PSn00bSDK)
|
||||
- [Releases](https://github.com/Lameguy64/PSn00bSDK/releases)
|
||||
371
psn00bsdk_manager.bat
Normal file
371
psn00bsdk_manager.bat
Normal file
@@ -0,0 +1,371 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set GITHUB_API=https://api.github.com/repos/Lameguy64/PSn00bSDK/releases/latest
|
||||
set GITHUB_RELEASES=https://github.com/Lameguy64/PSn00bSDK/releases
|
||||
set DEFAULT_INSTALL_DIR=C:\psn00bsdk
|
||||
set VERSION_FILE=.version
|
||||
|
||||
:main
|
||||
cls
|
||||
echo ==========================================
|
||||
echo PSn00bSDK Manager (Windows)
|
||||
echo ==========================================
|
||||
echo.
|
||||
echo Please select an action:
|
||||
echo.
|
||||
echo 1) Install PSn00bSDK
|
||||
echo 2) Uninstall PSn00bSDK
|
||||
echo 3) Check for updates
|
||||
echo 4) Exit
|
||||
echo.
|
||||
|
||||
set /p choice="Enter your choice [1-4]: "
|
||||
echo.
|
||||
|
||||
if "%choice%"=="1" goto install
|
||||
if "%choice%"=="2" goto uninstall
|
||||
if "%choice%"=="3" goto check_updates
|
||||
if "%choice%"=="4" goto exit_script
|
||||
|
||||
echo [ERROR] Invalid choice. Please enter a number between 1 and 4.
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
|
||||
:install
|
||||
echo.
|
||||
set /p version="Enter version to install (leave blank for latest, e.g., 0.24): "
|
||||
echo.
|
||||
set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: "
|
||||
if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR%
|
||||
|
||||
if defined version (
|
||||
set version_clean=%version%
|
||||
echo [INFO] Installing version: %version_clean%
|
||||
) else (
|
||||
call :get_latest_version latest_version
|
||||
if !latest_version!==FAILED (
|
||||
echo [ERROR] Failed to get latest version from GitHub
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
)
|
||||
set version_clean=!latest_version:~1!
|
||||
echo [INFO] Installing latest version: !version_clean!
|
||||
)
|
||||
|
||||
call :install_sdk %install_dir% %version_clean%
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
)
|
||||
|
||||
call :setup_environment %install_dir%
|
||||
call :verify_installation %install_dir%
|
||||
call :print_post_install %install_dir%
|
||||
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
|
||||
:uninstall
|
||||
echo.
|
||||
set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: "
|
||||
if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR%
|
||||
|
||||
call :uninstall_sdk %install_dir%
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
)
|
||||
|
||||
call :remove_environment
|
||||
echo.
|
||||
echo [INFO] Uninstallation complete!
|
||||
echo [INFO] Please restart your terminal for environment changes to take effect
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
|
||||
:check_updates
|
||||
echo.
|
||||
set /p install_dir="Enter installation directory [%DEFAULT_INSTALL_DIR%]: "
|
||||
if "%install_dir%"=="" set install_dir=%DEFAULT_INSTALL_DIR%
|
||||
|
||||
if not exist "%install_dir%" (
|
||||
echo [WARN] PSn00bSDK is not installed in: %install_dir%
|
||||
set /p install_dir="Enter installation directory: "
|
||||
if not exist "%install_dir%" (
|
||||
echo [ERROR] Directory not found: %install_dir%
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
)
|
||||
)
|
||||
|
||||
echo [INFO] Checking for latest release from GitHub...
|
||||
|
||||
set installed_version=
|
||||
if exist "%install_dir%\%VERSION_FILE%" (
|
||||
set /p installed_version=<"%install_dir%\%VERSION_FILE%"
|
||||
)
|
||||
|
||||
call :get_latest_version latest_version
|
||||
if !latest_version!==FAILED (
|
||||
echo [ERROR] Failed to get latest version from GitHub
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
)
|
||||
|
||||
set latest_version_num=!latest_version:~1!
|
||||
|
||||
echo.
|
||||
echo ==========================================
|
||||
echo Version Check Results
|
||||
echo ==========================================
|
||||
echo.
|
||||
if defined installed_version (
|
||||
echo Installed version: %installed_version%
|
||||
) else (
|
||||
echo Installed version: Not detected
|
||||
)
|
||||
echo Latest version: !latest_version_num!
|
||||
echo.
|
||||
|
||||
if "%installed_version%"=="!latest_version_num!" (
|
||||
echo [INFO] You are running the latest version!
|
||||
) else if not defined installed_version (
|
||||
echo [WARN] Could not detect installed version
|
||||
) else (
|
||||
echo [INFO] A newer version is available!
|
||||
echo.
|
||||
echo Download the latest version from:
|
||||
echo %GITHUB_RELEASES%
|
||||
)
|
||||
|
||||
echo ==========================================
|
||||
echo.
|
||||
pause
|
||||
goto main
|
||||
|
||||
:get_latest_version
|
||||
setlocal
|
||||
set latest_version=FAILED
|
||||
|
||||
for /f "delims=" %%i in ('powershell -Command "& {$response = Invoke-WebRequest -Uri '%GITHUB_API%' -UseBasicParsing; $tag = ($response.Content ^| ConvertFrom-Json).tag_name; Write-Host $tag}" 2^>nul') do (
|
||||
set latest_version=%%i
|
||||
)
|
||||
|
||||
if defined latest_version (
|
||||
endlocal & set %~1=%latest_version%
|
||||
) else (
|
||||
endlocal & set %~1=FAILED
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:install_sdk
|
||||
set install_dir=%~1
|
||||
set version=%~2
|
||||
|
||||
if exist "%install_dir%" (
|
||||
echo [WARN] Installation directory already exists: %install_dir%
|
||||
set /p confirm="Do you want to overwrite it? (y/N): "
|
||||
if /i not "%confirm%"=="y" (
|
||||
echo [ERROR] Installation cancelled.
|
||||
exit /b 1
|
||||
)
|
||||
rmdir /s /q "%install_dir%"
|
||||
)
|
||||
|
||||
set file_name=PSn00bSDK-%version%-win32.zip
|
||||
set download_url=https://github.com/Lameguy64/PSn00bSDK/releases/download/v%version%/%file_name%
|
||||
set temp_dir=%TEMP%\psn00bsdk_temp
|
||||
|
||||
if exist "%temp_dir%" rmdir /s /q "%temp_dir%"
|
||||
mkdir "%temp_dir%"
|
||||
|
||||
echo [INFO] Downloading PSn00bSDK v%version% (Windows)...
|
||||
echo [INFO] URL: %download_url%
|
||||
|
||||
powershell -Command "Invoke-WebRequest -Uri '%download_url%' -OutFile '%temp_dir%\%file_name%'" 2>nul
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Failed to download PSn00bSDK
|
||||
rmdir /s /q "%temp_dir%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] Extracting SDK to temporary directory...
|
||||
powershell -Command "Expand-Archive -Path '%temp_dir%\%file_name%' -DestinationPath '%temp_dir%'" 2>nul
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Failed to extract SDK
|
||||
rmdir /s /q "%temp_dir%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
for /d %%d in ("%temp_dir%\PSn00bSDK-*") do (
|
||||
set extracted_dir=%%d
|
||||
)
|
||||
|
||||
if not defined extracted_dir (
|
||||
echo [ERROR] Failed to find extracted SDK directory
|
||||
rmdir /s /q "%temp_dir%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] Installing PSn00bSDK to: %install_dir%
|
||||
|
||||
if not exist "%install_dir%" mkdir "%install_dir%"
|
||||
xcopy /s /e /i /y "!extracted_dir!\*" "%install_dir%\" >nul
|
||||
if errorlevel 1 (
|
||||
echo [ERROR] Failed to copy files
|
||||
rmdir /s /q "%temp_dir%"
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] Creating version file...
|
||||
echo %version% > "%install_dir%\%VERSION_FILE%"
|
||||
|
||||
rmdir /s /q "%temp_dir%"
|
||||
echo [INFO] Installation completed successfully!
|
||||
exit /b 0
|
||||
|
||||
:setup_environment
|
||||
set install_dir=%~1
|
||||
|
||||
set bin_dir=%install_dir%\bin
|
||||
set libs_dir=%install_dir%\lib\libpsn00b
|
||||
|
||||
echo [INFO] Configuring environment variables...
|
||||
|
||||
for /f "tokens=2*" %%a in ('reg query "HKCU\Environment" /v PATH 2^>nul') do (
|
||||
set current_path=%%b
|
||||
)
|
||||
|
||||
if not defined current_path set current_path=
|
||||
|
||||
set psn00b_path=%bin_dir%
|
||||
set psn00b_libs=%libs_dir%
|
||||
|
||||
echo %psn00b_path%| findstr /C:"%current_path%" >nul
|
||||
if errorlevel 1 (
|
||||
setx PATH "%psn00b_path%;%current_path%" >nul
|
||||
echo [INFO] PATH updated successfully
|
||||
) else (
|
||||
echo [WARN] PATH already contains PSn00bSDK
|
||||
)
|
||||
|
||||
setx PSN00BSDK_LIBS "%psn00b_libs%" >nul
|
||||
echo [INFO] PSN00BSDK_LIBS set successfully
|
||||
|
||||
echo [INFO] Please restart your terminal for environment changes to take effect
|
||||
exit /b 0
|
||||
|
||||
:verify_installation
|
||||
set install_dir=%~1
|
||||
|
||||
echo [INFO] Verifying installation...
|
||||
|
||||
if not exist "%install_dir%\bin" (
|
||||
echo [ERROR] bin directory not found in %install_dir%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%install_dir%\lib\libpsn00b" (
|
||||
echo [ERROR] libpsn00b directory not found in %install_dir%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [INFO] All checks passed!
|
||||
exit /b 0
|
||||
|
||||
:print_post_install
|
||||
set install_dir=%~1
|
||||
|
||||
echo.
|
||||
echo ==========================================
|
||||
echo PSn00bSDK Installation Complete!
|
||||
echo ==========================================
|
||||
echo.
|
||||
echo Installation directory: %install_dir%
|
||||
echo.
|
||||
echo To complete setup, please:
|
||||
echo 1. Close and reopen your terminal (or restart your computer)
|
||||
echo for environment variables to take effect
|
||||
echo.
|
||||
echo 2. Verify installation by running:
|
||||
echo mipsel-none-elf-gcc --version
|
||||
echo mkpsxiso --help
|
||||
echo.
|
||||
echo 3. Create your first project using the template:
|
||||
echo xcopy /e /i "%install_dir%\share\psn00bsdk\template" "%USERPROFILE%\my_project"
|
||||
echo cd "%USERPROFILE%\my_project"
|
||||
echo cmake --preset default .
|
||||
echo cmake --build ./build
|
||||
echo.
|
||||
echo For more information, see:
|
||||
echo %install_dir%\share\psn00bsdk\doc\README.md
|
||||
echo ==========================================
|
||||
exit /b 0
|
||||
|
||||
:uninstall_sdk
|
||||
set install_dir=%~1
|
||||
|
||||
if not exist "%install_dir%" (
|
||||
echo [WARN] Installation directory not found: %install_dir%
|
||||
set /p install_dir="Enter installation directory path: "
|
||||
if not exist "%install_dir%" (
|
||||
echo [ERROR] Directory not found: %install_dir%
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
echo [WARN] This will remove PSn00bSDK from: %install_dir%
|
||||
set /p confirm="Are you sure? (y/N): "
|
||||
if /i not "%confirm%"=="y" (
|
||||
echo [ERROR] Uninstallation cancelled.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
rmdir /s /q "%install_dir%"
|
||||
echo [INFO] PSn00bSDK removed successfully!
|
||||
exit /b 0
|
||||
|
||||
:remove_environment
|
||||
set install_dir=%install_dir%
|
||||
|
||||
echo [INFO] Removing PSn00bSDK environment variables...
|
||||
|
||||
reg query "HKCU\Environment" /v PSN00BSDK_LIBS >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
reg delete "HKCU\Environment" /v PSN00BSDK_LIBS /f >nul 2>&1
|
||||
echo [INFO] PSN00BSDK_LIBS removed
|
||||
)
|
||||
|
||||
for /f "tokens=2*" %%a in ('reg query "HKCU\Environment" /v PATH 2^>nul') do (
|
||||
set current_path=%%b
|
||||
)
|
||||
|
||||
if defined current_path (
|
||||
set psn00b_path=%DEFAULT_INSTALL_DIR%\bin
|
||||
|
||||
set new_path=!current_path!
|
||||
set new_path=!new_path:%psn00b_path%;=!
|
||||
set new_path=!new_path:%psn00b_path%=!
|
||||
|
||||
if not "!new_path!"=="!current_path!" (
|
||||
reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f >nul 2>&1
|
||||
if not errorlevel 1 (
|
||||
echo [INFO] PATH cleaned
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:exit_script
|
||||
echo Exiting...
|
||||
exit /b 0
|
||||
414
psn00bsdk_manager.sh
Executable file
414
psn00bsdk_manager.sh
Executable file
@@ -0,0 +1,414 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
GITHUB_API="https://api.github.com/repos/Lameguy64/PSn00bSDK/releases/latest"
|
||||
GITHUB_RELEASES="https://github.com/Lameguy64/PSn00bSDK/releases"
|
||||
DEFAULT_INSTALL_DIR="/opt/psn00bsdk"
|
||||
VERSION_FILE=".version"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
print_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
print_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
print_menu() {
|
||||
echo -e "${CYAN}$1${NC}"
|
||||
}
|
||||
|
||||
check_dependencies() {
|
||||
local missing_deps=()
|
||||
|
||||
for cmd in wget unzip curl jq; do
|
||||
if ! command -v $cmd &> /dev/null; then
|
||||
missing_deps+=($cmd)
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#missing_deps[@]} -ne 0 ]; then
|
||||
print_error "Missing required dependencies: ${missing_deps[*]}"
|
||||
print_info "Install with: sudo apt install ${missing_deps[*]} (Ubuntu/Debian)"
|
||||
print_info " sudo yum install ${missing_deps[*]} (RHEL/CentOS)"
|
||||
print_info " sudo pacman -S ${missing_deps[*]} (Arch Linux)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_latest_version() {
|
||||
local latest_tag=$(curl -s "$GITHUB_API" | grep -o '"tag_name": *"[^"]*"' | cut -d'"' -f4)
|
||||
|
||||
if [ -z "$latest_tag" ]; then
|
||||
print_error "Failed to fetch latest version from GitHub"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "$latest_tag"
|
||||
}
|
||||
|
||||
check_installed_version() {
|
||||
local install_dir="$1"
|
||||
|
||||
if [ ! -f "$install_dir/$VERSION_FILE" ]; then
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
cat "$install_dir/$VERSION_FILE"
|
||||
}
|
||||
|
||||
check_updates() {
|
||||
local install_dir="$1"
|
||||
|
||||
if [ ! -d "$install_dir" ]; then
|
||||
print_warn "PSn00bSDK is not installed in: $install_dir"
|
||||
read -p "Enter installation directory: " install_dir
|
||||
if [ ! -d "$install_dir" ]; then
|
||||
print_error "Directory not found: $install_dir"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_info "Checking for latest release from GitHub..."
|
||||
|
||||
local installed_version=$(check_installed_version "$install_dir")
|
||||
local latest_version=$(get_latest_version 2>/dev/null)
|
||||
|
||||
if [ $? -ne 0 ] || [ -z "$latest_version" ]; then
|
||||
print_error "Failed to get latest version from GitHub"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local latest_version_num=$(echo "$latest_version" | sed 's/^v//')
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo " Version Check Results"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Installed version: ${installed_version:-${RED}Not detected${NC}}"
|
||||
echo "Latest version: ${latest_version_num}"
|
||||
echo ""
|
||||
|
||||
if [ "$installed_version" = "$latest_version_num" ]; then
|
||||
print_info "You are running the latest version!"
|
||||
elif [ -z "$installed_version" ]; then
|
||||
print_warn "Could not detect installed version"
|
||||
else
|
||||
print_info "A newer version is available!"
|
||||
echo ""
|
||||
print_menu "Download the latest version from:"
|
||||
echo " $GITHUB_RELEASES"
|
||||
fi
|
||||
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
}
|
||||
|
||||
install_sdk() {
|
||||
local install_dir="$1"
|
||||
local version="$2"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
print_info "Checking for latest release from GitHub..."
|
||||
local latest_version=$(get_latest_version 2>/dev/null)
|
||||
if [ $? -ne 0 ] || [ -z "$latest_version" ]; then
|
||||
print_error "Failed to determine version to install"
|
||||
return 1
|
||||
fi
|
||||
version=$(echo "$latest_version" | sed 's/^v//')
|
||||
print_info "Installing latest version: $version"
|
||||
fi
|
||||
|
||||
local file_name="PSn00bSDK-${version}-Linux.zip"
|
||||
local download_url="https://github.com/Lameguy64/PSn00bSDK/releases/download/v${version}/${file_name}"
|
||||
local temp_dir=$(mktemp -d)
|
||||
|
||||
if [ -d "$install_dir" ]; then
|
||||
print_warn "Installation directory already exists: $install_dir"
|
||||
read -p "Do you want to overwrite it? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_error "Installation cancelled."
|
||||
rm -rf "$temp_dir"
|
||||
return 1
|
||||
fi
|
||||
sudo rm -rf "$install_dir"
|
||||
fi
|
||||
|
||||
print_info "Downloading PSn00bSDK v${version}..."
|
||||
print_info "URL: $download_url"
|
||||
|
||||
if ! wget -O "${temp_dir}/${file_name}" "$download_url"; then
|
||||
print_error "Failed to download PSn00bSDK"
|
||||
rm -rf "$temp_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_info "Extracting SDK to temporary directory..."
|
||||
unzip -q "${temp_dir}/${file_name}" -d "$temp_dir"
|
||||
|
||||
local extracted_dir=$(find "$temp_dir" -maxdepth 1 -type d -name "PSn00bSDK-*" | head -n1)
|
||||
|
||||
if [ -z "$extracted_dir" ]; then
|
||||
print_error "Failed to find extracted SDK directory"
|
||||
rm -rf "$temp_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_info "Installing PSn00bSDK to: $install_dir"
|
||||
|
||||
sudo mkdir -p "$install_dir"
|
||||
sudo cp -r "$extracted_dir"/* "$install_dir"/
|
||||
|
||||
print_info "Creating version file..."
|
||||
echo "$version" | sudo tee "$install_dir/$VERSION_FILE" > /dev/null
|
||||
|
||||
print_info "Setting permissions..."
|
||||
sudo chown -R root:root "$install_dir"
|
||||
sudo chmod -R 755 "$install_dir"
|
||||
sudo chmod +x "$install_dir"/bin/*
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
print_info "Installation completed successfully!"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_environment() {
|
||||
local install_dir="$1"
|
||||
local profile_file=""
|
||||
local bashrc="$HOME/.bashrc"
|
||||
local zshrc="$HOME/.zshrc"
|
||||
|
||||
if [ -n "$ZSH_VERSION" ]; then
|
||||
profile_file="$zshrc"
|
||||
elif [ -n "$BASH_VERSION" ]; then
|
||||
profile_file="$bashrc"
|
||||
else
|
||||
profile_file="$bashrc"
|
||||
fi
|
||||
|
||||
local bin_dir="$install_dir/bin"
|
||||
local libs_dir="$install_dir/lib/libpsn00b"
|
||||
|
||||
print_info "Configuring environment variables in: $profile_file"
|
||||
|
||||
local env_block="# PSn00bSDK Environment Variables"
|
||||
if grep -q "$env_block" "$profile_file" 2>/dev/null; then
|
||||
print_warn "Environment variables already configured in $profile_file"
|
||||
print_info "Removing old configuration..."
|
||||
sed -i "/$env_block/,/# End PSn00bSDK/d" "$profile_file"
|
||||
fi
|
||||
|
||||
{
|
||||
echo ""
|
||||
echo "$env_block"
|
||||
echo "export PATH="$bin_dir:$PATH""
|
||||
echo "export PSN00BSDK_LIBS="$libs_dir""
|
||||
echo "# End PSn00bSDK"
|
||||
} >> "$profile_file"
|
||||
|
||||
print_info "Environment variables added to $profile_file"
|
||||
print_info "Please run: source $profile_file"
|
||||
}
|
||||
|
||||
verify_installation() {
|
||||
local install_dir="$1"
|
||||
|
||||
print_info "Verifying installation..."
|
||||
|
||||
if [ ! -d "$install_dir/bin" ]; then
|
||||
print_error "bin directory not found in $install_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$install_dir/lib/libpsn00b" ]; then
|
||||
print_error "libpsn00b directory not found in $install_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$install_dir/bin/mipsel-none-elf-gcc" ]; then
|
||||
print_error "mipsel-none-elf-gcc not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
print_info "All checks passed!"
|
||||
return 0
|
||||
}
|
||||
|
||||
print_post_install() {
|
||||
local install_dir="$1"
|
||||
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo "PSn00bSDK Installation Complete!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Installation directory: $install_dir"
|
||||
echo ""
|
||||
echo "To complete setup, please:"
|
||||
echo " 1. Source your shell configuration:"
|
||||
echo " source ~/.bashrc"
|
||||
echo " or"
|
||||
echo " source ~/.zshrc"
|
||||
echo ""
|
||||
echo " 2. Verify installation by running:"
|
||||
echo " mipsel-none-elf-gcc --version"
|
||||
echo " mkpsxiso --help"
|
||||
echo ""
|
||||
echo " 3. Create your first project using the template:"
|
||||
echo " cp -r $install_dir/share/psn00bsdk/template ~/my_project"
|
||||
echo " cd ~/my_project"
|
||||
echo " cmake --preset default ."
|
||||
echo " cmake --build ./build"
|
||||
echo ""
|
||||
echo "For more information, see:"
|
||||
echo " $install_dir/share/psn00bsdk/doc/README.md"
|
||||
echo "=========================================="
|
||||
}
|
||||
|
||||
uninstall_sdk() {
|
||||
local install_dir="$1"
|
||||
|
||||
if [ ! -d "$install_dir" ]; then
|
||||
print_warn "Installation directory not found: $install_dir"
|
||||
read -p "Enter installation directory path: " install_dir
|
||||
if [ ! -d "$install_dir" ]; then
|
||||
print_error "Directory not found: $install_dir"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_warn "This will remove PSn00bSDK from: $install_dir"
|
||||
read -p "Are you sure? (y/N): " -n 1 -r
|
||||
echo
|
||||
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_error "Uninstallation cancelled."
|
||||
return 1
|
||||
fi
|
||||
|
||||
sudo rm -rf "$install_dir"
|
||||
print_info "PSn00bSDK removed successfully!"
|
||||
return 0
|
||||
}
|
||||
|
||||
remove_environment() {
|
||||
local profile_file=""
|
||||
local bashrc="$HOME/.bashrc"
|
||||
local zshrc="$HOME/.zshrc"
|
||||
|
||||
if [ -n "$ZSH_VERSION" ]; then
|
||||
profile_file="$zshrc"
|
||||
elif [ -n "$BASH_VERSION" ]; then
|
||||
profile_file="$bashrc"
|
||||
else
|
||||
profile_file="$bashrc"
|
||||
fi
|
||||
|
||||
if [ -f "$profile_file" ]; then
|
||||
if grep -q "PSn00bSDK Environment Variables" "$profile_file" 2>/dev/null; then
|
||||
print_info "Removing PSn00bSDK environment variables from: $profile_file"
|
||||
sed -i "/# PSn00bSDK Environment Variables/,/# End PSn00bSDK/d" "$profile_file"
|
||||
print_info "Environment variables removed."
|
||||
else
|
||||
print_warn "No PSn00bSDK environment variables found in $profile_file"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
show_menu() {
|
||||
echo ""
|
||||
echo "=========================================="
|
||||
echo " PSn00bSDK Manager"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Please select an action:"
|
||||
echo ""
|
||||
print_menu "1) Install PSn00bSDK"
|
||||
print_menu "2) Uninstall PSn00bSDK"
|
||||
print_menu "3) Check for updates"
|
||||
print_menu "4) Exit"
|
||||
echo ""
|
||||
read -p "Enter your choice [1-4]: " choice
|
||||
echo ""
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
echo ""
|
||||
read -p "Enter version to install (leave blank for latest, e.g., 0.24): " version
|
||||
echo ""
|
||||
read -p "Enter installation directory [$DEFAULT_INSTALL_DIR]: " install_dir
|
||||
install_dir="${install_dir:-$DEFAULT_INSTALL_DIR}"
|
||||
|
||||
if [[ ! $install_dir = /* ]]; then
|
||||
install_dir="$(pwd)/$install_dir"
|
||||
fi
|
||||
|
||||
if install_sdk "$install_dir" "$version"; then
|
||||
setup_environment "$install_dir"
|
||||
verify_installation "$install_dir"
|
||||
print_post_install "$install_dir"
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
echo ""
|
||||
read -p "Enter installation directory [$DEFAULT_INSTALL_DIR]: " install_dir
|
||||
install_dir="${install_dir:-$DEFAULT_INSTALL_DIR}"
|
||||
|
||||
if uninstall_sdk "$install_dir"; then
|
||||
remove_environment
|
||||
echo ""
|
||||
print_info "Uninstallation complete!"
|
||||
print_info "Please run: source ~/.bashrc (or ~/.zshrc) to update your shell"
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
echo ""
|
||||
read -p "Enter installation directory [$DEFAULT_INSTALL_DIR]: " install_dir
|
||||
install_dir="${install_dir:-$DEFAULT_INSTALL_DIR}"
|
||||
|
||||
check_updates "$install_dir"
|
||||
;;
|
||||
4)
|
||||
echo "Exiting..."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid choice. Please enter a number between 1 and 4."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main() {
|
||||
check_dependencies
|
||||
|
||||
while true; do
|
||||
show_menu
|
||||
echo ""
|
||||
read -p "Press Enter to continue or 'q' to quit: " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Qq]$ ]]; then
|
||||
echo "Exiting..."
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main
|
||||
fi
|
||||
Reference in New Issue
Block a user