Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/workstation-lampstand.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,41 @@ jobs:
grep -F '"documents": 1' "$stats_out" >/dev/null

PATH="$stub_bin:$PATH" bash "$helper" index --root "$tmp_dir" >/dev/null

- name: Smoke: sourceos-search user service commands with stub systemctl
run: |
set -euo pipefail
helper='profiles/linux-dev/workstation-v0/bin/sourceos-search.sh'
stub_bin=$(mktemp -d)
cat > "$stub_bin/systemctl" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
test "${1:-}" = --user
shift
case "${1:-}" in
status)
printf 'sourceos-lampstand.service active\n'
;;
start|stop|restart|enable)
printf 'systemctl --user %s %s\n' "$1" "${2:-}"
;;
*)
printf 'unexpected systemctl args: %s\n' "$*" >&2
exit 2
;;
esac
EOF
cat > "$stub_bin/journalctl" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
printf 'lampstand log line\n'
EOF
chmod +x "$stub_bin/systemctl" "$stub_bin/journalctl"

tmp_dir=$(mktemp -d)
PATH="$stub_bin:$PATH" bash "$helper" service status --write "$tmp_dir/status.txt"
grep -F 'sourceos-lampstand.service active' "$tmp_dir/status.txt" >/dev/null
PATH="$stub_bin:$PATH" bash "$helper" service restart >/dev/null
PATH="$stub_bin:$PATH" bash "$helper" service enable >/dev/null
PATH="$stub_bin:$PATH" bash "$helper" service logs --write "$tmp_dir/logs.txt"
grep -F 'lampstand log line' "$tmp_dir/logs.txt" >/dev/null
5 changes: 4 additions & 1 deletion profiles/linux-dev/workstation-v0/bin/sourceos
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Usage:
sourceos fix fish [apply|dry-run|revert] [--json] [--open|--write <path>]
sourceos doctor [--json|--open|--write <path>]
sourceos status [--json|--open|--write <path>]
sourceos search [health|stats|index] [options]
sourceos search [health|stats|index|service] [options]
sourceos search [--limit N] [--snippet] [--prompt] [--open|--write <path>] [query...]
sourceos profile apply
sourceos profile path
Expand Down Expand Up @@ -477,6 +477,9 @@ Search files (Lampstand) sourceos search --prompt --snippet --open
Lampstand health (open report) sourceos search health --open
Lampstand stats (open report) sourceos search stats --open
Lampstand index home sourceos search index --root "$HOME"
Lampstand service status sourceos search service status --open
Lampstand service restart sourceos search service restart
Lampstand service logs sourceos search service logs --open
Apply profile sourceos profile apply
Open sesh sesh
Open tmux tmux
Expand Down
43 changes: 43 additions & 0 deletions profiles/linux-dev/workstation-v0/bin/sourceos-search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ warn(){ printf "WARN: %s\n" "$*" >&2; }
have(){ command -v "$1" >/dev/null 2>&1; }

cache_dir(){ echo "${XDG_CACHE_HOME:-$HOME/.cache}/sourceos"; }
service_name(){ echo "sourceos-lampstand.service"; }

open_file(){
local p=$1
Expand All @@ -26,13 +27,39 @@ run_lampstand(){
return 127
}

run_user_service(){
local action=$1
local svc
svc="$(service_name)"

case "$action" in
status)
systemctl --user status "$svc" --no-pager
;;
start|stop|restart)
systemctl --user "$action" "$svc"
;;
enable)
systemctl --user enable "$svc"
;;
logs)
journalctl --user -u "$svc" --no-pager -n 200
;;
*)
err "unknown service action: $action (use status|start|stop|restart|enable|logs)"
return 2
;;
esac
}

usage(){
cat <<'EOF'
Usage:
sourceos-search.sh [--limit N] [--snippet] [--prompt] [--open|--write <path>] [query...]
sourceos-search.sh health [--open|--write <path>]
sourceos-search.sh stats [--open|--write <path>]
sourceos-search.sh index [--root <path>]...
sourceos-search.sh service status|start|stop|restart|enable|logs [--open|--write <path>]
EOF
}

Expand All @@ -59,12 +86,20 @@ SEARCH_WRITE_PATH=""
QUERY_PARTS=()
LAMPSTAND_ROOTS=()
MODE="query"
SERVICE_ACTION=""

case "${1:-}" in
health|stats|index)
MODE="$1"
shift
;;
service)
MODE="service"
shift
SERVICE_ACTION="${1:-}"
[[ -n "$SERVICE_ACTION" ]] || { err "service requires an action"; usage; exit 2; }
shift || true
;;
esac

while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -100,6 +135,14 @@ case "$MODE" in
run_lampstand "${args[@]}"
exit $?
;;
service)
set +e
out="$(run_user_service "$SERVICE_ACTION" 2>&1)"
rc=$?
set -e
write_or_print "$out" "lampstand-service-$SERVICE_ACTION.txt"
exit "$rc"
;;
esac

if [[ ${#QUERY_PARTS[@]} -eq 0 && "$SEARCH_PROMPT" == "1" ]]; then
Expand Down