-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpp-detect.sh
executable file
·108 lines (90 loc) · 2.56 KB
/
vpp-detect.sh
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
#!/bin/zsh --no-rcs
#
# VPP Detection script
#
# Alternative to the Obj-C based vpp-detect
# This version is meant for easier integration into scripts
#
# --------------------------------------------------------
#
# This script will return the following exit codes:
# 0 - VPP
# 1 - App Store
# 2 - Not assigned to VPP or App Store
# 3 - No receipt found
# 4 - Catch all for any other error
#
# --------------------------------------------------------
#
# Usage:
# Requires 1 argument: Application path to check
# Example: ./vpp-detect.sh /Applications/Keynote.app
#
# --------------------------------------------------------
#
# Written by: Mykola Grymalyuk
# Company: RIPEDA Consulting
#
# --------------------------------------------------------
# MARK: - Variables
# -----------------
application="$1"
applicationReceipt="$application/Contents/_MASReceipt/receipt"
verificationURL="https://buy.itunes.apple.com/verifyReceipt"
version="1.1.0"
# MARK: - Functions
# -----------------
# Call server to determine receipt type
# Takes applicationReceipt as an argument
__checkServer() {
local receiptJSON
local receiptData
local receiptResponse
receiptJSON="{\"receipt-data\":\"$(/usr/bin/base64 -i "$1")\"}"
receiptResponse=$(/usr/bin/curl -s -X POST --data "$receiptJSON" "$verificationURL")
# Check if receipt key is missing
if [[ ! "$receiptResponse" =~ "receipt" ]]; then
echo "Not assigned to VPP or App Store"
exit 2
fi
# Check if receipt_type key is missing
if [[ ! "$receiptResponse" =~ "receipt_type" ]]; then
echo "Not assigned to VPP or App Store"
exit 2
fi
# Check for 'receipt_type' value
if [[ "$receiptResponse" =~ "ProductionVPPSandbox" ]]; then
echo "VPP"
exit 0
elif [[ "$receiptResponse" =~ "ProductionVPP" ]]; then
echo "VPP"
exit 0
elif [[ "$receiptResponse" =~ "ProductionSandbox" ]]; then
echo "App Store"
exit 1
elif [[ "$receiptResponse" =~ "Production" ]]; then
echo "App Store"
exit 1
fi
echo "Unknown reciept type! Please report this issue"
exit 4
}
# MARK: - Main
# ------------
# Check if --version flag was passed
if [[ "$1" == "--version" ]] || [[ "$1" == "-v" ]]; then
echo "$version"
exit 0
fi
# Check if the application exists
if [[ ! -e "$application" ]]; then
echo "Application not found"
exit 4
fi
# Check if receipt exists
if [[ ! -e "$applicationReceipt" ]]; then
echo "No receipt found"
exit 3
fi
# Kick off the process
__checkServer "$applicationReceipt"