5252 This installs the selected release from:
5353 ${GITHUB_URL} /releases/tag/${RELEASE_TAG}
5454
55- Linux installs the Debian package on amd64 and arm64.
55+ Linux installs the Debian package on Debian/Ubuntu, or RPM packages on
56+ Fedora/RHEL, for amd64/x86_64 and arm64/aarch64.
5657 macOS installs the release Homebrew formula on Apple Silicon and starts a
5758 brew services-backed local gateway.
5859EOF
@@ -186,8 +187,18 @@ detect_platform() {
186187 esac
187188}
188189
189- check_linux_platform () {
190- require_cmd dpkg
190+ detect_linux_package_format () {
191+ if has_cmd dpkg; then
192+ echo " deb"
193+ return 0
194+ fi
195+
196+ if has_cmd rpm; then
197+ echo " rpm"
198+ return 0
199+ fi
200+
201+ error " Linux dev installs require either 'dpkg' or 'rpm'"
191202}
192203
193204check_macos_platform () {
@@ -227,7 +238,46 @@ find_deb_asset() {
227238 _arch=" $2 "
228239
229240 awk -v arch=" $_arch " '
230- $2 ~ "^\\*?openshell_.*_" arch "\\.deb$" {
241+ $2 ~ "^\\*?openshell[-_].*[-_]" arch "\\.deb$" {
242+ sub("^\\*", "", $2)
243+ print $2
244+ exit
245+ }
246+ ' " $_checksums "
247+ }
248+
249+ get_rpm_arch () {
250+ _arch=" "
251+ if has_cmd rpm; then
252+ _arch=" $( rpm --eval ' %{_arch}' 2> /dev/null || true) "
253+ fi
254+ if [ -z " $_arch " ]; then
255+ _arch=" $( uname -m) "
256+ fi
257+
258+ case " $_arch " in
259+ x86_64|aarch64)
260+ echo " $_arch "
261+ ;;
262+ amd64)
263+ echo " x86_64"
264+ ;;
265+ arm64)
266+ echo " aarch64"
267+ ;;
268+ * )
269+ error " no dev RPM package is published for architecture: ${_arch} "
270+ ;;
271+ esac
272+ }
273+
274+ find_rpm_asset () {
275+ _checksums=" $1 "
276+ _prefix=" $2 "
277+ _arch=" $3 "
278+
279+ awk -v prefix=" $_prefix " -v arch=" $_arch " '
280+ $2 ~ "^\\*?" prefix ".*-" arch "\\.rpm$" {
231281 sub("^\\*", "", $2)
232282 print $2
233283 exit
@@ -271,6 +321,61 @@ install_deb_package() {
271321 fi
272322}
273323
324+ install_rpm_packages () {
325+ if has_cmd dnf; then
326+ as_root dnf install -y " $@ "
327+ elif has_cmd yum; then
328+ as_root yum install -y " $@ "
329+ elif has_cmd rpm; then
330+ as_root rpm -Uvh --replacepkgs " $@ "
331+ else
332+ error " neither 'dnf', 'yum', nor 'rpm' found; cannot install RPM packages"
333+ fi
334+ }
335+
336+ ensure_local_gateway_env () {
337+ _config_dir=" ${TARGET_HOME} /.config/openshell"
338+ _env_file=" ${_config_dir} /gateway.env"
339+
340+ # shellcheck disable=SC2016
341+ as_target_user sh -c '
342+ env_file=$1
343+ port=$2
344+
345+ mkdir -p "$(dirname "$env_file")"
346+ touch "$env_file"
347+ chmod 600 "$env_file"
348+
349+ add_var() {
350+ key=$1
351+ value=$2
352+ if ! grep -Eq "^[[:space:]]*${key}=" "$env_file"; then
353+ printf "%s=%s\n" "$key" "$value" >>"$env_file"
354+ fi
355+ }
356+
357+ if ! grep -Eq "^[[:space:]]*OPENSHELL_SSH_HANDSHAKE_SECRET=" "$env_file"; then
358+ if command -v openssl >/dev/null 2>&1; then
359+ secret="$(openssl rand -hex 32)"
360+ elif command -v od >/dev/null 2>&1; then
361+ secret="$(od -An -tx1 -N32 /dev/urandom | tr -d " \n")"
362+ else
363+ echo "openshell: error: openssl or od is required to generate OPENSHELL_SSH_HANDSHAKE_SECRET" >&2
364+ exit 1
365+ fi
366+ printf "%s=%s\n" OPENSHELL_SSH_HANDSHAKE_SECRET "$secret" >>"$env_file"
367+ fi
368+
369+ add_var OPENSHELL_BIND_ADDRESS 127.0.0.1
370+ add_var OPENSHELL_SERVER_PORT "$port"
371+ add_var OPENSHELL_DISABLE_TLS true
372+ add_var OPENSHELL_DISABLE_GATEWAY_AUTH true
373+ add_var OPENSHELL_GRPC_ENDPOINT "http://127.0.0.1:${port}"
374+ add_var OPENSHELL_SSH_GATEWAY_HOST 127.0.0.1
375+ add_var OPENSHELL_SSH_GATEWAY_PORT "$port"
376+ ' sh " $_env_file " " $LOCAL_GATEWAY_PORT "
377+ }
378+
274379homebrew_formula_path () {
275380 _tap=" $1 "
276381 _formula=" $2 "
@@ -303,9 +408,11 @@ start_user_gateway() {
303408 info " restarting openshell-gateway user service as ${TARGET_USER} ..."
304409
305410 if ! as_target_user systemctl --user daemon-reload; then
306- info " could not reach the user systemd manager for ${TARGET_USER} "
307- info " restart the gateway later with: systemctl --user enable openshell-gateway && systemctl --user restart openshell-gateway"
308- info " then register it with: openshell gateway add http://127.0.0.1:17670 --local --name local"
411+ warn " could not reach the user systemd manager for ${TARGET_USER} "
412+ start_direct_gateway
413+ info " registering local gateway as ${TARGET_USER} ..."
414+ register_local_gateway
415+ wait_for_registered_gateway
309416 return 0
310417 fi
311418
@@ -315,6 +422,73 @@ start_user_gateway() {
315422
316423 info " registering local gateway as ${TARGET_USER} ..."
317424 register_local_gateway
425+ wait_for_registered_gateway
426+ }
427+
428+ start_direct_gateway () {
429+ _gateway_bin=" ${OPENSHELL_GATEWAY_BIN:- openshell-gateway} "
430+ _config_dir=" ${TARGET_HOME} /.config/openshell"
431+ _env_file=" ${_config_dir} /gateway.env"
432+ _state_home=" ${XDG_STATE_HOME:- ${TARGET_HOME} / .local/ state} "
433+ _state_dir=" ${_state_home} /openshell/gateway"
434+ _pid_file=" ${_state_dir} /openshell-gateway.pid"
435+ _log_file=" ${_state_dir} /openshell-gateway.log"
436+
437+ info " starting openshell-gateway directly as ${TARGET_USER} ..."
438+
439+ # shellcheck disable=SC2016
440+ as_target_user sh -c '
441+ gateway_bin=$1
442+ env_file=$2
443+ state_dir=$3
444+ pid_file=$4
445+ log_file=$5
446+ port=$6
447+
448+ if [ -f "$pid_file" ] && kill -0 "$(cat "$pid_file")" 2>/dev/null; then
449+ exit 0
450+ fi
451+
452+ mkdir -p "$state_dir"
453+
454+ export OPENSHELL_BIND_ADDRESS="${OPENSHELL_BIND_ADDRESS:-127.0.0.1}"
455+ export OPENSHELL_SERVER_PORT="${OPENSHELL_SERVER_PORT:-$port}"
456+ export OPENSHELL_DISABLE_TLS="${OPENSHELL_DISABLE_TLS:-true}"
457+ export OPENSHELL_DISABLE_GATEWAY_AUTH="${OPENSHELL_DISABLE_GATEWAY_AUTH:-true}"
458+ export OPENSHELL_DB_URL="${OPENSHELL_DB_URL:-sqlite:${state_dir}/openshell.db?mode=rwc}"
459+ export OPENSHELL_GRPC_ENDPOINT="${OPENSHELL_GRPC_ENDPOINT:-http://127.0.0.1:${port}}"
460+ export OPENSHELL_SSH_GATEWAY_HOST="${OPENSHELL_SSH_GATEWAY_HOST:-127.0.0.1}"
461+ export OPENSHELL_SSH_GATEWAY_PORT="${OPENSHELL_SSH_GATEWAY_PORT:-$port}"
462+
463+ if [ -f "$env_file" ]; then
464+ set -a
465+ . "$env_file"
466+ set +a
467+ fi
468+
469+ nohup "$gateway_bin" >"$log_file" 2>&1 &
470+ printf "%s\n" "$!" >"$pid_file"
471+ ' sh " $_gateway_bin " " $_env_file " " $_state_dir " " $_pid_file " " $_log_file " " $LOCAL_GATEWAY_PORT "
472+ }
473+
474+ wait_for_registered_gateway () {
475+ _status_bin=" ${OPENSHELL_REGISTER_BIN:- openshell} "
476+ _timeout=" ${OPENSHELL_INSTALL_GATEWAY_TIMEOUT:- 30} "
477+ _elapsed=0
478+ _last_output=" "
479+
480+ info " waiting for local gateway to become reachable..."
481+ while [ " $_elapsed " -lt " $_timeout " ]; do
482+ if _last_output=" $( as_target_user " $_status_bin " status 2>&1 ) " ; then
483+ info " local gateway is reachable"
484+ return 0
485+ fi
486+ sleep 1
487+ _elapsed=$(( _elapsed + 1 ))
488+ done
489+
490+ printf ' %s\n' " $_last_output " >&2
491+ error " local gateway did not become reachable within ${_timeout} s"
318492}
319493
320494remove_local_gateway_registration () {
@@ -358,8 +532,6 @@ register_local_gateway() {
358532}
359533
360534install_linux_deb () {
361- check_linux_platform
362-
363535 if [ " $( id -u) " -eq " $TARGET_UID " ] && [ -n " ${XDG_RUNTIME_DIR:- } " ]; then
364536 TARGET_RUNTIME_DIR=" $XDG_RUNTIME_DIR "
365537 else
@@ -399,6 +571,56 @@ install_linux_deb() {
399571 info " installing ${_deb_file} ..."
400572 install_deb_package " $_deb_path "
401573 info " installed ${APP_NAME} package from ${RELEASE_TAG} "
574+ ensure_local_gateway_env
575+ start_user_gateway
576+ }
577+
578+ install_linux_rpm () {
579+ if [ " $( id -u) " -eq " $TARGET_UID " ] && [ -n " ${XDG_RUNTIME_DIR:- } " ]; then
580+ TARGET_RUNTIME_DIR=" $XDG_RUNTIME_DIR "
581+ else
582+ TARGET_RUNTIME_DIR=" /run/user/${TARGET_UID} "
583+ fi
584+
585+ _arch=" $( get_rpm_arch) "
586+ _tmpdir=" $( mktemp -d) "
587+ chmod 0755 " $_tmpdir "
588+ trap ' rm -rf "$_tmpdir"' EXIT
589+
590+ _checksums_url=" ${GITHUB_URL} /releases/download/${RELEASE_TAG} /${CHECKSUMS_NAME} "
591+ info " downloading ${RELEASE_TAG} release checksums..."
592+ download " $_checksums_url " " ${_tmpdir} /${CHECKSUMS_NAME} " || {
593+ error " failed to download ${_checksums_url} "
594+ }
595+
596+ _cli_rpm_file=" $( find_rpm_asset " ${_tmpdir} /${CHECKSUMS_NAME} " " openshell-dev" " $_arch " ) "
597+ if [ -z " $_cli_rpm_file " ]; then
598+ error " no dev CLI RPM package found for architecture: ${_arch} "
599+ fi
600+
601+ _gateway_rpm_file=" $( find_rpm_asset " ${_tmpdir} /${CHECKSUMS_NAME} " " openshell-gateway-dev" " $_arch " ) "
602+ if [ -z " $_gateway_rpm_file " ]; then
603+ error " no dev gateway RPM package found for architecture: ${_arch} "
604+ fi
605+
606+ info " selected ${_cli_rpm_file} and ${_gateway_rpm_file} "
607+
608+ for _rpm_file in " $_cli_rpm_file " " $_gateway_rpm_file " ; do
609+ _rpm_path=" ${_tmpdir} /${_rpm_file} "
610+ info " downloading ${_rpm_file} ..."
611+ download_release_asset " $RELEASE_TAG " " $_rpm_file " " $_rpm_path " || {
612+ error " failed to download ${GITHUB_URL} /releases/download/${RELEASE_TAG} /${_rpm_file} "
613+ }
614+ chmod 0644 " $_rpm_path "
615+
616+ info " verifying checksum for ${_rpm_file} ..."
617+ verify_checksum " $_rpm_path " " ${_tmpdir} /${CHECKSUMS_NAME} " " $_rpm_file "
618+ done
619+
620+ info " installing ${_cli_rpm_file} and ${_gateway_rpm_file} ..."
621+ install_rpm_packages " ${_tmpdir} /${_cli_rpm_file} " " ${_tmpdir} /${_gateway_rpm_file} "
622+ info " installed ${APP_NAME} RPM packages from ${RELEASE_TAG} "
623+ ensure_local_gateway_env
402624 start_user_gateway
403625}
404626
@@ -477,7 +699,14 @@ main() {
477699
478700 case " $PLATFORM " in
479701 linux)
480- install_linux_deb
702+ case " $( detect_linux_package_format) " in
703+ deb)
704+ install_linux_deb
705+ ;;
706+ rpm)
707+ install_linux_rpm
708+ ;;
709+ esac
481710 ;;
482711 darwin)
483712 install_macos_homebrew
0 commit comments