-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate_config.sh
executable file
·92 lines (77 loc) · 2.34 KB
/
update_config.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
#!/bin/bash
#set -x
EFI="$(./mount_efi.sh)"
config="$EFI"/EFI/Clover/config.plist
#config=config_new.plist
# smbios data
# Note: The code for serial# generation from ProBook Installer, originally
# researched/written by RehabMan and philip_petev
week=CDFGHJKLMNPQRTVWXY12345678
week2=012345678
chars=ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
week_letter=`echo ${week:$(($RANDOM%${#week})):1}`
week_letter2=`echo ${week:$(($RANDOM%${#week2})):2}`
function random_char()
{
echo ${chars:$(($RANDOM%${#chars})):1};
}
function serial_number()
{
echo "C02"$week_letter$(random_char)$(random_char)$(random_char)"F5V7"
}
function generate_new_plist()
{
cp config.plist "$config"
echo Generated random serial: \"$(serial_number)\"
/usr/libexec/plistbuddy -c "Set :SMBIOS:SerialNumber $(serial_number)" "$config"
}
# no config.plist... make new one.
if [[ ! -e "$config" ]]; then
echo "No config.plist at $config, generating new."
generate_new_plist
exit
fi
# check to see if it is installation config.plist... if so, make new one
check=`/usr/libexec/plistbuddy -c "Print :ACPI:SortedOrder-Comment" "$config" 2>&1`
if [[ ! "$check" == *"Does Not Exist"* ]]; then
echo "The config.plist at $config is install plist, generating new."
generate_new_plist
exit
fi
function replace_var()
# $1 is path to replace
{
value=`/usr/libexec/plistbuddy -c "Print \"$1\"" config.plist`
/usr/libexec/plistbuddy -c "Set \"$1\" \"$value\"" "$config"
}
function replace_dict()
# $1 is path to replace
{
/usr/libexec/plistbuddy -x -c "Print \"$1\"" config.plist >/tmp/org_rehabman_node.plist
/usr/libexec/plistbuddy -c "Delete \"$1\"" "$config"
/usr/libexec/plistbuddy -c "Add \"$1\" dict" "$config"
/usr/libexec/plistbuddy -c "Merge /tmp/org_rehabman_node.plist \"$1\"" "$config"
}
# existing config.plist, preserve:
# CPU
# DisableDrivers
# GUI
# RtVariables, except CsrActiveConfig and BooterConfig
# SMBIOS
#
# replaced are:
# ACPI
# Boot
# Devices
# KernelAndKextPatches
# SystemParameters
# RtVariables:BooterConfig
# RtVariables:CsrActiveConfig
echo "The config.plist at $config will be updated."
replace_dict ":ACPI"
replace_dict ":Boot"
replace_dict ":Devices"
replace_dict ":KernelAndKextPatches"
replace_dict ":SystemParameters"
replace_var ":RtVariables:BooterConfig"
replace_var ":RtVariables:CsrActiveConfig"