Debian Codegraph @

debian/rscreen

raw
1 #!/bin/sh
2 #
3 # Script to use autossh to open up a remote screen session, or
4 # reconnect to an existing one. Based on autossh's original rscreen
5 # example script as installed on Debian systems into
6 # /usr/share/doc/autossh/rscreen, but with more generally usable
7 # defaults
8 #
9 # Copyright (C) Carson Harding, 2002.
10 # Copyright (C) Axel Beckert, 2011.
11 # All rights reserved.
12 #
13 # Redistribution and use in source and binary forms, with or without
14 # modification, are freely permitted.
15 #
16 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 # THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 BASENAME=`basename $0`
29 usage() {
30 cat <<EOF
31 Usage: $BASENAME [autossh or ssh options] <host>
32
33 If \$RSCREEN_COMMAND is set (either in the environment, in
34 /etc/${BASENAME}rc, or in ~/.${BASENAME}rc), it will be used instead of screen
35 or tmux. Use this feature if you want to supply additional screen
36 options or tmux commands. (Using \$RTMUX_COMMAND does not work!)
37
38 EOF
39 }
40
41 if [ -z "$1" ]; then
42 usage
43 exit 1
44 elif [ "$1" = "-h" -o "$1" = "--help" ]; then
45 usage
46 exit 0
47 fi
48
49 if [ -r /etc/${BASENAME}rc ]; then
50 . /etc/${BASENAME}rc
51 fi
52
53 if [ -r ~/.${BASENAME}rc ]; then
54 . ~/.${BASENAME}rc
55 fi
56
57 if [ -z "$SSH_AUTH_SOCK" ]; then
58 eval `ssh-agent -s`
59 ssh-add
60 fi
61
62 if [ -n "$RSCREEN_COMMAND" ]; then
63 exec autossh -t "$@" "$RSCREEN_COMMAND"
64 elif [ "$BASENAME" = "rtmux" ]; then
65 exec autossh -t "$@" "tmux a || tmux new"
66 elif [ "$BASENAME" = "ruscreen" ]; then
67 # screen with explicit UTF-8 setting
68 exec autossh -t "$@" "screen -RdU"
69 else
70 # Fall back to normal screen
71 exec autossh -t "$@" "screen -Rd"
72 fi