-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsce.template
More file actions
executable file
·61 lines (54 loc) · 1.65 KB
/
lsce.template
File metadata and controls
executable file
·61 lines (54 loc) · 1.65 KB
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
#!/bin/bash
# The encoded code
LICENSEDCODE="<<CODE>>"
# Config files where to find the LICENSE number
CONFIGFILES="etc/<<APPNAME>>.conf etc/<<APPNAME>>/<<APPNAME>>.conf $HOME/.<<APPNAME>>.conf /etc/<<APPNAME>>.conf /etc/<<APPNAME>>/<<APPNAME>>.conf /etc/default/<<APPNAME>>.conf"
function p_error() {
echo "$@" >&2
}
function readconfig() {
local FILENAME="$1"
[ "$FILENAME" == "" -o ! -e "$FILENAME" ] && return 1
shift
local VARS=( $@ )
local NVARS=${#VARS[@]}
local CONFIG="`cat "$FILENAME" | sed 's/#.*//g' | sed 's/^[ \t]*//g' | sed 's/[ \t]*$//g' | sed '/^$/d'`"
local L n K V
while read L; do
if [[ "$L" =~ ^[a-zA-Z_][a-zA-Z0-9_]+=.*$ ]]; then
IFS='=' read K V <<< "$L"
for ((n=0;n<NVARS;n++)); do
[ "${VARS[$n]}" == "$K" ] && break
done
if [ $n -eq $NVARS ]; then
p_error "ignoring value for $K"
else
read $K <<< "$V"
export $K
fi
else
p_error "ignoring $L"
fi
done <<< "$CONFIG"
}
# Read the license from the environment or from a config file
if [ "$LICENSE" == "" ]; then
for CF in $CONFIGFILES; do
readconfig "$CF" LICENSE
if [ "$LICENSE" != "" ]; then
p_error "license found in file $CF"
break
fi
done
else
p_error "license from environment"
fi
# Decode the code
LICENSEDCODE="$(echo "$LICENSEDCODE" | base64 -d 2> /dev/null | openssl enc -d -aes-256-cbc -in /dev/stdin -out /dev/stdout -k "$LICENSE" 2> /dev/null | gunzip 2> /dev/null) "
# If any error occurred, we'll assume that there is a problem with the license
if [ $? -ne 0 ]; then
p_error "license number is not valid"
exit 1
fi
# Execute the code
eval "$LICENSEDCODE"