Skip to content

Commit cabca01

Browse files
committed
workstation-v0: add Lampstand provisioning helper
1 parent 3a2d9cd commit cabca01

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Install Lampstand for workstation-v0 and optionally enable a user service.
5+
# Strategy:
6+
# - prefer a local checkout at ~/dev/lampstand (or SOURCEOS_LAMPSTAND_SRC)
7+
# - otherwise install from the public git URL via pipx
8+
# - write a user systemd unit for lampstandd if the daemon entrypoint exists
9+
10+
info(){ printf "INFO: %s\n" "$*" >&2; }
11+
warn(){ printf "WARN: %s\n" "$*" >&2; }
12+
err(){ printf "ERROR: %s\n" "$*" >&2; }
13+
14+
have(){ command -v "$1" >/dev/null 2>&1; }
15+
16+
lampstand_src(){
17+
local local_src="${SOURCEOS_LAMPSTAND_SRC:-$HOME/dev/lampstand}"
18+
if [[ -f "$local_src/pyproject.toml" ]]; then
19+
printf '%s\n' "$local_src"
20+
return
21+
fi
22+
printf '%s\n' 'git+https://github.com/SocioProphet/lampstand.git'
23+
}
24+
25+
ensure_pipx(){
26+
if have pipx; then
27+
return 0
28+
fi
29+
if have brew; then
30+
info "Installing pipx via brew (best-effort)"
31+
brew install pipx || true
32+
fi
33+
have pipx
34+
}
35+
36+
install_lampstand(){
37+
local src
38+
src="$(lampstand_src)"
39+
info "Installing Lampstand via pipx from: $src"
40+
pipx install --force "$src"
41+
}
42+
43+
write_user_service(){
44+
local bin="$HOME/.local/bin/lampstandd"
45+
if [[ ! -x "$bin" ]]; then
46+
warn "lampstandd not found at $bin; skipping user service"
47+
return 0
48+
fi
49+
50+
local svc_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
51+
local svc="$svc_dir/sourceos-lampstand.service"
52+
mkdir -p "$svc_dir"
53+
54+
cat > "$svc" <<'EOF'
55+
[Unit]
56+
Description=SourceOS Lampstand search daemon
57+
After=graphical-session.target
58+
PartOf=graphical-session.target
59+
60+
[Service]
61+
Type=simple
62+
ExecStart=%h/.local/bin/lampstandd --root %h --rpc unixjson
63+
Restart=on-failure
64+
RestartSec=2
65+
66+
[Install]
67+
WantedBy=default.target
68+
EOF
69+
70+
info "wrote user service: $svc"
71+
72+
if have systemctl; then
73+
systemctl --user daemon-reload || true
74+
systemctl --user enable sourceos-lampstand.service || true
75+
systemctl --user restart sourceos-lampstand.service || true
76+
fi
77+
}
78+
79+
main(){
80+
if ! ensure_pipx; then
81+
warn "pipx is not available; skipping Lampstand install"
82+
exit 0
83+
fi
84+
85+
install_lampstand || {
86+
warn "Lampstand install failed (non-fatal)"
87+
exit 0
88+
}
89+
90+
write_user_service || warn "Lampstand user service setup failed (non-fatal)"
91+
}
92+
93+
main "$@"

0 commit comments

Comments
 (0)