-
Notifications
You must be signed in to change notification settings - Fork 14
/
gluster-lic-info.in
executable file
·204 lines (162 loc) · 4.57 KB
/
gluster-lic-info.in
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
ME=$(basename $0);
function epoch()
{
aT=$(stat -c '%X' /.epoch);
mT=$(stat -c '%Y' /.epoch);
cT=$(stat -c '%Z' /.epoch);
dE=$((echo $aT; echo $mT; echo $cT) | sort -n | head -n 1);
echo $dE;
}
function food()
{
if [ -f /.default ]; then
delta=$(cat /.default);
else
delta=$((30 * 24 * 3600));
fi
echo $delta;
}
function say_and_die()
{
if [ $now -gt $expire ]; then
status=dead;
else
status=alive;
fi
case "$mode" in
unlicensed)
if [ -f /.default ]; then
cat <<EOF
********************************************************************************
************************* ACTIVATE 30-DAY TRIAL NOW ****************************
********************************************************************************
You have been granted a limited, five day operational license for Gluster.
To get a free full featured 30-day license with detailed documentation and access
to engineering support, please copy and paste the following URL in your browser:
http://www.gluster.com/ami-register?AMIID=$macid
EOF
else
cat <<EOF
This system is unlicensed. To obtain a license you have to first generate
a license request and get it signed. Note that a license request is for the
entire cluster of systems and therefore you need to first start all your
systems (ensure ssh connectivity among them) and peer probe them all as well.
To generate a license request, run this command and follow the instructions:
sh# gluster-lic-request
EOF
fi
;;
invalid_license)
cat <<EOF
The license file in place is invalid (signature verification failed.) Please
contact Gluster support at [email protected] for any questions.
EOF
;;
licensed)
if [ $status = "alive" ]; then
cat <<EOF
You have a valid license for $count systems.
EOF
else
cat <<EOF
You had a license for $count systems which has expired.
EOF
fi
;;
mislicensed)
cat <<EOF
Your license file is not valid on this system. Please contact Gluster support
at [email protected] for any questions.
EOF
;;
esac
if [ $status = "alive" ]; then
delta=$(($expire - $now));
days=$(($delta / (3600 * 24)));
if [ "$mode" = "unlicensed" ]; then
cat <<EOF
The trial will expire in $days day(s), on $(date -u --date="1970-01-01 00:00:00 $expire seconds").
EOF
else
cat <<EOF
This system is licensed for the next $days day(s), till $(date -u --date="1970-01-01 00:00:00 $expire seconds").
EOF
fi
else
delta=$(($now - $expire));
days=$(($delta / (3600 * 24)));
cat <<EOF
This system license has been expired for the last $days day(s), since $(date -u --date="1970-01-01 00:00:00 $expire seconds").
EOF
fi
}
function show_help()
{
cat <<EOF
Gluster Licensing Tools, Version @PACKAGE_VERSION@.
Usage: $ME [-h]
Display Gluster license information.
Miscellaneous:
-h display this help and exit
Example:
$ME
EOF
}
function main()
{
# Parse command line arguments.
while getopts :h OPT; do
case "$OPT" in
h)
show_help
exit 0
;;
\?)
# getopts issues an error message
echo "Invalid option: -$OPTARG"
show_help
exit 1
;;
esac
done
# Remove the switches we parsed above.
shift `expr $OPTIND - 1`
# We want no non-option argument.
if [ $# -ne 0 ]; then
show_help
exit 1
fi
macid=$(cat /.epoch 2>/dev/null);
if [ -z "$macid" ]; then
cat <<EOF
This machine has not been setup for gluster licensing. Please run:
sh# gluster-lic-setup
The above setup will prepare the machine for license management.
EOF
exit 1
fi
now=$(date '+%s');
def_expire=$(( $(epoch) + $(food) ));
if [ ! -f /lic/license.asc ]; then
expire=$def_expire;
mode=unlicensed;
else
/lic/gpgv --keyring /lic/pubring.gpg /lic/license.asc >/dev/null 2>&1;
if [ $? -ne 0 ]; then
mode=invalid_license;
expire=$def_expire;
else
count=$(grep '^........-....-....-....-............ ' /lic/license.asc | wc -l);
if grep -q "^$macid " /lic/license.asc; then
expire=$(grep "^$macid " /lic/license.asc | cut -f2 -d' ');
mode=licensed;
else
expire=$def_expire;
mode=mislicensed;
fi
fi
fi
say_and_die;
}
main "$@";