如何使用 Inno Setup 以静默方式运行安装后命令?

问题描述 投票:0回答:1

我正在使用 Inno Setup 为我的应用程序创建安装程序。安装过程的一部分包括安装 Ollama 二进制文件并运行几个命令来设置模型。但是,这些命令似乎没有按预期运行。这是我的 Inno 安装脚本:

[Setup]
AppName=Chat2Find
AppVersion=1.0
DefaultDirName={pf}\Chat2Find
DefaultGroupName=Chat2Find
OutputDir=.
OutputBaseFilename=Chat2FindInstaller
Compression=lzma
SolidCompression=yes
DiskSpanning=yes

[Files]
; Include the executable
Source: "C:\Users\presh\c2f\dist\Chat2Find.exe"; DestDir: "{app}"; Flags: ignoreversion

; Include the GGUF files to be extracted to a permanent location
Source: "C:\Users\presh\c2f\dist\Mistral-7B-Instruct-v0.3.Q4_K_M.gguf"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\Phi-3-mini-4k-instruct-q4.gguf"; DestDir: "{app}"; Flags: ignoreversion

; Include the Ollama setup binary
Source: "C:\Users\presh\c2f\dist\OllamaSetup.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall

; Include other resources
Source: "C:\Users\presh\c2f\dist\menu.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\close.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\new_note.jpg"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\copy.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\send_icon.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\chat2find.jpeg"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{group}\Chat2Find"; Filename: "{app}\Chat2Find.exe"
Name: "{commondesktop}\Chat2Find"; Filename: "{app}\Chat2Find.exe"; Tasks: desktopicon

[Tasks]
Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: checkedonce

[Run]
Filename: "{app}\Chat2Find.exe"; Description: "Launch Chat2Find"; Flags: nowait postinstall skipifsilent
; Run Ollama setup silently
Filename: "{tmp}\OllamaSetup.exe"; Description: "Install Ollama"; Flags: waituntilterminated

; Run Ollama commands silently using a script
Filename: "cmd.exe"; Parameters: "/C {app}\run_ollama_commands.bat"; Flags: runhidden postinstall

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
  GGUFDir: String;
  MistralDef, Phi3Def, OllamaScript: String;
