Add sendmail-based mail merger
[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 || echo "Failed to get new tokens"
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 if [ "x$KRB5CCNAME" != "x" ]; then
27     cp $KRB5CCNAME $NEWKRB5
28 else
29     echo "No tickets; not copying to new CC"
30 fi
31
32 # Now actually use the new tickets.
33 KRB5CCNAME=FILE:$NEWKRB5; export KRB5CCNAME
34
35 # Repeat for krb4 if appropriate.
36 if [ "x$KRBTKFILE" != "x" ]; then
37    NEWKRB4=/tmp/tkt_${USER}_screen
38    KRBTKFILE=`echo $KRBTKFILE | sed 's/FILE://'`
39    cp $KRBTKFILE $NEWKRB4
40    KRBTKFILE=$NEWKRB4; export KRBTKFILE
41 fi
42
43 # Figure out which zephyr client to use.  Defaults to barnowl.
44 if [ "x$ZEPHYR_SCREEN_CLIENT" = "x" ]; then
45     barnowl=`which barnowl`
46     if [ ! -x "$barnowl" ]; then
47         attach -n -q barnowl
48         barnowl=`athdir /mit/barnowl`/barnowl
49     fi
50     ZEPHYR_SCREEN_CLIENT="$barnowl"
51 fi
52
53 # Renew tickets and tokens.
54 contrenew=`which cont-renew-notify`
55 if [ ! -x "$contrenew" ]; then
56     zwrite $ATHENA_USER -d -m "$0: cont-renew doesn't exist on $(hostname)... Not doing renewals"
57     contrenew=/bin/true
58 fi
59 nohup $contrenew < /dev/null > /dev/null 2> /dev/null &
60
61 # Name the screen pag so we can reattach the right screen later.
62 $screen -S pag