-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake
268 lines (210 loc) · 7.22 KB
/
make
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
#!/usr/bin/env bash
# You have been bamboozled.
# This is not a real make file, but rather
# a build/install script written in bash
versionstring="pyz_1.2.0_amd64"
debcontrol="Package: pyz
Version: 1.2.0
Architecture: amd64
Essential: no
Priority: optional
Depends: python3, python3-pip, sudo
Maintainer: Markix
Description: A shell, written in Python, for Python
"
desktopfile="[Desktop Entry]
Name=PyZ
Exec=pyz
Icon=PyZlogo
Type=Application
Terminal=true
Categories=Utility
"
apprun="#!/bin/sh
CURRDIR=\"\$(dirname \"\$(readlink -f \"\${0}\")\")\"
EXEC=\"\${CURRDIR}/usr/local/bin/pyz\"
exec \"\${EXEC}\""
helptext="Help menu for PyZ's make script
make [COMMAND]
make package [DEB/AppImage]
Commands:
- build: Builds the program and nothing else
- docs: Builds the man pages
- install: Builds the program and installs it to ~./local/bin
- update: Updates the program
- uninstall: If you've installed PyZ with ./make install, use this to uninstall it
- installdeps: Installs dependencies
- all: Installs all dependencies
- dev: Installs dependencies only required for development/compiling
- runtime: Installs dependencies only required for runtime
- package: Builds the program and creates a package
- help: Shows this help menu
"
help () {
printf "%s" "$helptext"
}
build () {
if [[ "$OSTYPE" == *"linux-gnu"* ]]; then
mkdir -p bin/Linux
cd bin/Linux || exit 2
pythonfiles=(
../../src/main.py
../../src/shell/__init__.py
../../src/shell/shell.py
../../src/shell/rccreator.py
../../src/shell/pluginimport.py
../../src/pluginmgr/__init__.py
../../src/pluginmgr/manager.py
../../src/pluginmgr/installer.py
../../src/pluginmgr/mgrinit.py
../../src/pluginmgr/remover.py
../../src/pluginmgr/searcher.py
../../src/pluginmgr/updater.py
../../src/updatemgr/__init__.py
../../src/updatemgr/checker.py
../../src/pyziniter/__init__.py
../../src/pyziniter/pyzinit.py
../../src/pyziniter/verJSONcreate.py
../../src/api/__init__.py
../../src/api/connection.py
../../src/api/pyzprompt.py
../../src/api/pyzshell.py
)
pyinstaller --onefile "${pythonfiles[@]}"
if [[ "$?" != "0" ]]; then
printf "[ERROR] Error while building! Check logs above"
exit 1
else
cd dist || exit 2
mv main ../pyz
cd ../ || exit 2
rm -r build dist main.spec
printf "[OK] Build successful!\n"
fi
else
printf "[ERROR] Platform error! If you are on Windows, run make.ps1.\nIf you are on macOS, unfortunately, there is no binary for you.\n"
fi
}
install () {
build
cp "pyz" "$HOME/.local/bin/pyz"
cd ../../ || exit 1
rm -r bin
printf "[OK] Program installed!\n"
}
update () {
build
rm "$HOME/.local/bin/pyz"
cp "pyz" "$HOME/.local/bin/pyz"
wget https://raw.githubusercontent.com/CodyMarkix/PyZ-shell/master/version.json -O "$HOME/.local/share/pyz/version.json"
}
uninstall () {
printf "Removing ~/.local/share/pyz..."
rm -r "$HOME/.local/share/pyz"
printf "Removing ~/.local/bin/pyz..."
rm -r "$HOME/.local/bin/pyz"
}
package () {
if [[ "$1" == "DEB" ]] || [[ "$1" == "deb" ]]; then
build
cd ../ || exit 1
mkdir -p "${versionstring}/DEBIAN" "${versionstring}/usr/local/bin"
touch "${versionstring}/DEBIAN/control"
echo "${debcontrol}" > ${versionstring}/DEBIAN/control
cd Linux/ || exit 1
cp "pyz" "../${versionstring}/usr/local/bin/pyz"
cd ../ || exit 1
dpkg-deb --build ${versionstring}
rm -r "${versionstring}"
mv "${versionstring}.deb" Linux/
cd Linux/ || exit 1
rm pyz
elif [[ "$1" == "AppImage" ]] || [[ "$1" == "Appimage" ]] || [[ "$1" == "appImage" ]] || [[ "$1" == "appimage" ]] || [[ "$1" == "APPIMAGE" ]]; then
build
cd ../ || exit 1
mkdir "${versionstring}.AppDir" && cd "${versionstring}.AppDir" || exit 1
mkdir -p usr/local/bin
touch pyz.desktop
echo "${desktopfile}" > pyz.desktop
chmod +x pyz.desktop
touch AppRun
echo "${apprun}" > AppRun
chmod +x AppRun
cp ../../icon/PyZlogo.png ./PyZlogo.png
cd ../Linux || exit 1
cp "pyz" "../${versionstring}.AppDir/usr/local/bin/pyz"
cd .. || exit 1
read -p "Enter your architecture (x86_64, i386, armhf, aarch64): " appimagearch
read -p "Enter the path to AppImageTool: " aitpath
ARCH=${appimagearch}
${aitpath} "${versionstring}.AppDir"
mv "PyZ-${ARCH}.AppImage" "Linux/"
rm -r "${versionstring}.AppDir"
rm Linux/pyz
else
printf "[ERROR] Please specify what kind of package you want to create!\n"
fi
}
checkdeps () {
if [ "$(pip)" ]; then
if [[ -n "$(pip list | grep -i termcolor)" ]]; then
if [[ -n "$(pip list | grep -i pyinstaller)" ]]; then
build
else
printf "[ERROR] Dependency error!\n\nThe pyinstaller module is required!\nInstall using \"pip install pyinstaller\"" || exit 1
fi
else
printf "[ERROR] Dependency error!\n\nThe Termcolor module is required!\nInstall using \"pip install termcolor\"" || exit 1
fi
else
printf "[ERROR] Dependency error!\n\nPython's PIP module manager required.\n" || exit 1
fi
}
docs () {
cd src/docs || exit 1
pandoc pyz.1.MD -s -t man -o pyz.1
pandoc pyz-plugm.1.MD -s -t man -o pyz-plugm.1
gzip pyz.1 && gzip pyz-plugm.1
sudo --prompt="Enter your password (for moving the man-pages to a write-protected location): " mv pyz.1.gz /usr/local/share/man/man1/pyz.1.gz
sudo mv pyz-plugm.1.gz /usr/local/share/man/man1/pyz-plugm.1.gz
sudo mandb
}
installdeps () {
if [[ "$1" == "all" ]]; then
sudo apt install python3-pip pandoc || sudo pacman -S python-pip pandoc || sudo dnf install python3-pip pandoc
pip install termcolor
pip install pyinstaller
pip install pynput
elif [[ "$1" == "dev" ]]; then
sudo apt install python3-pip pandoc || sudo pacman -S python-pip pandoc || sudo dnf install python3-pip pandoc
pip install pyinstaller
elif [[ "$1" == "runtime" ]]; then
sudo apt install python3-pip || sudo pacman -S python-pip || sudo dnf install python3-pip
pip install termcolor
pip install pynput
fi
}
main () {
if [[ "$1" == "help" ]]; then
help
elif [[ "$1" == "build" ]]; then
checkdeps
elif [[ "$1" == "docs" ]]; then
docs
elif [[ "$1" == "install" ]]; then
install
elif [[ "$1" == "update" ]]; then
update
elif [[ "$1" == "uninstall" ]]; then
uninstall
elif [[ "$1" == "installdeps" ]]; then
installdeps "$2"
elif [[ "$1" == "package" ]]; then
package "$2"
elif [[ "$1" == "help" ]]; then
help
else
help
fi
}
main "$1" "$2" "$3"