-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.sh
49 lines (37 loc) · 1.67 KB
/
compile.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
#!/bin/bash
trap terminate INT
function terminate() {
# Trapped so echo does not work on line 45 when incomplete.
echo -e "\e[31mNot compeleted\e[0m" && exit 1
}
# Create bin/ to put copies of the compiled files if it does not exist.
[ -d bin ] || mkdir bin
bin="$(realpath bin)" && cd bin
# Compile to /usr/bin if ran with root permissions, otherwise /home/$USER/.local
[ $(id -u) == 0 ] && loc="/usr" || loc="/home/$USER/.local"
python="$(which python3)" # Assumming Python3 is installed.
# Verify Python version 3 and above is installed and use that.
if [ -z $python ]; then
if [ -n "$(which python)" ]; then
[[ -z "$(python -V | grep -P ' [3-9]')" ]] &&
echo "Python version 3 and above is required, install, or add it to path then try again." && exit 1
else
echo "Please install Python3 or add it to path then try again." && exit 1
fi
python=python
fi
# Install requirements from requirements.txt.
$python -m pip install -r ../requirements.txt
# Loop through scripts/ for Python scripts to then compile.
for script in ../scripts/*.py; do
pyinstaller --clean --onefile "$(realpath $script)"
done
[ -d ../temp ] || mkdir ../temp
# I'm not explaining this.
mv dist/* ../temp && rm -rf ./* && mv ../temp/* . && rm -rf ../temp
# Create user bin if it does not exists.
[ -d $loc ] || mkdir -p $loc/bin
cp ./* $loc/bin && echo -e "\n\e[32mCompiled to $loc/bin and left copies in $bin\e[0m"
# Check if user bin is in path, if not, give a warning to add it.
[ -z "$(echo $PATH | grep -P :?$loc/bin/?)" ] &&
echo -e "$loc/bin not in path, you might want to add it: \e[36mexport\e[0m PATH=\e[33m\"$(realpath $loc/bin):\e[0;35m\$PATH\e[33m\"\e[0m\n"