-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlaunchLMS_service.cmd
More file actions
121 lines (101 loc) · 4.21 KB
/
launchLMS_service.cmd
File metadata and controls
121 lines (101 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@echo off && setlocal EnableDelayedExpansion
rem VXN LMStudio Portable Launch Script (LMS PLS)
rem Modify in case you want to change in which GPU(s) you want to load models.
rem 0 (1st GPU), 1 (2nd), 2 (3rd) and so on. Specify multiple GPUs with commas: 1,2,3
rem set CUDA_VISIBLE_DEVICES=1
rem Get current path and set log file on it
cd /D "%~dp0"
set "CurrentPath=%CD%"
rem Set current lmstudio home
echo %CurrentPath%\.lmstudio > "%CurrentPath%\.lmstudio-home-pointer"
rem Set current drive as %HomeDrive%
set "HomeDrive=%~d0"
rem \
set "HomePath=%cd:~2%"
set "UserProfile=%CurrentPath%"
rem \AppData\Local
set "LocalAppData=%CurrentPath%\AppData\Local"
rem \AppData\Local
set "LocalLowAppData=%CurrentPath%\AppData\LocalLow"
rem \AppData\Local\Temp
set "Temp=%LocalAppData%\Temp"
rem \AppData\Roaming
set "AppData=%CurrentPath%\AppData\Roaming"
rem Set \AppPath
set "AppPath=%CurrentPath%\App"
rem Create paths if doesn't exist
if not exist "%UserProfile%\Desktop" mkdir "%UserProfile%\Desktop"
if not exist "%UserProfile%\AppData" mkdir "%UserProfile%\AppData"
if not exist "%LocalLowAppData%" mkdir "%LocalLowAppData%"
if not exist "%LocalAppData%" mkdir "%LocalAppData%"
if not exist "%AppData%" mkdir "%AppData%"
if not exist "%AppPath%" mkdir "%AppPath%"
if not exist "%Temp%" mkdir "%Temp%"
rem Check if latest installer is ready for installation, in case needed
set "InstallerPath=%CurrentPath%\Installer"
if not exist "%InstallerPath%" mkdir "%InstallerPath%"
for /f "delims=" %%A in ('dir /b /a-d /on "%InstallerPath%\LM-Studio-*.exe" 2^>nul') do ( set "InstallerExe=%%A" )
rem Skip functions and go directly to :main
goto :main
:cleanUpRegistry
rem LM Studio Installer registry clean-up
set "regKey=HKEY_CURRENT_USER\Software\c6dbe996-22a9-5998-b542-7abe33da3b83"
echo Checking if key "%regKey%" exists...
reg query "%regKey%" >nul
if %errorlevel% equ 0 ( reg delete "%regKey%" /f )
set "regKey=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\c6dbe996-22a9-5998-b542-7abe33da3b83"
echo Checking if key "%regKey%" exists...
reg query "%regKey%" >nul
if %errorlevel% equ 0 ( reg delete "%regKey%" /f )
exit /b 0
:main
rem Application Startup
if not exist "%AppPath%\LM Studio.exe" (
echo LM Studio not installed in "%AppPath%"
echo Performing installation...
if "%InstallerExe%" == "" (
echo LM Studio installer ^(LM-Studio-*.exe^) was not found.
echo Please download LM Studio from https://lmstudio.ai/download and put the installer file inside "%InstallerPath%"
pause && exit
) else (
echo Performing initial registry cleanup...
call :cleanUpRegistry
echo Launching installer "%InstallerExe%" from "%InstallerPath%"
call "%InstallerPath%\%InstallerExe%" /S /D="%AppPath%"
echo LM Studio installed, cleaning up registry and launching it...
call :cleanUpRegistry
timeout /t 5 /nobreak
)
) else (
rem Modify models path in settings.json to the current drive
set "inputFile=%AppData%\LM Studio\settings.json"
if exist "!inputFile!" (
set "tempFile=%AppData%\LM Studio\settings_temp.json"
set searchString=downloadsFolder
rem "downloadsFolder": "..\\..\\..\\..\\.lmstudio\\models",
set replaceString= "downloadsFolder": "%UserProfile:\=\\%\\.lmstudio\\models",
(
rem Recreate config file with a modified downloadsFolder
for /f "usebackq delims=" %%A in ("!inputFile!") do (
set "line=%%A"
echo !line! | findstr /c:!searchString! >nul
if !errorlevel! equ 0 (
rem Replace line if the string is found
echo !replaceString!
) else (
rem Keep rest of lines
echo !line!
)
)
) > "!tempFile!"
rem Replace original settings file with modified one
move /y "!tempFile!" "!inputFile!" >nul
)
)
if exist "%AppPath%\LM Studio.exe" (
rem Start app in headless mode
start "LM Studio Headless" "%AppPath%\LM Studio.exe" --run-as-service
) else (
echo Please check why LM Studio was not properly installed under %AppPath%
pause && exit
)