Skip to content
Open
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ and notifications when users attach/detach.
#### wemux attach
Use `wemux attach` to attach to an existing wemux server.
#### wemux stop
Use `wemux stop` to kill the wemux server and remove the /tmp/wemux-wemux
Use `wemux stop` to stop the wemux server and remove the /tmp/wemux-wemux
socket.
#### wemux kill
Use `wemux kill` to stop the wemux server and forcibly remove the
/tmp/wemux-wemux socket (using sudo).
#### wemux kick *username*
Use `wemux kick <username>` to kick an SSH user from the server and remove
their wemux rogue sessions.
Expand Down
8 changes: 7 additions & 1 deletion man/wemux.1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ WEMUX HOST COMMANDS
\fBwemux stop\fR
.
.br
\fBwemux kill\fR
.
.br
\fBwemux users\fR
.
.br
Expand Down Expand Up @@ -83,7 +86,10 @@ Start a wemux session, chmod /tmp/wemux\-wemux to 1777 so that other users may c
Attach to an existing wemux session\.
.
.SS "wemux stop"
Kill the wemux session and remove the /tmp/wemux\-wemux socket\.
Stop the wemux session and remove the /tmp/wemux\-wemux socket\.
.
.SS "wemux kill"
Stop the wemux session and forcibly remove the /tmp/wemux\-wemux socket (using sudo)\.
.
.SS "wemux kick <var>username</var>"
Kick an SSH user from the server and remove their wemux pair sessions\.
Expand Down
48 changes: 33 additions & 15 deletions wemux
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# wemux start : Start the wemux server/join an existing wemux server.
# wemux attach: Join an existing wemux server.
# wemux stop : Stop the wemux server.
# wemux kill : Stop the wemux server, forcibly killing the socket (with sudo).
# wemux users : List the currently attached wemux users.
# wemux kick : Disconnect an SSH user, remove their wemux server.
# wemux config: Open the wemux configuration file in your $EDITOR.
Expand Down Expand Up @@ -377,6 +378,23 @@ display_version() {

# Host mode, used when user is listed in the host_list array in /usr/local/etc/wemux.conf
host_mode() {
# Sets server and socket vars by a server's name or list number (specified as args)
get_server_socket() {
server_sockets=(`echo $socket_prefix*`)
# If a specific server is supplied:
if [ $1 ]; then
# If user enters a number, get the server with that number in `wemux list`
if [[ $@ =~ ^[0-9]+$ ]]; then
socket=${server_sockets[$1-1]}
server=`echo $socket | sed -e "s,$socket_prefix-,,g"`
# Otherwise, get the server with the supplied name.
else
server=`sanitize_server_name $@`
socket="$socket_prefix-$server"
fi
fi
}

# Start the server if it doesn't exist, otherwise reattach.
start_server() {
if ! session_exists; then
Expand Down Expand Up @@ -418,21 +436,20 @@ host_mode() {
fi
}

# Stop the wemux session and remove the socket file.
stop_server() {
server_sockets=(`echo $socket_prefix*`)
# If a specific server is supplied:
if [ $1 ]; then
# If user enters a number, stop the server with that number in `wemux list`
if [[ $@ =~ ^[0-9]+$ ]]; then
socket=${server_sockets[$1-1]}
server=`echo $socket | sed -e "s,$socket_prefix-,,g"`
# Otherwise, stop the server with the supplied name.
else
server=`sanitize_server_name $@`
socket="$socket_prefix-$server"
# Attempt to take ownership of the server socket
steal_socket() {
get_server_socket "$@"
# If the socket file exists:
if [ -e "$socket" ]; then
if ! sudo chown $username $socket; then
echo "Could not assume ownership of '$socket'."
fi
fi
}

# Stop the wemux session and remove the socket file.
stop_server() {
get_server_socket "$@"
# If the user doesn't pass an argument, stop current server.
if kill_server_successful; then
echo "wemux server on '$server' stopped."
Expand All @@ -459,7 +476,8 @@ host_mode() {
echo ""
echo " [s] start: Start the wemux server/attach to an existing wemux server."
echo " [a] attach: Attach to an existing wemux server."
echo " [k] stop: Kill the wemux server '$server', delete its socket."
echo " [st] stop: Stop the wemux server '$server', delete its socket."
echo " [k] kill: Kill the wemux server '$server', forcibly delete its socket (with sudo)."
echo ""
if [ "$allow_server_change" == "true" ]; then
echo " [j] join [name]: Join the specified wemux server."
Expand Down Expand Up @@ -490,7 +508,7 @@ host_mode() {
start|s) announce_connection "host" start_server;;
attach|a) announce_connection "host" reattach;;
stop|st) shift; stop_server "$@";;
kill|k) shift; stop_server "$@";;
kill|k) shift; steal_socket "$@"; stop_server "$@";;
help|h) display_host_commands;;
join|j) shift; change_server "$@";;
name|n) shift; change_server "$@";;
Expand Down