-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlnsv
executable file
·36 lines (27 loc) · 859 Bytes
/
lnsv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/zsh
error() {
tput setaf 1
echo "lnsv: $1\033[0m" 1>&2
exit
}
lnsv() {
local _svdir="/etc/runit/sv"
local _runsvdir="/run/runit/service"
[[ "$#" -lt 1 ]] && error "Not enough arguments"
case "$1" in
-u ) # Unlink a service
[[ -z "$2" ]] && error "No service name specified to remove"
local _sv="$_runsvdir/$2"
[[ -L "$_sv" ]] && sudo unlink "$_sv" || error "$2 is not a symlink in $_runsvdir"
echo "Unlinked: $_sv"
;;
* ) # Link a service
local _sv="$_svdir/$1"
[[ -d "$_sv" ]] \
&& sudo ln --symbolic "$_sv" "$_runsvdir/" \
|| error "No service dir for $1 in $_svdir"
tput setaf 6; echo "Linked: $_sv -> $_runsvdir/$1\033[0m"
;;
esac
}
lnsv "$@"