Skip to content

Commit a672cb7

Browse files
committed
fix: corrects installer
1 parent d9e362a commit a672cb7

5 files changed

Lines changed: 136 additions & 31 deletions

File tree

deploy/linux/install.sh

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Usage:
66
# sudo ./install.sh [--grpc-port N] [--rest-port N] [--studio-port N]
77
# [--root-key KEY] [--source-url URL] [--data-dir DIR]
8+
# [--cert-path PATH] [--cert-password PASS]
89
# [--no-studio] [--non-interactive]
910
#
1011
# Without arguments the script runs interactively and prompts for each setting.
@@ -24,6 +25,8 @@ STUDIO_PORT=2628
2425
ROOT_KEY=""
2526
SOURCE_URL="https://github.com/EntglDb/BLite.Server"
2627
STUDIO_ENABLED="true"
28+
CERT_PATH=""
29+
CERT_PASSWORD=""
2730
NON_INTERACTIVE=false
2831

2932
# ── Colour helpers ────────────────────────────────────────────────────────────
@@ -42,6 +45,8 @@ while [[ $# -gt 0 ]]; do
4245
--source-url) SOURCE_URL="$2"; shift 2 ;;
4346
--data-dir) DATA_DIR="$2"; shift 2 ;;
4447
--no-studio) STUDIO_ENABLED="false"; shift ;;
48+
--cert-path) CERT_PATH="$2"; shift 2 ;;
49+
--cert-password) CERT_PASSWORD="$2"; shift 2 ;;
4550
--non-interactive) NON_INTERACTIVE=true; shift ;;
4651
*) error "Unknown option: $1"; exit 1 ;;
4752
esac
@@ -103,6 +108,17 @@ prompt SOURCE_URL "Source URL (AGPLv3 §13 compliance)" "$SOURCE_URL"
103108
prompt STUDIO_ENABLED "Enable Studio UI (true/false)" "$STUDIO_ENABLED"
104109
prompt DATA_DIR "Data directory" "$DATA_DIR"
105110

111+
# Optional TLS certificate (leave empty to use plain HTTP)
112+
if ! $NON_INTERACTIVE && [[ -z "$CERT_PATH" ]]; then
113+
read -rp "Certificate (.pfx/.pem) path [leave empty for plain HTTP]: " _cert_input
114+
CERT_PATH="${_cert_input:-}"
115+
if [[ -n "$CERT_PATH" ]]; then
116+
read -rsp "Certificate password [leave empty if none]: " _pass_input
117+
echo ""
118+
CERT_PASSWORD="${_pass_input:-}"
119+
fi
120+
fi
121+
106122
echo ""
107123
info "Installing BLite Server with the following settings:"
108124
echo " Install dir : $INSTALL_DIR"
@@ -112,6 +128,11 @@ echo " gRPC port : $GRPC_PORT"
112128
echo " REST port : $REST_PORT"
113129
echo " Studio port : $STUDIO_PORT"
114130
echo " Studio enabled: $STUDIO_ENABLED"
131+
if [[ -n "$CERT_PATH" ]]; then
132+
echo " Certificate : $CERT_PATH (HTTPS enabled)"
133+
else
134+
echo " TLS : disabled (plain HTTP)"
135+
fi
115136
echo " Source URL : $SOURCE_URL"
116137
echo ""
117138

@@ -145,6 +166,19 @@ chmod 750 "$DATA_DIR"
145166
info "Writing configuration to $CONFIG_DIR..."
146167
mkdir -p "$CONFIG_DIR"
147168

