diff options
| author | salmon <salmonik@tuta.io> | 2026-08-09 23:28:12 +0200 |
|---|---|---|
| committer | salmon <salmonik@tuta.io> | 2026-08-09 23:28:12 +0200 |
| commit | da4147a8ca2ed92556eb56061a63e0cccb1984ce (patch) | |
| tree | f6135a996a5dc53bdbf1a0166fb7234f37baa1c5 | |
| parent | Document FreeBSD requirements in README (diff) | |
| download | rsplayer-da4147a8ca2ed92556eb56061a63e0cccb1984ce.tar.gz rsplayer-da4147a8ca2ed92556eb56061a63e0cccb1984ce.zip | |
Add FreeBSD rc.d service, install completions only for installed shells
| -rw-r--r-- | README.md | 14 | ||||
| -rwxr-xr-x | install.sh | 103 | ||||
| -rwxr-xr-x | rsplayer.rc | 72 |
3 files changed, 147 insertions, 42 deletions
| @@ -31,9 +31,19 @@ cargo build --release | |||
| 31 | install -m 755 target/release/rsp /usr/local/bin/rsp | 31 | install -m 755 target/release/rsp /usr/local/bin/rsp |
| 32 | ``` | 32 | ``` |
| 33 | 33 | ||
| 34 | `install.sh` does all of the above on FreeBSD and additionally installs an rc.d | ||
| 35 | service. Enable it with: | ||
| 36 | ``` | ||
| 37 | sudo sysrc rsplayer_enable=YES | ||
| 38 | sudo sysrc rsplayer_user=salmon # the user that runs the rsp CLI | ||
| 39 | sudo service rsplayer start | ||
| 40 | ``` | ||
| 41 | |||
| 34 | FreeBSD notes: | 42 | FreeBSD notes: |
| 35 | - There is no systemd: run `rsp start-daemon` manually, from your login shell, | 43 | - There is no systemd: the rc.d service (rsplayer.rc) runs `rsp start-daemon` |
| 36 | or via an rc.d script. `start-daemon`/`stop-daemon`/`restart` behave the same. | 44 | as rsplayer_user via daemon(8); `service rsplayer status`/`stop`/`restart` |
| 45 | work as expected. You can also run `rsp start-daemon` manually from your | ||
| 46 | login shell — `start-daemon`/`stop-daemon`/`restart` behave the same. | ||
| 37 | - XDG_RUNTIME_DIR is not set by default on FreeBSD, so the daemon socket and PID | 47 | - XDG_RUNTIME_DIR is not set by default on FreeBSD, so the daemon socket and PID |
| 38 | file fall back to /tmp/rsplayer/. Set XDG_RUNTIME_DIR in your rc.d script or | 48 | file fall back to /tmp/rsplayer/. Set XDG_RUNTIME_DIR in your rc.d script or |
| 39 | shell profile if you prefer a private runtime dir. | 49 | shell profile if you prefer a private runtime dir. |
| @@ -19,52 +19,75 @@ echo "Stopping existing daemon..." | |||
| 19 | systemctl --user stop rsplayer 2>/dev/null || true | 19 | systemctl --user stop rsplayer 2>/dev/null || true |
| 20 | rsp stop-daemon 2>/dev/null || true | 20 | rsp stop-daemon 2>/dev/null || true |
| 21 | 21 | ||
| 22 | echo "Installing to /usr/bin/rsp..." | 22 | if [ "$(uname -s)" = "FreeBSD" ]; then |
| 23 | sudo install target/release/rsp /usr/bin/rsp | 23 | BIN="/usr/local/bin/rsp" |
| 24 | echo "Installing to ${BIN}..." | ||
| 25 | sudo install target/release/rsp "${BIN}" | ||
| 24 | 26 | ||
| 25 | echo "" | 27 | echo "" |
| 26 | echo "Installing systemd service..." | 28 | echo "Installing rc.d service..." |
| 27 | mkdir -p ~/.config/systemd/user | 29 | sudo install -m 755 rsplayer.rc /usr/local/etc/rc.d/rsplayer |
| 28 | cp rsplayer.service ~/.config/systemd/user/ | 30 | echo "Service installed. Enable it with:" |
| 29 | 31 | echo " sudo sysrc rsplayer_enable=YES" | |
| 30 | if systemctl --user is-active default.target &>/dev/null; then | 32 | echo " sudo sysrc rsplayer_user=$USER # the user that runs the rsp CLI" |
| 31 | systemctl --user daemon-reload | 33 | echo " sudo service rsplayer start" |
| 32 | echo "Activating the daemon…" | ||
| 33 | systemctl --user restart --now rsplayer.service | ||
| 34 | else | 34 | else |
| 35 | echo "Service installed but not enabled (no user session running)" | 35 | echo "Installing to /usr/bin/rsp..." |
| 36 | echo "To enable later when logged in: systemctl --user enable rsplayer" | 36 | sudo install target/release/rsp /usr/bin/rsp |
| 37 | |||
| 38 | echo "" | ||
| 39 | echo "Installing systemd service..." | ||
| 40 | mkdir -p ~/.config/systemd/user | ||
| 41 | cp rsplayer.service ~/.config/systemd/user/ | ||
| 42 | |||
| 43 | if systemctl --user is-active default.target &>/dev/null; then | ||
| 44 | systemctl --user daemon-reload | ||
| 45 | echo "Activating the daemon…" | ||
| 46 | systemctl --user restart --now rsplayer.service | ||
| 47 | else | ||
| 48 | echo "Service installed but not enabled (no user session running)" | ||
| 49 | echo "To enable later when logged in: systemctl --user enable rsplayer" | ||
| 50 | fi | ||
| 37 | fi | 51 | fi |
| 38 | 52 | ||
| 39 | echo "" | 53 | echo "" |
| 40 | echo "Installing shell completions..." | 54 | echo "Installing shell completions (only for shells that are installed)..." |
| 41 | shell_name=$(basename "${SHELL:-}") | 55 | found=0 |
| 42 | case "$shell_name" in | 56 | |
| 43 | bash) | 57 | if command -v bash >/dev/null 2>&1; then |
| 44 | dest="${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions" | 58 | dest="${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions" |
| 45 | mkdir -p "$dest" | 59 | mkdir -p "$dest" |
| 46 | cp completions/rsp.bash "$dest/rsp" | 60 | "${BIN}" completions bash > "$dest/rsp" |
| 47 | echo " → Bash completions: $dest/rsp" | 61 | echo " → Bash completions: $dest/rsp" |
| 48 | ;; | 62 | found=1 |
| 49 | zsh) | 63 | fi |
| 64 | |||
| 65 | if command -v zsh >/dev/null 2>&1; then | ||
| 66 | if [ "$(uname -s)" = "FreeBSD" ]; then | ||
| 67 | dest="/usr/local/share/zsh/site-functions/_rsp" | ||
| 68 | else | ||
| 50 | dest="/usr/share/zsh/site-functions/_rsp" | 69 | dest="/usr/share/zsh/site-functions/_rsp" |
| 51 | tmpfile=$(mktemp) | 70 | fi |
| 52 | /usr/bin/rsp completions zsh > "$tmpfile" | 71 | tmpfile=$(mktemp) |
| 53 | cat completions/_rsp >> "$tmpfile" | 72 | "${BIN}" completions zsh > "$tmpfile" |
| 54 | sudo cp "$tmpfile" "$dest" | 73 | cat completions/_rsp >> "$tmpfile" |
| 55 | rm -f "$tmpfile" | 74 | sudo cp "$tmpfile" "$dest" |
| 56 | echo " → Zsh completions: $dest" | 75 | rm -f "$tmpfile" |
| 57 | ;; | 76 | echo " → Zsh completions: $dest" |
| 58 | fish) | 77 | found=1 |
| 59 | dest="$HOME/.config/fish/completions/rsp.fish" | 78 | fi |
| 60 | mkdir -p "$(dirname "$dest")" | 79 | |
| 61 | /usr/bin/rsp completions fish > "$dest" | 80 | if command -v fish >/dev/null 2>&1; then |
| 62 | echo " → Fish completions: $dest" | 81 | dest="$HOME/.config/fish/completions/rsp.fish" |
| 63 | ;; | 82 | mkdir -p "$(dirname "$dest")" |
| 64 | *) | 83 | "${BIN}" completions fish > "$dest" |
| 65 | echo " → Unrecognized shell '$shell_name'; generate with: rsp completions <bash|zsh|fish|powershell|elvish>" | 84 | echo " → Fish completions: $dest" |
| 66 | ;; | 85 | found=1 |
| 67 | esac | 86 | fi |
| 87 | |||
| 88 | if [ "$found" -eq 0 ]; then | ||
| 89 | echo " → No supported shell (bash/zsh/fish) found; generate manually with: rsp completions <bash|zsh|fish|powershell|elvish>" | ||
| 90 | fi | ||
| 68 | 91 | ||
| 69 | echo "" | 92 | echo "" |
| 70 | echo "Done!" | 93 | echo "Done!" |
diff --git a/rsplayer.rc b/rsplayer.rc new file mode 100755 index 0000000..33a46b9 --- /dev/null +++ b/rsplayer.rc | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | # This file is a part of RSPlayer | ||
| 4 | # Licensed under the GPL-3.0 License | ||
| 5 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io | ||
| 6 | # https://codeberg.org/salmonik/RSPlayer | ||
| 7 | # | ||
| 8 | # FreeBSD rc.d service for RSPlayer. | ||
| 9 | # | ||
| 10 | # Add the following to /etc/rc.conf to enable the service: | ||
| 11 | # | ||
| 12 | # rsplayer_enable="YES" | ||
| 13 | # rsplayer_user="salmon" # user to run the daemon as (NOT root) | ||
| 14 | # rsplayer_group="wheel" # group of that user | ||
| 15 | # | ||
| 16 | # rsplayer_user must be a regular user: the daemon socket and PID file live | ||
| 17 | # in rsplayer_runtime_dir (default /tmp/rsplayer, matching the daemon's | ||
| 18 | # fallback when XDG_RUNTIME_DIR is unset) and the `rsp` CLI connects to that | ||
| 19 | # socket, so the daemon and the CLI must run as the same user. | ||
| 20 | # | ||
| 21 | # Optional: rsplayer_runtime_dir="/tmp/rsplayer" | ||
| 22 | |||
| 23 | # PROVIDE: rsplayer | ||
| 24 | # REQUIRE: LOGIN dbus | ||
| 25 | # KEYWORD: shutdown | ||
| 26 | |||
| 27 | . /etc/rc.subr | ||
| 28 | |||
| 29 | name="rsplayer" | ||
| 30 | rcvar=rsplayer_enable | ||
| 31 | |||
| 32 | load_rc_config $name | ||
| 33 | |||
| 34 | : ${rsplayer_user:="root"} | ||
| 35 | : ${rsplayer_group:="wheel"} | ||
| 36 | : ${rsplayer_runtime_dir:="/tmp/rsplayer"} | ||
| 37 | |||
| 38 | command="/usr/local/bin/rsp" | ||
| 39 | procname="${command}" | ||
| 40 | pidfile="${rsplayer_runtime_dir}/rsplayer.pid" | ||
| 41 | |||
| 42 | start_cmd="rsplayer_start" | ||
| 43 | stop_cmd="rsplayer_stop" | ||
| 44 | |||
| 45 | rsplayer_start() | ||
| 46 | { | ||
| 47 | if [ -s "${pidfile}" ] && kill -0 "$(cat "${pidfile}")" 2>/dev/null; then | ||
| 48 | echo "rsplayer is already running (PID $(cat "${pidfile}"))." | ||
| 49 | return 0 | ||
| 50 | fi | ||
| 51 | |||
| 52 | if [ "${rsplayer_user}" = "root" ]; then | ||
| 53 | echo "WARNING: rsplayer_user is \"root\"; the rsp CLI will not be able to" | ||
| 54 | echo " connect to the daemon socket. Set rsplayer_user in rc.conf." | ||
| 55 | fi | ||
| 56 | |||
| 57 | install -d -o "${rsplayer_user}" -g "${rsplayer_group}" -m 700 "${rsplayer_runtime_dir}" | ||
| 58 | echo "Starting rsplayer as ${rsplayer_user}." | ||
| 59 | /usr/sbin/daemon -u "${rsplayer_user}" -o "${rsplayer_runtime_dir}/rsplayer.log" \ | ||
| 60 | "${command}" start-daemon | ||
| 61 | } | ||
| 62 | |||
| 63 | rsplayer_stop() | ||
| 64 | { | ||
| 65 | echo "Stopping rsplayer." | ||
| 66 | if ! su -m "${rsplayer_user}" -c "${command} stop-daemon"; then | ||
| 67 | echo "rsplayer is not running; cleaning up stale files." | ||
| 68 | rm -f "${pidfile}" "${rsplayer_runtime_dir}/daemon.sock" | ||
| 69 | fi | ||
| 70 | } | ||
| 71 | |||
| 72 | run_rc_command "$1" | ||
