-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetupCert.sh
executable file
·54 lines (45 loc) · 1.13 KB
/
setupCert.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash -e
case `uname` in
Linux|CYGWIN*) ECHO="echo -e" ;;
*) ECHO="echo" ;;
esac
usage(){
$ECHO "setupCert.sh [options] [user@server] [p12 file]"
$ECHO
$ECHO "Options:"
$ECHO "-c \tset up for cern-get-sso-cookie"
$ECHO "-d \tdry run (just print commands, don't execute)"
exit 1
}
COOKIE=""
DRYRUN=""
while getopts "cd" opt; do
case "$opt" in
c) COOKIE=true
;;
d) DRYRUN=true
;;
esac
done
shift $(($OPTIND - 1))
SERVER=$1
P12=$2
if [ -z "$P12" ] || [ -z "$SERVER" ]; then
usage
else
P12BASE=$(basename $P12)
fi
CMD1="scp $P12 $SERVER:~/"
CMD2b="mkdir -p .globus; rm -f .globus/usercert.pem .globus/userkey.pem .globus/userkey.rsa; openssl pkcs12 -in $P12BASE -clcerts -nokeys -out .globus/usercert.pem; openssl pkcs12 -in $P12BASE -nocerts -out .globus/userkey.pem; chmod 400 .globus/usercert.pem; chmod 400 .globus/userkey.pem"
if [ -n "$COOKIE" ]; then
CMD2b="$CMD2b; openssl rsa -in .globus/userkey.pem -out .globus/userkey.rsa; chmod 400 .globus/userkey.rsa"
fi
CMD2="ssh -t $SERVER '"$CMD2b"'"
if [ -n "$DRYRUN" ]; then
$ECHO "dry run:"
$ECHO "$CMD1"
$ECHO "$CMD2"
else
eval "$CMD1"
eval "$CMD2"
fi