169+
# Determine protocol scheme and install certificate when provided
170+
if [[ -n "$CERT_PATH" ]]; then
171+
_SCHEME="https"
172+
_DEST_CERT="$CONFIG_DIR/server.pfx"
173+
cp "$CERT_PATH" "$_DEST_CERT"
174+
chown root:"$SERVICE_USER" "$_DEST_CERT"
175+
chmod 640 "$_DEST_CERT"
176+
info "Certificate installed at $_DEST_CERT"
177+
CERT_PATH="$_DEST_CERT"
178+
else
179+
_SCHEME="http"
180+
fi
181+
148182
# Environment file read by the systemd unit (EnvironmentFile=-/etc/blite-server/environment)
149183
cat > "$CONFIG_DIR/environment" <<EOF
150184
# BLite Server — site configuration
@@ -155,11 +189,11 @@ cat > "$CONFIG_DIR/environment" <<EOF
155189
Auth__RootKey=${ROOT_KEY}
156190
157191
# Kestrel endpoint URLs
158-
KESTREL__ENDPOINTS__GRPC__URL=http://*:${GRPC_PORT}
192+
KESTREL__ENDPOINTS__GRPC__URL=${_SCHEME}://*:${GRPC_PORT}
159193
KESTREL__ENDPOINTS__GRPC__PROTOCOLS=Http2
160-
KESTREL__ENDPOINTS__REST__URL=http://*:${REST_PORT}
194+
KESTREL__ENDPOINTS__REST__URL=${_SCHEME}://*:${REST_PORT}
161195
KESTREL__ENDPOINTS__REST__PROTOCOLS=Http1AndHttp2
162-
KESTREL__ENDPOINTS__STUDIO__URL=http://*:${STUDIO_PORT}
196+
KESTREL__ENDPOINTS__STUDIO__URL=${_SCHEME}://*:${STUDIO_PORT}
163197
KESTREL__ENDPOINTS__STUDIO__PROTOCOLS=Http1AndHttp2
164198
165199
# Data paths
@@ -175,6 +209,16 @@ LICENSE__SOURCEURL=${SOURCE_URL}
175209
ASPNETCORE_ENVIRONMENT=Production
176210
EOF
177211

212+
# Append TLS certificate settings when HTTPS is enabled
213+
if [[ -n "$CERT_PATH" ]]; then
214+
cat >> "$CONFIG_DIR/environment" <<EOFSSL
215+
216+
# TLS certificate
217+
KESTREL__CERTIFICATES__DEFAULT__PATH=${CERT_PATH}
218+
KESTREL__CERTIFICATES__DEFAULT__PASSWORD=${CERT_PASSWORD}
219+
EOFSSL
220+
fi
221+
178222
chmod 640 "$CONFIG_DIR/environment"
179223
chown root:"$SERVICE_USER" "$CONFIG_DIR/environment"
180224

@@ -224,10 +268,10 @@ echo -e "${GREEN}╔════════════════════
224268
echo -e "${GREEN}║ BLite Server installed and running successfully ║${NC}"
225269
echo -e "${GREEN}╚══════════════════════════════════════════════════╝${NC}"
226270
echo ""
227-
echo " gRPC → http://localhost:${GRPC_PORT}"
228-
echo " REST → http://localhost:${REST_PORT}"
271+
echo " gRPC ${_SCHEME}://localhost:${GRPC_PORT}"
272+
echo " REST ${_SCHEME}://localhost:${REST_PORT}"
229273
if [[ "$STUDIO_ENABLED" == "true" ]]; then
230-
echo " Studio → http://localhost:${STUDIO_PORT}"
274+
echo " Studio → ${_SCHEME}://localhost:${STUDIO_PORT}"
231275
fi
232276
echo ""
233277
echo " Service status : systemctl status blite-server"

deploy/windows/blite-server.iss

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
5757

