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
2425ROOT_KEY=" "
2526SOURCE_URL=" https://github.com/EntglDb/BLite.Server"
2627STUDIO_ENABLED=" true"
28+ CERT_PATH=" "
29+ CERT_PASSWORD=" "
2730NON_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"
103108prompt STUDIO_ENABLED " Enable Studio UI (true/false)" " $STUDIO_ENABLED "
104109prompt 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+
106122echo " "
107123info " Installing BLite Server with the following settings:"
108124echo " Install dir : $INSTALL_DIR "
@@ -112,6 +128,11 @@ echo " gRPC port : $GRPC_PORT"
112128echo " REST port : $REST_PORT "
113129echo " Studio port : $STUDIO_PORT "
114130echo " 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
115136echo " Source URL : $SOURCE_URL "
116137echo " "
117138
@@ -145,6 +166,19 @@ chmod 750 "$DATA_DIR"
145166info " Writing configuration to $CONFIG_DIR ..."
146167mkdir -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)
149183cat > " $CONFIG_DIR /environment" << EOF
150184# BLite Server — site configuration
@@ -155,11 +189,11 @@ cat > "$CONFIG_DIR/environment" <<EOF
155189Auth__RootKey=${ROOT_KEY}
156190
157191# Kestrel endpoint URLs
158- KESTREL__ENDPOINTS__GRPC__URL=http ://*:${GRPC_PORT}
192+ KESTREL__ENDPOINTS__GRPC__URL=${_SCHEME} ://*:${GRPC_PORT}
159193KESTREL__ENDPOINTS__GRPC__PROTOCOLS=Http2
160- KESTREL__ENDPOINTS__REST__URL=http ://*:${REST_PORT}
194+ KESTREL__ENDPOINTS__REST__URL=${_SCHEME} ://*:${REST_PORT}
161195KESTREL__ENDPOINTS__REST__PROTOCOLS=Http1AndHttp2
162- KESTREL__ENDPOINTS__STUDIO__URL=http ://*:${STUDIO_PORT}
196+ KESTREL__ENDPOINTS__STUDIO__URL=${_SCHEME} ://*:${STUDIO_PORT}
163197KESTREL__ENDPOINTS__STUDIO__PROTOCOLS=Http1AndHttp2
164198
165199# Data paths
@@ -175,6 +209,16 @@ LICENSE__SOURCEURL=${SOURCE_URL}
175209ASPNETCORE_ENVIRONMENT=Production
176210EOF
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+
178222chmod 640 " $CONFIG_DIR /environment"
179223chown root:" $SERVICE_USER " " $CONFIG_DIR /environment"
180224
@@ -224,10 +268,10 @@ echo -e "${GREEN}╔════════════════════
224268echo -e " ${GREEN} ║ BLite Server installed and running successfully ║${NC} "
225269echo -e " ${GREEN} ╚══════════════════════════════════════════════════╝${NC} "
226270echo " "
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} "
229273if [[ " $STUDIO_ENABLED " == " true" ]]; then
230- echo " Studio → http ://localhost:${STUDIO_PORT} "
274+ echo " Studio → ${_SCHEME} ://localhost:${STUDIO_PORT} "
231275fi
232276echo " "
233277echo " Service status : systemctl status blite-server"
0 commit comments