This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
/
unlock
executable file
·125 lines (98 loc) · 2.9 KB
/
unlock
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
#!/bin/sh
# SPDX-License-Identifier: MIT
#set -e
printf "VMware ESXi Unlocker 4.0.5\n"
printf "==========================\n"
printf "\nInstalling unlocker...\n"
# Ensure we only use unmodified commands
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
if [ $# -ne 0 ]; then
case "$1" in
-v)
printf "Verbose mode"
set -x
;;
*)
printf "Invalid switch!"
exit 1
;;
esac
fi
# Check space require 400MB to be sure can patch
REQUIRED=400
FREE=$(df -m . | tail -1 | awk '{print $4}')
if [ "$FREE" -lt "$REQUIRED" ]; then
printf "\x1B[41m\x1B[37m>>> ERROR: Not enough free space to patch ESXi: free $FREE MB required $REQUIRED MB <<<\x1B[0m\n"
exit 1
fi
# Check for earlier v3 install
if [ -f "/bootbank/unlocker.tgz" ]; then
printf "\x1B[41m\x1B[37m>>> ERROR: Version 3 of ESXi Unlocker is installed and must be uninstalled <<<\x1B[0m\n"
printf "Run this command:\nBootModuleConfig.sh --verbose --remove=unlocker.tgz\nAnd reboot the ESXi server\n"
exit 1
fi
# TODO: Check not in UEFI Secure Mode
# TODO: Check on VMs are running
# TODO: Maintenance mode
# Absolute path to this script
SCRIPT=$(readlink -f "$0")
#echo "$SCRIPT"
# Absolute folder to this script
SCRIPTPATH=$(dirname "$SCRIPT")
#echo "$SCRIPTPATH"
# Change to script folder for processing
cd "$SCRIPTPATH"
# Cleanup any previous runs
rm -rf ./tmp 2>/dev/null
rm -f -f apple.* 2>/dev/null
# Create a tmp folder for processing and copy files
mkdir -p ./tmp/bin
cp $1 /bin/vmx ./tmp/bin
cp $1 /bin/vmx-debug ./tmp/bin
cp $1 /bin/vmx-stats ./tmp/bin
mkdir -p ./tmp/lib64
cp $1 /lib64/libvmkctl.so ./tmp/lib64
# Ensure vmx files are 4755/-rwsr-xr-x
chmod 4755 ./tmp/bin/*
# Ensure lib files are 755/-rwxr-xr-x
chmod 755 ./tmp/lib64/*
mkdir -p ./tmp/etc
vmware -v > ./tmp/etc/unlock.conf
# Do the unlocking stuff
python ./patchsmc patch ./tmp/bin/vmx
python ./patchsmc patch ./tmp/bin/vmx-debug
python ./patchsmc patch ./tmp/bin/vmx-stats
python ./patchvmkctl patch ./tmp/lib64/libvmkctl.so
# Ensure vmx files are 4555/-r-sr-xr-x
chmod 4555 ./tmp/bin/*
# Ensure lib files are 555/-r-xr-xr-x
chmod 555 ./tmp/lib64/*
# Build a GZ/VMTAR file
printf "Building apple.v00 VMTAR file...\n"
# Compress files to TAR file
cd ./tmp
tar c $1 -f ../apple.tar *
cd ..
# Create VMTAR from TAR file
vmtar -c apple.tar $1 -o apple.vtar 2>/dev/null
# Compress VMTAR to GZIP file
pigz $1 -f -9 -n -T -k -S .v00 apple.vtar
mv $1 -f apple.vtar.v00 apple.v00
# Remove the working files
printf "Cleaning up tmp files...\n"
rm $1 -rf ./tmp
rm $1 -f apple.tar
rm $1 -f apple.vtar
printf "Adding to bootbank...\n"
BootModuleConfig.sh --verbose --add=apple.v00
read -r -p "Reboot the ESXi server to install unlocker (y/N)? " response
case "$response" in
[yY])
printf "Rebooting the ESXi Server\n"
reboot
;;
*)
printf "The SMC patches will not be loaded until the ESXi server has been rebooted\n"
;;
esac
exit 0