5858
[Code]
5959
var
60-
ConfigPage: TInputQueryWizardPage;
61-
GrpcPort: String;
62-
RestPort: String;
63-
StudioPort: String;
64-
RootKey: String;
65-
SourceUrl: String;
66-
StudioCheck: TNewCheckBox;
60+
ConfigPage: TInputQueryWizardPage;
61+
SslPage: TInputQueryWizardPage;
62+
GrpcPort: String;
63+
RestPort: String;
64+
StudioPort: String;
65+
RootKey: String;
66+
SourceUrl: String;
67+
CertPath: String;
68+
CertPassword: String;
69+
StudioCheck: TNewCheckBox;
6770
6871
procedure InitializeWizard;
6972
var
@@ -103,6 +106,20 @@ begin
103106
StudioCheck.Top := StudioLabel.Top;
104107
StudioCheck.Left := StudioLabel.Left + StudioLabel.Width + 8;
105108
StudioCheck.Width := 80;
109+
110+
{ ── SSL / TLS page (optional) ──────────────────────────────────────────── }
111+
SslPage := CreateInputQueryPage(
112+
ConfigPage.ID,
113+
'HTTPS / TLS Configuration (optional)',
114+
'Provide a PFX certificate to enable HTTPS on all endpoints.',
115+
'Leave the certificate path empty to keep plain HTTP (recommended behind a reverse proxy).' + #13#10 +
116+
'When a certificate is provided, all Kestrel endpoints switch to https://.');
117+
118+
SslPage.Add('Certificate (.pfx) full path:', False);
119+
SslPage.Add('Certificate password:', True);
120+
121+
SslPage.Values[0] := '';
122+
SslPage.Values[1] := '';
106123
end;
107124
108125
{ Validate input before allowing Next }
@@ -144,6 +161,18 @@ begin
144161
Result := False; Exit;
145162
end;
146163
end;
164+
165+
if CurPageID = SslPage.ID then
166+
begin
167+
CertPath := Trim(SslPage.Values[0]);
168+
CertPassword := Trim(SslPage.Values[1]);
169+
170+
if (CertPath <> '') and not FileExists(CertPath) then
171+
begin
172+
MsgBox('Certificate file not found:' + #13#10 + CertPath, mbError, MB_OK);
173+
Result := False; Exit;
174+
end;
175+
end;
147176
end;
148177
149178
{ Escape a string for embedding inside a JSON value }
@@ -167,14 +196,36 @@ end;
167196
{ Write appsettings.Production.json after all files are copied }
168197
procedure WriteAppSettings;
169198
var
170-
Path: String;
171-
Content: String;
172-
Studio: String;
199+
FilePath: String;
200+
Content: String;
201+
Studio: String;
202+
Scheme: String;
203+
CertSection: String;
173204
begin
174-
Path := ExpandConstant('{app}\appsettings.Production.json');
205+
FilePath := ExpandConstant('{app}\appsettings.Production.json');
175206
176207
if StudioCheck.Checked then Studio := 'true' else Studio := 'false';
177208
209+
{ Switch between http and https based on whether a certificate was provided }
210+
if CertPath <> '' then
211+
begin
212+
Scheme := 'https';
213+
CertSection :=
214+
' "Kestrel": {' + #13#10 +
215+
' "Certificates": {' + #13#10 +
216+
' "Default": {' + #13#10 +
217+
' "Path": "' + JsonEscape(CertPath) + '",' + #13#10 +
218+
' "Password": "' + JsonEscape(CertPassword) + '"' + #13#10 +
219+
' }' + #13#10 +
220+
' },' + #13#10 +
221+
' "Endpoints": {';
222+
end
223+
else
224+
begin
225+
Scheme := 'http';
226+
CertSection := ' "Kestrel": {' + #13#10 + ' "Endpoints": {';
227+
end;
228+
178229
Content :=
179230
'{' + #13#10 +
180231
' "Auth": {' + #13#10 +
@@ -184,18 +235,17 @@ begin
184235
' "DatabasePath": "data\\blite.db",' + #13#10 +
185236
' "DatabasesDirectory": "data\\tenants"' + #13#10 +
186237
' },' + #13#10 +
187-
' "Kestrel": {' + #13#10 +
188-
' "Endpoints": {' + #13#10 +
238+
CertSection + #13#10 +
189239
' "Grpc": {' + #13#10 +
190-
' "Url": "http://*:' + GrpcPort + '",' + #13#10 +
240+
' "Url": "' + Scheme + '://*:' + GrpcPort + '",' + #13#10 +
191241
' "Protocols": "Http2"' + #13#10 +
192242
' },' + #13#10 +
193243
' "Rest": {' + #13#10 +
194-
' "Url": "http://*:' + RestPort + '",' + #13#10 +
244+
' "Url": "' + Scheme + '://*:' + RestPort + '",' + #13#10 +
195245
' "Protocols": "Http1AndHttp2"' + #13#10 +
196246
' },' + #13#10 +
197247
' "Studio": {' + #13#10 +
198-
' "Url": "http://*:' + StudioPort + '",' + #13#10 +
248+
' "Url": "' + Scheme + '://*:' + StudioPort + '",' + #13#10 +
199249
' "Protocols": "Http1AndHttp2"' + #13#10 +
200250
' }' + #13#10 +
201251
' }' + #13#10 +
@@ -208,7 +258,7 @@ begin
208258
' }' + #13#10 +
209259
'}' + #13#10;
210260
211-
SaveStringToFile(Path, Content, False);
261+
SaveStringToFile(FilePath, Content, False);
212262
end;
213263
214264
procedure CurStepChanged(CurStep: TSetupStep);

src/BLite.Server/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@
3030
builder.Host.UseSystemd();
3131

3232
// ── Configuration ─────────────────────────────────────────────────────────────
33+
// When running as a Windows Service the working directory is C:\Windows\System32.
34+
// Always resolve relative paths against the executable's directory so that the
35+
// database and tenant files end up next to the binary regardless of how the
36+
// process was started.
37+
static string ResolveAppPath(string path) =>
38+
Path.IsPathRooted(path)
39+
? path
40+
: Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, path));
41+
3342
var serverConfig = builder.Configuration.GetSection("BLiteServer");
34-
var dbPath = serverConfig.GetValue<string>("DatabasePath") ?? "blite.db";
35-
var databasesDir = serverConfig.GetValue<string>("DatabasesDirectory") ?? "data/tenants";
43+
var dbPath = ResolveAppPath(serverConfig.GetValue<string>("DatabasePath") ?? "blite.db");
44+
var databasesDir = ResolveAppPath(serverConfig.GetValue<string>("DatabasesDirectory") ?? "data/tenants");
3645
var pageSizeBytes = serverConfig.GetValue<int>("MaxPageSizeBytes");
3746
if (pageSizeBytes <= 0) pageSizeBytes = 16384;
3847
var pageConfig = new PageFileConfig

