-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBorn on Date.xml
More file actions
65 lines (65 loc) · 2.47 KB
/
Copy pathBorn on Date.xml
File metadata and controls
65 lines (65 loc) · 2.47 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
62
63
64
65
<?xml version="1.0" encoding="UTF-8"?><extensionAttribute>
<displayName>Born on Date</displayName>
<description>Guess the date manufactured based off the serial number. Works with both 11 digit and 12 digit serial numbers. This is accurate down to the manufacture week but does not guarantee or imply any warranty. </description>
<dataType>date</dataType>
<scriptContentsMac>#!/bin/bash
# Created by Zach Gottesman, Isaac Ordonez
# Mann Consulting (2018-05-01)
# For more information email support@mann.com or visit http://mann.com
if [[ $# -gt '0' ]]; then
serialNumber="$1"
else
serialNumber=$(system_profiler SPHardwareDataType | grep 'Serial Number (system)' | awk '{print $NF}')
fi
if [ "${#serialNumber}" == 11 ]; then
#old serialNumber number style
year=${serialNumber:2:1}
intYear=$((year+2000))
intWeek=${serialNumber:3:2}
elif [ "${#serialNumber}" == 12 ]; then
# New serial number number style
yearValues=( C D F G H J K L M N P Q R S T V W X Y Z )
weekValues=( 1 2 3 4 5 6 7 8 9 C D F G H J K L M N P Q R T V W X Y )
year=${serialNumber:3:1}
week=${serialNumber:4:1}
intYear=0
intWeek=0
for i in "${!yearValues[@]}"
do
if [ "${yearValues[i]}" == "$year" ]; then
intYear=$(((i / 2) + 2010))
intYearHalf=$i
fi
done
for i in "${!weekValues[@]}"
do
if [ "${weekValues[i]}" == "$week" ]; then
intWeek=$i
fi
done
if [ "$((intYearHalf % 2))" != 0 ]; then
intWeek=$((intWeek+27))
fi
else
printf "<result>Invalid SN</result>"
fi
#use $intYear and $intWeek to make a date string (and display)
########################################################################################################
## move to # # # move to # #
##Thu Jan 1 16:00:00 PST 1970 # move to selected year # move to week # monday # format properly #
result=$(date -v-$(($(date +%s)))S -v+1d -v+$((intYear - 1970))y -v+$((intWeek - 1))w -v-mon "+%Y-%m-%d")
if [ ! -z "$result" ]; then
printf "<result>%s</result>" "$result"
else
printf "<result>none</result>"
fi
</scriptContentsMac>
<scriptContentsWindows/>
</extensionAttribute>