-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccmod.sh
executable file
·221 lines (200 loc) · 5.87 KB
/
ccmod.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/zsh
CC=CN
# Specify GEOConfigStore.db location
macos_version=$(sw_vers -productVersion)
major_version=$(echo $macos_version | awk -F '.' '{print $1}')
if [ "$major_version" -ge 14 ]; then
DATABASE_FILE=~/Library/Containers/com.apple.geod/Data/Library/Caches/com.apple.geod/Vault/GEOConfigStore.db
else
DATABASE_FILE=~/Library/Containers/com.apple.geod/Data/Library/Caches/com.apple.geod/GEOConfigStore.db
fi
# SQL queries
CHECK_OCC="SELECT * FROM defaults WHERE key='OverrideCountryCode';"
CHECK_SOCC="SELECT * FROM defaults WHERE key='ShouldOverrideCountryCode';"
CHECK_SENR="SELECT * FROM defaults WHERE key='GEOShowEnvironmentNameRule';"
ADD_OCC="INSERT INTO defaults (key,parent,type,value) VALUES ('OverrideCountryCode','0','str','$CC');"
ADD_SOCC="INSERT INTO defaults (key,parent,type,value) VALUES ('ShouldOverrideCountryCode','0','int','1');"
ADD_SENR="INSERT INTO defaults (key,parent,type,value) VALUES ('GEOShowEnvironmentNameRule','0','int','2');"
UPDATE_OCC="UPDATE defaults SET value='$CC' WHERE key='OverrideCountryCode';"
UPDATE_SOCC="UPDATE defaults SET value='1' WHERE key='ShouldOverrideCountryCode';"
UPDATE_SENR="UPDATE defaults SET value='2' WHERE key='GEOShowEnvironmentNameRule';"
DELETE_OCC="DELETE FROM defaults WHERE key='OverrideCountryCode';"
DELETE_SOCC="DELETE FROM defaults WHERE key='ShouldOverrideCountryCode';"
DELETE_SENR="DELETE FROM defaults WHERE key='GEOShowEnvironmentNameRule';"
killGEOD() {
killall -9 com.apple.geod 2>/dev/null; sleep 0.1
}
query() { # e.g. query "$CHECK_OCC"
if [ $# != 1 ]; then
echo "Error: Exactly 1 argument is required."
exit 1
fi
killGEOD
RESULT=$(sqlite3 -line "$DATABASE_FILE" "$1" 2>/dev/null)
while [ $? != 0 ]; do
killGEOD
RESULT=$(sqlite3 -line "$DATABASE_FILE" "$1" 2>/dev/null)
done
echo "$RESULT"
}
check() {
RESULT_OCC=$(query "$CHECK_OCC")
RESULT_SOCC=$(query "$CHECK_SOCC")
RESULT_SENR=$(query "$CHECK_SENR")
if [ -z "$RESULT_OCC" ]; then
echo "========== OCC NOT found. =========="
else
echo "========== OCC Result =========="
echo "$RESULT_OCC"
fi
if [ -z "$RESULT_SOCC" ]; then
echo "========== SOCC NOT found. =========="
else
echo "========== SOCC Result =========="
echo "$RESULT_SOCC"
fi
if [ -z "$RESULT_SENR" ]; then
echo "========== SENR NOT found. =========="
else
echo "========== SENR Result =========="
echo "$RESULT_SENR"
fi
}
updateOCC() {
RESULT_OCC=$(query "$CHECK_OCC")
if [ -z "$RESULT_OCC" ]; then
echo "========== OCC NOT found. Adding OCC... =========="
query "$ADD_OCC" >/dev/null
query "$CHECK_OCC"
else
echo "========== OCC found. =========="
echo "$RESULT_OCC"
echo "========== Updating OCC... =========="
killGEOD
query "$UPDATE_OCC" >/dev/null
query "$CHECK_OCC"
fi
}
updateSOCC() {
RESULT_SOCC=$(query "$CHECK_SOCC")
if [ -z "$RESULT_SOCC" ]; then
echo "========== SOCC NOT found. Adding SOCC... =========="
query "$ADD_SOCC" >/dev/null
query "$CHECK_SOCC"
else
echo "========== SOCC found. =========="
echo "$RESULT_SOCC"
echo "========== Updating SOCC... =========="
query "$UPDATE_SOCC" >/dev/null
query "$CHECK_SOCC"
fi
}
updateSENR() {
RESULT_SENR=$(query "$CHECK_SENR")
if [ -z "$RESULT_SENR" ]; then
echo "========== SENR NOT found. Adding SENR... =========="
query "$ADD_SENR" >/dev/null
query "$CHECK_SENR"
else
echo "========== SENR found. =========="
echo "$RESULT_SENR"
echo "========== Updating SENR... =========="
query "$UPDATE_SENR" >/dev/null
query "$CHECK_SENR"
fi
}
restoreSOCC() {
RESULT_SOCC=$(query "$CHECK_SOCC")
if [ -z "$RESULT_SOCC" ]; then
echo "========== SOCC NOT found, no need to restore. =========="
else
echo "========== SOCC found. =========="
echo "$RESULT_SOCC"
echo "========== Restoring SOCC... =========="
query "UPDATE defaults SET value='0' WHERE key='ShouldOverrideCountryCode';" >/dev/null
query "$CHECK_SOCC"
fi
}
restoreSENR() {
RESULT_SENR=$(query "$CHECK_SENR")
if [ -z "$RESULT_SENR" ]; then
echo "========== SENR NOT found, no need to restore. =========="
else
echo "========== SENR found. =========="
echo "$RESULT_SENR"
echo "========== Restoring SENR... =========="
query "UPDATE defaults SET value='0' WHERE key='GEOShowEnvironmentNameRule';" >/dev/null
query "$CHECK_SENR"
fi
}
delete() {
query "$DELETE_OCC" >/dev/null
query "$DELETE_SOCC" >/dev/null
query "$DELETE_SENR" >/dev/null
echo "========== Deleted OCC and SOCC. =========="
}
clear
while true; do
if [ ! -f "$DATABASE_FILE" ]; then
echo "Error: Database file not found."
exit 1
fi
echo "Menu:"
echo " 1. Check"
echo " 2. Override"
echo " 3. Restore Default"
echo " 4. Show Environment"
echo " 5. Hide Environment"
echo " 6. Delete ALL Keys"
echo " 7. Exit"
echo "Enter your choice: "
read choice
case $choice in
1)
clear
echo "You selected Option 1, checking..."
check
echo "========== END ==========\n"
;;
2)
clear
echo "You selected Option 2, overriding..."
updateOCC
updateSOCC
echo "========== END ==========\n"
;;
3)
clear
echo "You selected Option 3, restoring..."
restoreSOCC
echo "========== END ==========\n"
;;
4)
clear
echo "You selected Option 4, showing environment..."
updateSENR
echo "========== END ==========\n"
;;
5)
clear
echo "You selected Option 5, hiding environment..."
restoreSENR
echo "========== END ==========\n"
;;
6)
clear
echo "You selected Option 5, deleting all keys..."
delete
echo "========== END ==========\n"
;;
7)
echo "Exiting the script. Goodbye!"
exit 0
;;
*)
clear
echo "Invalid choice. Please enter a number between 1 and 5."
echo "====================\n"
;;
esac
done