-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlicense-config
executable file
·265 lines (227 loc) · 7.33 KB
/
license-config
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
#Debug mode
#set -vx;
LICENSE_INSTALLED_PATH=/var/lib/smilart_srv/license;
#exist dialog?
dialog --clear;
if [[ $? != 0 ]];then
echo -e "\E[31mERROR: Cannot run 'dialog'.">&2;tput sgr0;
exit 1;
fi;
#********Genetate tempfiles from dialog*********#
tempfile() {
tempprefix=$(basename "$0");
mktemp /tmp/${tempprefix}.XXXXXX;
}
tempdir() {
mktemp -d /tmp/smilart-mount.XXXXXX;
}
TMP_DIALOG_WARN=$(tempfile)
TMP_DIALOG_INFO=$(tempfile)
TMP_DIALOG_MENU=$(tempfile)
TMP_DIALOG_ERROR=$(tempfile)
MOUNT_DIR=$(tempdir)
echo "
dialog_color = (BLACK,WHITE,ON)
title_color = (YELLOW,WHITE,ON)
" > $TMP_DIALOG_WARN;
echo "
dialog_color = (BLACK,WHITE,ON)
title_color = (GREEN,WHITE,ON)
" > $TMP_DIALOG_INFO;
echo "
bindkey formbox TAB form_next
bindkey formfield TAB form_next
bindkey formfield BTAB form_prev
bindkey formbox BTAB form_prev
" > $TMP_DIALOG_MENU;
echo "
dialog_color = (BLACK,WHITE,ON)
title_color = (RED,WHITE,ON)
" > $TMP_DIALOG_ERROR;
# echo ERROR to dialog
# error_func <text>
error_func() {
DIALOGRC="$TMP_DIALOG_ERROR" \
dialog --title "" --msgbox "\n $1" 10 50
}
# Function at break script
run_at_break(){
sleep 1;
DIALOGRC="$TMP_DIALOG_WARN" \
dialog --ok-label "OK" \
--title "" \
--msgbox "\nWARN: License product is not configured." 10 50;
umount $MOUNT_DIR > /dev/null 2>&1;
rm -f -r $TMP_DIALOG_MENU $TMP_DIALOG_ERROR $TMP_DIALOG_INFO $TMP_DIALOG_WARN $MOUNT_DIR;
exit 1;
}
# Function at exit script
run_at_exit(){
umount $MOUNT_DIR > /dev/null 2>&1;
rm -f -r $TMP_DIALOG_MENU $TMP_DIALOG_ERROR $TMP_DIALOG_INFO $TMP_DIALOG_WARN $MOUNT_DIR;
exit 0;
}
trap 'run_at_break' SIGHUP SIGINT SIGTERM
#****************MAIN PROGRAMM*****************#
mkdir -p $MOUNT_DIR;
mkdir -p $LICENSE_INSTALLED_PATH;
# Exist label SMILART_LIC in system?
#While. Remount SMILART_LIC
echo 'Mounting flash drive to directory /tmp/smilart.'
#Menu
EXIT_FORM="true";
while [[ $EXIT_FORM == "true" ]];do
# Store data to $cmd variable
exec 3>&1
FORM_LICENSE=$(DIALOGRC="$TMP_DIALOG_MENU" dialog --clear \
--ok-label "Next" \
--title "Smilart Operating System" \
--radiolist "\nLicense setup:" \
11 50 4 \
1 "Generate request file" off \
2 "Install license" on \
2>&1 1>&3)
DIALOG_RETURN_VALUE=$?
exec 3>&-
if [[ $DIALOG_RETURN_VALUE == 1 || $DIALOG_RETURN_VALUE == 255 ]]; then
umount $MOUNT_DIR > /dev/null 2>&1;
run_at_break;
fi;
#Empty ?
if [[ -z "$FORM_LICENSE" ]]; then
error_func "ERROR: Not selected operation license.";
continue
fi;
#Checked menu
if [[ "$FORM_LICENSE" == "1" ]];then
PARTITION_LIC=`blkid | grep 'SMILART_LIC' | tail -1 | awk -F ':' '{print $1}'`;
mount $PARTITION_LIC $MOUNT_DIR >/dev/null 2>&1;
if [ $? -ne 0 ];then
# display values just entered
# open fd
exec 3>&1
# Store data to variable
FORM_REQUEST=$(DIALOGRC="$TMP_DIALOG_MENU" dialog --clear \
--ok-label "OK" \
--title "Smilart Operating System" \
--form "\nNot found device whit label SMILART_LIC.\n" \
0 0 0 \
"Path to request file: " 1 1 "$FORM_REQUEST" 1 25 30 0 \
2>&1 1>&3)
DIALOG_RETURN_VALUE=$?
exec 3>&-
#ESC in dialog?
if [[ $DIALOG_RETURN_VALUE == 1 || $DIALOG_RETURN_VALUE == 255 ]]; then
sleep 1;
continue
fi;
#Empty?
if [[ -z "$FORM_REQUEST" ]]; then
FORM_REQUEST=$PWD
fi;
#Path is valid?
if ! [ -d ${FORM_REQUEST} ];then
mkdir -p ${FORM_REQUEST};
if [ $? -ne 0 ];then
error_func "ERROR: Cannot create directory ${FORM_REQUEST}";
continue
fi;
fi;
nodeinfo | tr -d '\n' > $FORM_REQUEST/request
if [ $? -ne 0 ];then
error_func "ERROR: Request not saved to $FORM_REQUEST. Maybe directory is read-only..";
continue
else
DIALOGRC="$TMP_DIALOG_INFO" \
dialog --ok-label "OK" \
--title "" \
--msgbox "\nINFO: Request saved to $FORM_REQUEST/request." 10 50;
fi;
else
nodeinfo | tr -d '\n' > $MOUNT_DIR/request
if [ $? -ne 0 ];then
error_func "ERROR: Request not saved to device SMILART_LIC. Cannot create file request.";
else
DIALOGRC="$TMP_DIALOG_INFO" \
dialog --ok-label "OK" \
--title "" \
--msgbox "\nINFO: Request saved to device $PARTITION_LIC." 10 50;
fi;
fi;
run_at_exit;
else
PARTITION_LIC=`blkid | grep 'SMILART_LIC' | tail -1 | awk -F ':' '{print $1}'`;
mount $PARTITION_LIC $MOUNT_DIR >/dev/null 2>&1;
#Exist file license?
if ! [ -e $MOUNT_DIR/license ];then
# display values just entered
# open fd
exec 3>&1
# Store data to variable
FORM_RESPONSE=$(DIALOGRC="$TMP_DIALOG_MENU" dialog --clear \
--ok-label "OK" \
--title "Smilart Operating System" \
--form "\nLicense file not found on device SMILART_LIC.\n Check to lisense file:" \
0 0 0 \
"License file: " 1 1 "$FORM_RESPONSE" 1 20 30 0 \
2>&1 1>&3)
DIALOG_RETURN_VALUE=$?
exec 3>&-
#ESC in dialog?
if [[ $DIALOG_RETURN_VALUE == 1 || $DIALOG_RETURN_VALUE == 255 ]]; then
sleep 1;
continue
fi;
#Empty?
if [[ -z "$FORM_RESPONSE" ]]; then
FORM_RESPONSE=$PWD/license;
fi;
#Exist file license?
if ! [ -e $FORM_RESPONSE ];then
error_func "ERROR: Not found license file from $FORM_RESPONSE.";
continue;
fi;
verifylic $FORM_RESPONSE > /dev/null 2>&1;
if [ $? -ne 0 ];then
error_func "ERROR: Licence signature is not valid.";
continue;
fi;
if [[ -z `verifylic $FORM_RESPONSE | grep "$(nodeinfo)"` ]];then
error_func "ERROR: License file is correct, but is generated for a different PC.";
continue;
fi;
DIALOGRC="$TMP_DIALOG_INFO" \
dialog --ok-label "OK" \
--title "" \
--msgbox "\nINFO: License file saved to $LICENSE_INSTALLED_PATH." 10 50;
cp $FORM_RESPONSE $LICENSE_INSTALLED_PATH/license > /dev/null 2>&1;
if [ $? -ne 0 ];then
error_func "ERROR: Not copying file from $FORM_RESPONSE to $LICENSE_INSTALLED_PATH/license.";
continue;
fi;
else
verifylic $MOUNT_DIR/license > /dev/null 2>&1;
if [ $? -ne 0 ];then
error_func "ERROR: Digital signature to license from device $PARTITION_LIC not valid.";
continue;
fi;
if [[ -z `verifylic $MOUNT_DIR/license | grep "$(nodeinfo)"` ]];then
error_func "ERROR: License from device $PARTITION_LIC is correct, but is generated for a different PC.";
continue;
fi;
DIALOGRC="$TMP_DIALOG_INFO" \
dialog --ok-label "OK" \
--title "" \
--msgbox "\nINFO: License file saved to $LICENSE_INSTALLED_PATH." 10 50;
cp $MOUNT_DIR/license $LICENSE_INSTALLED_PATH/license > /dev/null 2>&1;
if [ $? -ne 0 ];then
error_func "ERROR: Not copying file from $FORM_RESPONSE to $MOUNT_DIR/license.";
continue;
fi;
fi;
fi;
EXIT_FORM="false";
done;
#Umount exist?
run_at_exit;