begin
  if CurStep = ssPostInstall then
  begin
    GGUFDir := ExpandConstant('{app}');
    
    if not DirExists(GGUFDir) then
    begin
      CreateDir(GGUFDir);
    end;
    
    MistralDef := GGUFDir + '\mistral_definition';
    SaveStringToFile(MistralDef,
      'FROM ' + GGUFDir + '\Mistral-7B-Instruct-v0.3-Q4_K_M.gguf' + #13#10 +
      'TEMPLATE """[INST] {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }} [/INST]"""' + #13#10 +
      'PARAMETER stop "[INST]"' + #13#10 +
      'PARAMETER stop "[/INST]"', False);

    Phi3Def := GGUFDir + '\phi3_definition';
    SaveStringToFile(Phi3Def,
      'FROM ' + GGUFDir + '\Phi-3-mini-4k-instruct-q4.gguf' + #13#10 +
      'TEMPLATE """<s>{{ if .Prompt }}' + #13#10 +
      '{{ .Prompt }}' + #13#10 +
      '{{ end }}' + #13#10 +
      '{{ .Response }}"""' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER num_ctx 4096', False);

    OllamaScript := GGUFDir + '\run_ollama_commands.bat';
    SaveStringToFile(OllamaScript,
      'ollama create C2F_mistral -f "' + MistralDef + '"' + #13#10 +
      'ollama create C2F_phi3 -f "' + Phi3Def + '"', False);
  end;
end;

问题:

run_ollama_commands.bat 中的命令似乎没有按预期执行。如何确保安装 Ollama 二进制文件后这些命令以静默方式运行?

其他背景:

OllamaSetup.exe 正确安装 Ollama 二进制文件。

我需要使用安装过程中提供的 GGUF 文件和模板来创建模型。

批处理文件 (run_ollama_commands.bat) 应静默运行,而不显示命令提示符窗口。

任何有关如何正确执行这些安装后命令的见解或建议将不胜感激!

windows batch-file installation scripting silent-installer
1个回答
0
投票

这就是你的做法:

你必须删除整个部分:

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
  GGUFDir: String;
  MistralDef, Phi3Def, OllamaScript: String;
begin
  if CurStep = ssPostInstall then
  begin
    GGUFDir := ExpandConstant('{app}');
    
    if not DirExists(GGUFDir) then
    begin
      CreateDir(GGUFDir);
    end;
    
    MistralDef := GGUFDir + '\mistral_definition';
    SaveStringToFile(MistralDef,
      'FROM ' + GGUFDir + '\Mistral-7B-Instruct-v0.3-Q4_K_M.gguf' + #13#10 +
      'TEMPLATE """[INST] {{ if .System }}{{ .System }} {{ end }}{{ .Prompt }} [/INST]"""' + #13#10 +
      'PARAMETER stop "[INST]"' + #13#10 +
      'PARAMETER stop "[/INST]"', False);

    Phi3Def := GGUFDir + '\phi3_definition';
    SaveStringToFile(Phi3Def,
      'FROM ' + GGUFDir + '\Phi-3-mini-4k-instruct-q4.gguf' + #13#10 +
      'TEMPLATE """<s>{{ if .Prompt }}' + #13#10 +
      '{{ .Prompt }}' + #13#10 +
      '{{ end }}' + #13#10 +
      '{{ .Response }}"""' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER stop' + #13#10 +
      'PARAMETER num_ctx 4096', False);

    OllamaScript := GGUFDir + '\run_ollama_commands.bat';
    SaveStringToFile(OllamaScript,
      'ollama create C2F_mistral -f "' + MistralDef + '"' + #13#10 +
      'ollama create C2F_phi3 -f "' + Phi3Def + '"', False);
  end;
end;

;因为没有必要。这才是你应该做的:

  1. 手动创建mistral_definition文件和phi3_definition文件并将其直接放置在正确的位置(在Inno Setup中加载脚本的直接位置)。

run_ollama_commands.bat 文件应如下所示:

@echo off
cd /d %~dp0
echo Running Ollama commands...

ollama create C2F_mistral -f mistral_definition
if %errorlevel% neq 0 (
    echo Failed to create C2F_mistral model
    exit /b %errorlevel%
)

ollama create C2F_phi3 -f phi3_definition
if %errorlevel% neq 0 (
    echo Failed to create C2F_phi3 model
    exit /b %errorlevel%
)

echo Ollama commands executed successfully. Deleting GGUF files...

del /f /q "Mistral-7B-Instruct-v0.3.Q4_K_M.gguf"
del /f /q "Phi-3-mini-4k-instruct-q4.gguf"

echo GGUF files deleted.
exit

我还添加了在成功运行命令后删除 GGUF 文件的语句。这被认为是道德编程。

因此,要给出最终代码,脚本文件必须如下所示:

[Setup]
AppName=Chat2Find
AppVersion=1.0
DefaultDirName={pf}\Chat2Find
DefaultGroupName=Chat2Find
OutputDir=.
OutputBaseFilename=Chat2FindInstaller
Compression=lzma
SolidCompression=yes
DiskSpanning=yes

[Files]
; Include the executable
Source: "C:\Users\presh\c2f\dist\Chat2Find.exe"; DestDir: "{app}"; Flags: ignoreversion

; Include the GGUF files to be extracted to a permanent location
Source: "C:\Users\presh\c2f\dist\Mistral-7B-Instruct-v0.3.Q4_K_M.gguf"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\Phi-3-mini-4k-instruct-q4.gguf"; DestDir: "{app}"; Flags: ignoreversion

Source: "C:\Users\presh\c2f\dist\mistral_definition"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\phi3_definition"; DestDir: "{app}"; Flags: ignoreversion

; Include the Ollama setup binary
Source: "C:\Users\presh\c2f\dist\OllamaSetup.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall

; Include the batch file
Source: "C:\Users\presh\c2f\dist\run_ollama_commands.bat"; DestDir: "{app}"; Flags: ignoreversion

; Include other resources
Source: "C:\Users\presh\c2f\dist\menu.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\close.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\new_note.jpg"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\copy.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\send_icon.png"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\presh\c2f\dist\chat2find.jpeg"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{group}\Chat2Find"; Filename: "{app}\Chat2Find.exe"
Name: "{commondesktop}\Chat2Find"; Filename: "{app}\Chat2Find.exe"; Tasks: desktopicon

[Tasks]
Name: "desktopicon"; Description: "Create a &desktop icon"; GroupDescription: "Additional icons:"; Flags: checkedonce

[Run]
Filename: "{tmp}\OllamaSetup.exe"; Description: "Install Ollama"; Flags: waituntilterminated runhidden

; Run Ollama commands with command prompt visible
Filename: "{app}\run_ollama_commands.bat"; Parameters: ""; Flags: waituntilterminated runhidden

Filename: "{app}\Chat2Find.exe"; Description: "Launch Chat2Find"; Flags: postinstall
; Run Ollama setup silently

批处理文件必须如下所示:

@echo off
cd /d %~dp0
echo Running Ollama commands...

ollama create C2F_mistral -f mistral_definition
if %errorlevel% neq 0 (
    echo Failed to create C2F_mistral model
    exit /b %errorlevel%
)

ollama create C2F_phi3 -f phi3_definition
if %errorlevel% neq 0 (
    echo Failed to create C2F_phi3 model
    exit /b %errorlevel%
)

echo Ollama commands executed successfully. Deleting GGUF files...

del /f /q "Mistral-7B-Instruct-v0.3.Q4_K_M.gguf"
del /f /q "Phi-3-mini-4k-instruct-q4.gguf"

echo GGUF files deleted.
exit

记下我包含在脚本文件中的标志。这就是您获得您想要的东西的方式。

© www.soinside.com 2019 - 2024. All rights reserved.