This repository has been archived by the owner on Sep 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
mg-common
190 lines (174 loc) · 2.6 KB
/
mg-common
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
#!/usr/bin/env bash
# mg-common - common functions for MacGen
set -e
set -u
# MacGen version
gScriptVersion="2.1.2"
# Styles
gStyleReset="\e[0m"
gStyleBold="\e[1m"
gStyleUnderlined="\e[4m"
# Colors
gColorBlack="\e[1m"
gColorRed="\e[1;31m"
gColorGreen="\e[32m"
gColorDarkYellow="\e[33m"
gColorMagenta="\e[1;35m"
gColorPurple="\e[35m"
gColorCyan="\e[36m"
gColorBlue="\e[1;34m"
gColorOrange="\e[31m"
gColorGrey="\e[37m"
# Debug mode, set to 1 to get information about the generated serial number
if [ ! -z ${MG_DEBUG+x} ]; then
# Set gDebug to the value of the MG_DEBUG environment variable (if it is set)
gDebug=$MG_DEBUG
else
# Enable debug mode by default
gDebug=1
fi
function print_error()
{
# Print the error text and exit
printf "%b%bERROR: %b%s\n" $gColorRed $gStyleBold $gStyleReset "$1"
exit 1
}
function print_debug()
{
# Print debug text as bold
printf "%b%s: %b%s\n" $gStyleBold "$1" $gStyleReset "$2"
}
# Returns the decoded location.
function decode_location_val()
{
local location="Unknown"
case $1 in
CK2)
location="Cork, Ireland"
;;
C02|C07)
location="Quanta Computer, China"
;;
C17|C1M)
location="Unknown, China"
;;
# D25)
# location="????, ????"
# ;;
F5K)
location="Flextronics, United States"
;;
esac
echo "$location"
}
# Returns the decoded year number.
function decode_year_val()
{
local yearNumber=0
case $1 in
C|D)
let yearNumber=0
;;
F|G)
let yearNumber=1
;;
H|J)
let yearNumber=2
;;
K|L)
let yearNumber=3
;;
M|N)
let yearNumber=4
;;
P|Q)
let yearNumber=5
;;
R|S)
let yearNumber=6
;;
T|V)
let yearNumber=7
;;
W|X)
let yearNumber=8
;;
Y|Z)
let yearNumber=9
;;
esac
echo $yearNumber
}
# Returns the decoded week number.
function decode_week_val()
{
local weekNumber=0
case $1 in # These manufacture year values are offset by 27 weeks
D|G|J|L|N|Q|S|V|X|Z)
let weekNumber=27
;;
esac
case $2 in
[1-9])
let weekNumber+=$2
;;
C)
let weekNumber+=10
;;
D)
let weekNumber+=11
;;
F)
let weekNumber+=12
;;
G)
let weekNumber+=13
;;
H)
let weekNumber+=14
;;
K)
let weekNumber+=15
;;
L)
let weekNumber+=16
;;
M)
let weekNumber+=17
;;
N)
let weekNumber+=18
;;
P)
let weekNumber+=19
;;
Q)
let weekNumber+=20
;;
R)
let weekNumber+=21
;;
S)
let weekNumber+=22
;;
T)
let weekNumber+=23
;;
U)
let weekNumber+=24
;;
V)
let weekNumber+=25
;;
W)
let weekNumber+=26
;;
X)
let weekNumber+=27
;;
Y)
let weekNumber+=28
;;
esac
echo $weekNumber
}