Add README with license and ~history
[user/alex/software/my-snippets.git] / pag-screen
1 #!/usr/bin/env pagsh
2
3 screen=`which screen`
4
5 # Check for pre-existing screens.
6 screenlist=`$screen -list | grep owl`
7 if [ "x$screenlist" != "x" ]; then
8     echo "Found a pre-existing owl-screen session:"
9     echo "$screenlist"
10     echo "You probably want to reattach it instead."
11     echo
12     exit 1
13 fi
14
15 # Get AFS tokens for the screen session.
16 # We are now in a new PAG (because of pagsh).
17 # If you want to get tokens for other cells, list them in ~/.xlog
18 aklog
19
20 # Use separate kerberos tickets for screen. Even if we accidentally
21 # (or intentionally) log out, screen and owl will still have tickets.
22 NEWKRB5=/tmp/krb5cc_${USER}_screen
23
24 # Copy the tickets we obtained on login to the screen tickets.
25 KRB5CCNAME=`echo $KRB5CCNAME | sed 's/FILE://'`
26 cp $KRB5CCNAME $NEWKRB5
27
28 # Now actually use the new tickets.
29 KRB5CCNAME=FILE:$NEWKRB5; export KRB5CCNAME
30
31 # Repeat for krb4 if appropriate.
32 if [ "x$KRBTKFILE" != "x" ]; then
33    NEWKRB4=/tmp/tkt_${USER}_screen
34    KRBTKFILE=`echo $KRBTKFILE | sed 's/FILE://'`
35    cp $KRBTKFILE $NEWKRB4
36    KRBTKFILE=$NEWKRB4; export KRBTKFILE
37 fi
38
39 # Figure out which zephyr client to use.  Defaults to barnowl.
40 if [ "x$ZEPHYR_SCREEN_CLIENT" = "x" ]; then
41     barnowl=`which barnowl`
42     if [ ! -x "$barnowl" ]; then
43         attach -n -q barnowl
44         barnowl=`athdir /mit/barnowl`/barnowl
45     fi
46     ZEPHYR_SCREEN_CLIENT="$barnowl"
47 fi
48
49 # Renew tickets and tokens.
50 contrenew=`which cont-renew-notify`
51 if [ ! -x "$contrenew" ]; then
52     zwrite $ATHENA_USER -d -m "$0: cont-renew doesn't exist on $(hostname)... Not doing renewals"
53     contrenew=/bin/true
54 fi
55 nohup $contrenew < /dev/null > /dev/null 2> /dev/null &
56
57 # Name the screen pag so we can reattach the right screen later.
58 $screen -S pag