-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathMAKEFILE.sh
219 lines (189 loc) · 5.46 KB
/
MAKEFILE.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
#!/bin/bash
# This is the Makefile for WAIL for macOS
# http://matkelly.com/wail/
DIRECTORY="/Applications/WAIL.app/"
trap exit INT
main ()
{
# Provide a means to skip all questions for GitHub Actions
while getopts ":q" opt; do
case ${opt} in
q )
echo "Skipping options to build for testing" >&2
makeWAIL
exit 0
;;
\? )
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check if WAIL processes are running and offer to kill them
wailProcessesRunning=$(ps -A | grep '[/]WAIL.app/' | wc -l)
if (($wailProcessesRunning > 0)); then
while true; do
read -p "Kill currently running WAIL processes (y/n)? " yn
case $yn in
[Yy]* )
pkill -f '[/]WAIL.app/'
break;;
[Nn]* )
break;;
* ) echo "Please answer y or n.";;
esac
done
fi
# Check if WAIL.app exists. Ask the user whether to nuke old binary. Exit if 'no'
if [ -d "$DIRECTORY" ]; then
echo $DIRECTORY" already exists!"
while true; do
read -p "Do you want me to delete the old app and continue (y/n)? " yn
case $yn in
[Yy]* ) echo "Continuing to build, retaining WARCs"; break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n.";;
esac
done
fi
if [[ $1 == "ci" ]]; then
ans="i"
else
read -p "Would you like to install binary (i), create dmg (d), or both (b)? (i/d/b) " ans
fi
case "$ans" in
i|d|b)
;;
*)
echo "Invalid choice, choose one of i/d/b"
exit
;;
esac
makeWAIL
}
installRequirements ()
{
echo "Installing build requirements"
# wxPython 4.2.0 has issues building on Linux w/o attrdict being installed first
python3 -m pip install attrdict3
python3 -m pip install --upgrade wxPython
python3 -m pip install -r requirements.txt
}
createBinary ()
{
echo "Creating binary"
which pyinstaller
# Only specify the universal2 flag if an appropriate Python is installed, otherwise use default
if file `which python3` | grep 'universal'; then
echo "🌌 Building universal binary"
archflag=(--target-arch universal2)
else
echo "🍎 Building native single-architecture binary"
fi
pyinstaller -p bundledApps ./bundledApps/WAIL.py --onefile --windowed --clean "${archflag[@]}" --icon="./build/icons/wail_blue.icns"
# Replace default version and icon information from pyinstaller
cp ./build/Info.plist ./dist/WAIL.app/Contents/Info.plist
# Copy the bundledApps and support directories to inside WAIL.app/
cp -r ./bundledApps ./support ./build ./config ./archives ./archiveIndexes ./dist/WAIL.app/
#pkgbuild --install-location=/Applications --component ./dist/WAIL.app ~/Downloads/WAIL.pkg
}
deleteBinary ()
{
echo "Deleting binary"
rm -rf /Applications/WAIL.app
}
mvWARCsToTemp ()
{
if [ -d "/tmp/tempArchives" ]
then
echo "Moving WARCs to /tmp/tempArchives/"
mv /tmp/tempArchives /tmp/tempArchives_old
mv /Applications/WAIL.app/archives /tmp/tempArchives
fi
}
mvWARCsBackFromTemp ()
{
if [ -d "/tmp/tempArchives" ]
then
echo "Moving WARCs back to /Applications/WAIL.app/archives/"
mv /tmp/tempArchives/* /Applications/WAIL.app/archives/
rm -rf /tmp/tempArchives
mv /tmp/tempArchives_old /tmp/tempArchives
fi
}
mvProducts ()
{
echo "Moving WAIL.app to /Applications"
mv ./dist/WAIL.app /Applications/
mv ./dist/WAIL /Applications/WAIL_cli
}
cleanupByproducts ()
{
echo "Cleaning up byproducts, deleting ./dist and ./build/WAIL"
# Remove installation remnants
rm -r ./dist
rm -r ./build/WAIL
}
optimizeforMac ()
{
echo "Optimizing for Mac"
# Remove Windows supporting package
echo "> Removing MemGator (Linux)"
rm ./dist/WAIL.app/bundledApps/memgator-linux-amd64
echo "> Removing MemGator (Window)"
rm ./dist/WAIL.app/bundledApps/memgator-windows-amd64.exe
echo "> Removing Java (Windows)"
rm -rf ./dist/WAIL.app/bundledApps/Java/Windows
if [[ $(uname -p) == 'i386' ]]; then
echo "> Removing MemGator (Apple Silicon)"
rm ./dist/WAIL.app/bundledApps/memgator-darwin-arm64
chmod 755 ./dist/WAIL.app/bundledApps/memgator-darwin-amd64
else
echo "> Removing MemGator (pre-Apple Silicon)"
rm ./dist/WAIL.app/bundledApps/memgator-darwin-amd64
chmod 755 ./dist/WAIL.app/bundledApps/memgator-darwin-arm64
fi
}
buildDiskImage ()
{
echo "Building Disk Image"
# Create a dmg
dmgbuild -s ./build/dmgbuild_settings.py "WAIL" WAIL.dmg
}
tweakOS ()
{
echo "Tweaking OS file associations"
# Instruct the system to update the version string
defaults read /Applications/WAIL.app/Contents/Info.plist > /dev/null
# Associate defined file types with WAIL
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Applications/WAIL.app
}
makeWAIL ()
{
echo "Running makeWAIL()"
installRequirements
createBinary
mvWARCsToTemp
deleteBinary # Remove previous version
optimizeforMac
mvProducts
cleanupByproducts
mvWARCsBackFromTemp
# install binary, create dmg, or both? (i/d/b)
# Just build dmg, delete binary, no system tweaks required
if [[ $ans == "b" ]] || [[ $ans == "d" ]]; then
buildDiskImage
if [[ $ans = "d" ]]; then # Remove the installed binary if only making dmg
deleteBinary
fi
fi
if [[ $ans = "i" ]] || [[ $ans = "d" ]]; then # Tweak system for binary
tweakOS
fi
#killall Finder
#cleanup
#rm -r dist
#rm WAIL.spec
#rm -r build
}
main "$@"; exit