-
Notifications
You must be signed in to change notification settings - Fork 0
/
gwms-pack-cacert.sh
executable file
·89 lines (76 loc) · 2.02 KB
/
gwms-pack-cacert.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# Find and package CA certificates
# Initial version 9/22/2014 - Marco Mambelli - [email protected]
function find_ca_certs {
if [ -e "$X509_CERT_DIR" ]; then
retv="$X509_CERT_DIR"
elif [ -e "$HOME/.globus/certificates/" ]; then
retv="$HOME/.globus/certificates/"
elif [ -e "/etc/grid-security/certificates/" ]; then
retv="/etc/grid-security/certificates/"
else
STR="Could not find grid-certificates!\n"
STR+="Looked in:\n"
STR+=" \$X509_CERT_DIR ($X509_CERT_DIR)\n"
STR+=" \$HOME/.globus/certificates/ ($HOME/.globus/certificates/)\n"
STR+=" /etc/grid-security/certificates/"
STR1=$(echo -e "$STR")
echo "$STR1" >&2
exit 1
fi
echo "$retv"
return 0
}
PKG_FNAME="gwms-certpkg.tgz"
function help_msg {
cat << EOF
$0 [ options ]
-h print this help message
-c CA_DIR Path of the CA certificates directory [search availables]
-o FNAME Name of the CA certificate package [$PKG_FNAME]
-r Do not strip CSLs
-v verbose output
EOF
}
while getopts hc:o:rv option
do
case "${option}"
in
"h") help_msg; exit 0;;
"c") CA_DIR="${OPTARG}";;
"o") PKG_FNAME="${OPTARG}";;
"r") KEEP_CRL=yes;;
"v") VERBOSE=yes;;
*) help_msg; exit 1;;
esac
done
if [ -z "$CA_DIR" ]; then
CA_DIR=$(find_ca_certs)
fi
[ -n "$VERBOSE" ] && echo "CA Certificates dir: $CA_DIR"
tmpdir=$(mktemp -d)
function get_abs_path {
retv=$(readlink -f "$1" 2> /dev/null)
# OSX has a different readlink
if [ -n "$retv" ]; then
echo "$retv"
else
if [[ ! "$1" == /.* ]]; then
echo "$(pwd)/$1"
else
echo "$1"
fi
fi
}
PKG_FNAME=$(get_abs_path "$PKG_FNAME")
CA_DIR=$(get_abs_path "$CA_DIR")
mkdir -p "$tmpdir/gwms_certificates"
pushd "$tmpdir" > /dev/null || exit 1
cp "$CA_DIR"/* gwms_certificates/
if [ -z "$KEEP_CRL" ]; then
rm -f gwms_certificates/*r0 2> /dev/null
fi
tar czf $PKG_FNAME gwms_certificates
popd > /dev/null || exit 1
rm -rf "$tmpdir"
[ -n "$VERBOSE" ] && echo "CA Certificates packaged in: $PKG_FNAME"