-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflashgbx.sh
294 lines (261 loc) · 8.29 KB
/
flashgbx.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
function updateFlashGBX() {
(
set -e
repo_dir="$HOME/.tmp/FlashGBX"
if [ -f "/Applications/FlashGBX.app/Contents/Info.plist" ]; then
installed_version=$(plutil -p "/Applications/FlashGBX.app/Contents/Info.plist" | grep "CFBundleShortVersionString" | awk -F\" '{print $4}')
else
installed_version="0"
fi
latest_version=$(curl -s https://api.github.com/repos/lesserkuma/FlashGBX/releases/latest | grep '"tag_name":' | awk -F\" '{print $4}') || {
echo "Error fetching latest version information"
exit 1
}
if [ "$latest_version" = "$installed_version" ]; then
echo "FlashGBX is already up-to-date (version $installed_version)."
return 0
fi
# Prompt for user confirmation
echo "A new version of FlashGBX is available."
echo "current: $installed_version, latest: $latest_version"
echo -n "Do you want to update? (y/n): "
read -r user_input
if [[ ! $user_input =~ ^[Yy]$ ]]; then
echo "Update cancelled."
return 0
fi
if [ ! -d "$repo_dir" ]; then
mkdir -p "$repo_dir"
git clone https://github.com/lesserkuma/FlashGBX.git "$repo_dir" || {
echo "Error cloning repository"
exit 1
}
cd "$repo_dir"
else
cd "$repo_dir"
git fetch || {
echo "Error fetching repository updates"
exit 1
}
fi
# Reset repo to upstream
git clean -fd
git reset --hard
# Checkout latest release
git checkout tags/"$latest_version" >/dev/null 2>&1 || {
echo "Error checking out tag $latest_version"
exit 1
}
#update_spec
printf "# -*- mode: python ; coding: utf-8 -*-\n\n\
a = Analysis(\n\
['run.py'],\n\
pathex=[],\n\
binaries=[],\n\
datas=[],\n\
hiddenimports=[],\n\
hookspath=[],\n\
hooksconfig={},\n\
runtime_hooks=[],\n\
excludes=[],\n\
noarchive=False,\n\
)\n\
pyz = PYZ(a.pure)\n\n\
exe = EXE(\n\
pyz,\n\
a.scripts,\n\
[],\n\
exclude_binaries=True,\n\
name='FlashGBX',\n\
debug=False,\n\
bootloader_ignore_signals=False,\n\
strip=False,\n\
upx=True,\n\
console=False,\n\
disable_windowed_traceback=False,\n\
argv_emulation=False,\n\
target_arch=None,\n\
codesign_identity=None,\n\
entitlements_file=None,\n\
icon=['FlashGBX/res/icon.ico'],\n\
)\n\
coll = COLLECT(\n\
exe,\n\
a.binaries,\n\
a.datas,\n\
strip=False,\n\
upx=True,\n\
upx_exclude=[],\n\
name='FlashGBX',\n\
)\n\
info_plist = {\n\
'CFBundleName': 'FlashGBX',\n\
'CFBundleDisplayName': 'FlashGBX',\n\
'CFBundleGetInfoString': 'Reads and writes Game Boy and Game Boy Advance cartridge data.',\n\
'CFBundleShortVersionString': '%s',\n\
'CFBundleIdentifier': 'com.lesserkuma.FlashGBX',\n\
}\n\
app = BUNDLE(\n\
coll,\n\
name='FlashGBX.app',\n\
icon='FlashGBX/res/icon.ico',\n\
bundle_identifier='com.lesserkuma.FlashGBX',\n\
info_plist=info_plist,\n\
)" "$latest_version" > FlashGBX.spec
yes | pyinstaller FlashGBX.spec
# Manually copy cartridge information files to the app bundle
mkdir dist/FlashGBX.app/Contents/MacOS/config
cp -R FlashGBX/config/* dist/FlashGBX.app/Contents/MacOS/config
cp -R FlashGBX/res dist/FlashGBX.app/Contents/MacOS
#plutil -replace CFBundleShortVersionString -string "$latest_version" dist/FlashGBX.app/Contents/Info.plist
rsync -a --delete dist/FlashGBX.app/ /Applications/FlashGBX.app/
echo "Successfully updated FlashGBX to version $latest_version."
)
}
function createFlashGBXImage {
(
set -e
repo_dir="$HOME/.tmp/FlashGBX"
release_repo="Cliffback/FlashGBX-macOS"
latest_version=$(curl -s https://api.github.com/repos/lesserkuma/FlashGBX/releases/latest | grep '"tag_name":' | awk -F\" '{print $4}') || {
echo "Error fetching latest version information"
exit 1
}
# Prompt for user confirmation to create an image
echo -n "Do you want to create an image of FlashGBX v$latest_version? (y/n): "
read -r user_input
if [[ ! $user_input =~ ^[Yy]$ ]]; then
echo "Creation cancelled."
return 0
fi
# Clone or fetch the FlashGBX repository
if [ ! -d "$repo_dir" ]; then
mkdir -p "$repo_dir"
git clone https://github.com/lesserkuma/FlashGBX.git "$repo_dir" || {
echo "Error cloning repository"
exit 1
}
fi
cd "$repo_dir"
git fetch
git checkout tags/"$latest_version" >/dev/null 2>&1 || {
echo "Error checking out tag $latest_version"
exit 1
}
#update_spec
printf "# -*- mode: python ; coding: utf-8 -*-\n\n\
a = Analysis(\n\
['run.py'],\n\
pathex=[],\n\
binaries=[],\n\
datas=[],\n\
hiddenimports=[],\n\
hookspath=[],\n\
hooksconfig={},\n\
runtime_hooks=[],\n\
excludes=[],\n\
noarchive=False,\n\
)\n\
pyz = PYZ(a.pure)\n\n\
exe = EXE(\n\
pyz,\n\
a.scripts,\n\
[],\n\
exclude_binaries=True,\n\
name='FlashGBX',\n\
debug=False,\n\
bootloader_ignore_signals=False,\n\
strip=False,\n\
upx=True,\n\
console=False,\n\
disable_windowed_traceback=False,\n\
argv_emulation=False,\n\
target_arch=None,\n\
codesign_identity=None,\n\
entitlements_file=None,\n\
icon=['FlashGBX/res/icon.ico'],\n\
)\n\
coll = COLLECT(\n\
exe,\n\
a.binaries,\n\
a.datas,\n\
strip=False,\n\
upx=True,\n\
upx_exclude=[],\n\
name='FlashGBX',\n\
)\n\
info_plist = {\n\
'CFBundleName': 'FlashGBX',\n\
'CFBundleDisplayName': 'FlashGBX',\n\
'CFBundleGetInfoString': 'Reads and writes Game Boy and Game Boy Advance cartridge data.',\n\
'CFBundleShortVersionString': '%s',\n\
'CFBundleIdentifier': 'com.lesserkuma.FlashGBX',\n\
}\n\
app = BUNDLE(\n\
coll,\n\
name='FlashGBX.app',\n\
icon='FlashGBX/res/icon.ico',\n\
bundle_identifier='com.lesserkuma.FlashGBX',\n\
info_plist=info_plist,\n\
)" "$latest_version" > FlashGBX.spec
yes | pyinstaller FlashGBX.spec
# Manually copy cartridge information files to the app bundle
mkdir dist/FlashGBX.app/Contents/MacOS/config
cp -R FlashGBX/config/* dist/FlashGBX.app/Contents/MacOS/config
mkdir -p dist/dmg
cp -r "dist/FlashGBX.app" dist/dmg
# Check if the DMG file already exists and remove it if it does
dmg_path="dist/FlashGBX.dmg"
if [ -f "$dmg_path" ]; then
echo "Removing existing DMG file..."
rm "$dmg_path"
fi
create-dmg \
--volname "FlashGBX" \
--volicon "FlashGBX/res/icon.ico" \
--window-pos 200 120 \
--window-size 600 300 \
--icon-size 100 \
--icon "FlashGBX.app" 175 120 \
--hide-extension "FlashGBX.app" \
--app-drop-link 425 120 \
"dist/FlashGBX.dmg" \
"dist/dmg/"
echo "Successfully created image of FlashGBX v$latest_version."
# Check permission level for the release repository
permission_level=$(gh repo view "$release_repo" --json viewerPermission --jq '.viewerPermission')
if [[ $permission_level == "ADMIN" || $permission_level == "WRITE" ]]; then
# User has admin or write access, ask for confirmation to create a release
echo "You have permission to create a release on $release_repo."
echo "Do you want to create a release for FlashGBX v$latest_version? (y/n): "
read -r release_input
if [[ $release_input =~ ^[Yy]$ ]]; then
# User confirmed, create a release
dmg_path="dist/FlashGBX.dmg" # Ensure this is the correct path to your DMG file
if [ -f "$dmg_path" ]; then
release_notes=$(cat <<EOF
App compiled and packaged from the official repo.
Probably only works on Apple Silicone
If you can't open it, it probably got quarantined during download. Run the following to unquarantine it:
xattr -d com.apple.quarantine /path/to/FlashGBX.app
EOF
)
gh release create "$latest_version" \
--repo "$release_repo" \
--title "FlashGBX v$latest_version" \
--notes "$release_notes" \
"$dmg_path"
echo "Release successfully created for FlashGBX v$latest_version."
else
echo "DMG file not found. Release not created."
fi
else
echo "Release creation cancelled."
fi
else
echo "You do not have permission to create a release on $release_repo."
fi
# Clean up
cd "$HOME"
)
}