src/BLite.Server/Studio/SetupService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ public sealed class SetupService
2020

2121
public SetupService(IConfiguration config)
2222
{
23-
var dbPath = config.GetValue<string>("BLiteServer:DatabasePath") ?? "blite.db";
24-
var dir = Path.GetDirectoryName(Path.GetFullPath(dbPath))
25-
?? Directory.GetCurrentDirectory();
23+
var raw = config.GetValue<string>("BLiteServer:DatabasePath") ?? "blite.db";
24+
var dbPath = Path.IsPathRooted(raw)
25+
? raw
26+
: Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, raw));
27+
var dir = Path.GetDirectoryName(dbPath) ?? AppContext.BaseDirectory;
2628
_markerPath = Path.Combine(dir, "server-setup.json");
2729
}
2830

src/BLite.Server/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
"Kestrel": {
3333
"Endpoints": {
3434
"Grpc": {
35-
"Url": "https://*:2626",
35+
"Url": "http://*:2626",
3636
"Protocols": "Http2"
3737
},
3838
"Rest": {
39-
"Url": "https://*:2627",
39+
"Url": "http://*:2627",
4040
"Protocols": "Http1AndHttp2"
4141
},
4242
"Studio": {
43-
"Url": "https://*:2628",
43+
"Url": "http://*:2628",
4444
"Protocols": "Http1AndHttp2"
4545
}
4646
}

0 commit comments

Comments
 (0)