|
|
@@ -0,0 +1,295 @@
|
|
|
+@echo off
|
|
|
+REM Usage:
|
|
|
+REM Normal mode: getlog <caseno> [filename]
|
|
|
+REM Setup mode: getlog setup
|
|
|
+REM Folder setup: getlog foldersetup
|
|
|
+REM Install: getlog install
|
|
|
+
|
|
|
+set "SCRIPT_DIR=%~dp0"
|
|
|
+set "SCRIPT_PATH=%~f0"
|
|
|
+set "CONFIG_FILE=%SCRIPT_DIR%getlog_config.dat"
|
|
|
+set "FOLDER_CONFIG=%SCRIPT_DIR%getlog_folder.dat"
|
|
|
+
|
|
|
+REM Check for setup modes
|
|
|
+if /i "%~1"=="setup" (
|
|
|
+ call :setup
|
|
|
+ goto :eof
|
|
|
+)
|
|
|
+
|
|
|
+if /i "%~1"=="foldersetup" (
|
|
|
+ call :foldersetup
|
|
|
+ goto :eof
|
|
|
+)
|
|
|
+
|
|
|
+if /i "%~1"=="install" (
|
|
|
+ call :install
|
|
|
+ goto :eof
|
|
|
+)
|
|
|
+
|
|
|
+if /i "%~1"=="uninstall" (
|
|
|
+ call :uninstall
|
|
|
+ goto :eof
|
|
|
+)
|
|
|
+
|
|
|
+REM Normal mode - check for required arguments
|
|
|
+if "%~1"=="" (
|
|
|
+ echo Usage: %~n0 ^<caseno^> [filename]
|
|
|
+ echo.
|
|
|
+ echo Examples:
|
|
|
+ echo %~n0 1010011 support.tgz - Download specific file
|
|
|
+ echo %~n0 1010011 - Download entire case directory
|
|
|
+ echo.
|
|
|
+ echo Setup mode: %~n0 setup
|
|
|
+ echo Folder setup: %~n0 foldersetup
|
|
|
+ echo Install: %~n0 install
|
|
|
+ exit /b 1
|
|
|
+)
|
|
|
+
|
|
|
+REM Load username from config or use default
|
|
|
+set "USERNAME=pashwani"
|
|
|
+if exist "%CONFIG_FILE%" (
|
|
|
+ set /p USERNAME=<"%CONFIG_FILE%"
|
|
|
+)
|
|
|
+
|
|
|
+REM Load folder preference or use default (SJLNT structure)
|
|
|
+set "FOLDER_MODE=SJLNT"
|
|
|
+if exist "%FOLDER_CONFIG%" (
|
|
|
+ set /p FOLDER_MODE=<"%FOLDER_CONFIG%"
|
|
|
+)
|
|
|
+
|
|
|
+set "CASE=%~1"
|
|
|
+
|
|
|
+REM Check if filename is provided
|
|
|
+if "%~2"=="" (
|
|
|
+ set "DOWNLOAD_MODE=dir"
|
|
|
+ echo No filename provided. Will download entire case directory.
|
|
|
+) else (
|
|
|
+ set "DOWNLOAD_MODE=file"
|
|
|
+ set "FILE=%~2"
|
|
|
+)
|
|
|
+
|
|
|
+REM Determine destination based on folder mode
|
|
|
+if /i "%FOLDER_MODE%"=="OLD" (
|
|
|
+ set "DEST=%USERPROFILE%\Downloads\Traces n Logs\%CASE%"
|
|
|
+ echo Using OLD folder structure: Traces n Logs
|
|
|
+) else (
|
|
|
+ set "DEST=%USERPROFILE%\Downloads\SJLNT\%CASE%"
|
|
|
+ echo Using NEW folder structure: SJLNT
|
|
|
+)
|
|
|
+
|
|
|
+REM Create destination folder if it doesn't exist
|
|
|
+if not exist "%DEST%" (
|
|
|
+ mkdir "%DEST%" 2>nul
|
|
|
+ if errorlevel 1 (
|
|
|
+ echo ERROR: Cannot create directory: %DEST%
|
|
|
+ echo Please check your permissions or disk space.
|
|
|
+ exit /b 1
|
|
|
+ )
|
|
|
+ echo Created folder: %DEST%
|
|
|
+)
|
|
|
+
|
|
|
+REM Perform download based on mode
|
|
|
+if "%DOWNLOAD_MODE%"=="dir" (
|
|
|
+ echo Downloading entire case directory using username: %USERNAME%
|
|
|
+ echo Remote source: %USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%
|
|
|
+ echo Local destination: %DEST%
|
|
|
+ echo.
|
|
|
+ echo This may take some time depending on the directory size...
|
|
|
+ echo.
|
|
|
+
|
|
|
+ REM First, let's test the connection and check if the remote directory exists
|
|
|
+ echo Testing connection to remote server...
|
|
|
+ ssh -o BatchMode=yes -o ConnectTimeout=5 "%USERNAME%@sjanalysis.citrite.net" "ls -la /upload/ftp/%CASE%/ 2>/dev/null || echo 'Directory not found'" >nul 2>&1
|
|
|
+
|
|
|
+ echo Starting download...
|
|
|
+
|
|
|
+ REM Use scp -r for recursive directory copy - REMOVE trailing slash from source
|
|
|
+ REM The issue was likely with the trailing slash in the source path
|
|
|
+ scp -rp "%USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%" "%DEST%"
|
|
|
+
|
|
|
+ if errorlevel 1 (
|
|
|
+ echo.
|
|
|
+ echo SCP failed with error code: %errorlevel%
|
|
|
+ echo Possible issues:
|
|
|
+ echo 1. Case directory %CASE% doesn't exist on remote server
|
|
|
+ echo 2. Network connectivity issue
|
|
|
+ echo 3. Incorrect username
|
|
|
+ echo.
|
|
|
+ echo You can run 'getlog setup' to reconfigure username.
|
|
|
+ echo To check if directory exists: ssh %USERNAME%@sjanalysis.citrite.net "ls -la /upload/ftp/%CASE%/"
|
|
|
+ exit /b 1
|
|
|
+ )
|
|
|
+
|
|
|
+ echo.
|
|
|
+ echo Entire case directory downloaded successfully to: %DEST%
|
|
|
+ echo.
|
|
|
+
|
|
|
+ REM Show downloaded contents
|
|
|
+ echo Directory contents:
|
|
|
+ echo -------------------
|
|
|
+ dir /b "%DEST%" 2>nul || echo (No files downloaded or directory empty)
|
|
|
+) else (
|
|
|
+ echo Downloading file using username: %USERNAME%
|
|
|
+ echo Remote file: /upload/ftp/%CASE%/%FILE%
|
|
|
+
|
|
|
+ scp -p "%USERNAME%@sjanalysis.citrite.net:/upload/ftp/%CASE%/%FILE%" "%DEST%"
|
|
|
+
|
|
|
+ if errorlevel 1 (
|
|
|
+ echo SCP failed with error code: %errorlevel%
|
|
|
+ echo Please check:
|
|
|
+ echo 1. File exists on remote server
|
|
|
+ echo 2. Username is correct
|
|
|
+ echo 3. Network connection
|
|
|
+ echo.
|
|
|
+ echo Run 'getlog setup' to reconfigure username.
|
|
|
+ exit /b 1
|
|
|
+ )
|
|
|
+
|
|
|
+ echo.
|
|
|
+ echo File downloaded successfully to: %DEST%
|
|
|
+ echo Full path: %DEST%\%FILE%
|
|
|
+)
|
|
|
+
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:setup
|
|
|
+echo Current username: %USERNAME%
|
|
|
+echo.
|
|
|
+set /p "NEW_USER=Enter new username: "
|
|
|
+if "%NEW_USER%"=="" (
|
|
|
+ echo Username cannot be empty.
|
|
|
+ goto :setup
|
|
|
+)
|
|
|
+echo %NEW_USER%>"%CONFIG_FILE%"
|
|
|
+echo Username saved successfully.
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:foldersetup
|
|
|
+echo.
|
|
|
+echo Current folder structure: %FOLDER_MODE%
|
|
|
+echo.
|
|
|
+echo Available options:
|
|
|
+echo 1. SJLNT (new) - %USERPROFILE%\Downloads\SJLNT\<caseno>
|
|
|
+echo 2. OLD (legacy) - %USERPROFILE%\Downloads\Traces n Logs\<caseno>
|
|
|
+echo.
|
|
|
+set /p "FOLDER_CHOICE=Enter folder structure (1 for SJLNT, 2 for OLD): "
|
|
|
+
|
|
|
+if "%FOLDER_CHOICE%"=="1" (
|
|
|
+ echo SJLNT>"%FOLDER_CONFIG%"
|
|
|
+ echo Folder structure set to SJLNT (new).
|
|
|
+) else if "%FOLDER_CHOICE%"=="2" (
|
|
|
+ echo OLD>"%FOLDER_CONFIG%"
|
|
|
+ echo Folder structure set to OLD (legacy).
|
|
|
+) else (
|
|
|
+ echo Invalid choice. Using default (SJLNT).
|
|
|
+ echo SJLNT>"%FOLDER_CONFIG%"
|
|
|
+)
|
|
|
+echo.
|
|
|
+echo Run: getlog ^<caseno^> [filename] to download files.
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:install
|
|
|
+echo Installing getlog for global access...
|
|
|
+echo ========================================
|
|
|
+echo.
|
|
|
+
|
|
|
+REM Check if already in PATH
|
|
|
+echo %PATH% | find /i "%SCRIPT_DIR%" >nul
|
|
|
+if not errorlevel 1 (
|
|
|
+ echo Script is already in PATH.
|
|
|
+ echo Location: %SCRIPT_DIR%
|
|
|
+ goto :check_admin
|
|
|
+)
|
|
|
+
|
|
|
+REM Check for administrator privileges
|
|
|
+net session >nul 2>&1
|
|
|
+if %errorlevel% neq 0 (
|
|
|
+ echo Warning: Administrative privileges required for system-wide installation.
|
|
|
+ echo You can still install for current user only.
|
|
|
+ echo.
|
|
|
+ choice /c SU /m "Install for: [S]ystem (admin required) or [U]ser"
|
|
|
+ if errorlevel 2 goto :user_install
|
|
|
+ goto :system_install
|
|
|
+)
|
|
|
+
|
|
|
+:system_install
|
|
|
+echo Installing for all users (requires admin)...
|
|
|
+echo.
|
|
|
+REM Add to system PATH using setx
|
|
|
+setx PATH "%PATH%;%SCRIPT_DIR%" /M >nul
|
|
|
+if errorlevel 1 (
|
|
|
+ echo Failed to update system PATH. Trying user PATH...
|
|
|
+ goto :user_install
|
|
|
+) else (
|
|
|
+ echo Successfully added to system PATH.
|
|
|
+ echo Script directory: %SCRIPT_DIR%
|
|
|
+ echo.
|
|
|
+ echo You may need to restart your terminal for changes to take effect.
|
|
|
+)
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:user_install
|
|
|
+echo Installing for current user only...
|
|
|
+echo.
|
|
|
+REM Add to user PATH
|
|
|
+setx PATH "%PATH%;%SCRIPT_DIR%" >nul
|
|
|
+if errorlevel 1 (
|
|
|
+ echo Failed to update user PATH.
|
|
|
+ echo.
|
|
|
+ echo Manual installation steps:
|
|
|
+ echo 1. Copy this script to a directory already in your PATH
|
|
|
+ echo 2. Or add this directory to your PATH manually:
|
|
|
+ echo %SCRIPT_DIR%
|
|
|
+) else (
|
|
|
+ echo Successfully added to user PATH.
|
|
|
+ echo Script directory: %SCRIPT_DIR%
|
|
|
+ echo.
|
|
|
+ echo You may need to restart your terminal for changes to take effect.
|
|
|
+)
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:check_admin
|
|
|
+echo.
|
|
|
+echo You can now run 'getlog' from any directory.
|
|
|
+echo.
|
|
|
+goto :eof
|
|
|
+
|
|
|
+:uninstall
|
|
|
+echo Uninstalling getlog...
|
|
|
+echo ======================
|
|
|
+echo.
|
|
|
+echo Warning: This will only remove the script directory from PATH.
|
|
|
+echo The script files and configuration will not be deleted.
|
|
|
+echo.
|
|
|
+echo Script location: %SCRIPT_DIR%
|
|
|
+echo.
|
|
|
+
|
|
|
+choice /c YN /m "Are you sure you want to remove getlog from PATH? [Y/N]"
|
|
|
+if errorlevel 2 (
|
|
|
+ echo Uninstall cancelled.
|
|
|
+ goto :eof
|
|
|
+)
|
|
|
+
|
|
|
+echo.
|
|
|
+echo Removing from PATH...
|
|
|
+
|
|
|
+REM Create a temporary PowerShell script to safely remove from PATH
|
|
|
+set "PS_SCRIPT=%TEMP%\remove_from_path.ps1"
|
|
|
+(
|
|
|
+echo $currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
|
|
|
+echo $systemPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
|
|
|
+echo $scriptDir = "%SCRIPT_DIR:\=/%"
|
|
|
+echo $newUserPath = ($currentPath -split ';' ^| Where-Object { $_ -ne "%SCRIPT_DIR%" } ^| Where-Object { $_ -ne "" }) -join ';'
|
|
|
+echo $newSystemPath = ($systemPath -split ';' ^| Where-Object { $_ -ne "%SCRIPT_DIR%" } ^| Where-Object { $_ -ne "" }) -join ';'
|
|
|
+echo [Environment]::SetEnvironmentVariable('PATH', $newUserPath, 'User')
|
|
|
+echo [Environment]::SetEnvironmentVariable('PATH', $newSystemPath, 'Machine')
|
|
|
+echo "PATH updated. You may need to restart your terminal."
|
|
|
+) > "%PS_SCRIPT%"
|
|
|
+
|
|
|
+powershell -ExecutionPolicy Bypass -File "%PS_SCRIPT%"
|
|
|
+del "%PS_SCRIPT%" >nul 2>&1
|
|
|
+
|
|
|
+echo.
|
|
|
+echo getlog has been removed from PATH.
|
|
|
+echo Note: Script files and configuration remain in: %SCRIPT_DIR%
|
|
|
+goto :eof
|