torswitch/build.sh

35 lines
1.0 KiB
Bash
Executable File

echo "TorSwitch installer v1.1"
echo "Installing prerequisites"
sudo apt install tor -y
sudo apt install python3-pip -y
if [ $? -ne 0 ]; then
echo "Seems like your distro do not have python3-pip in repo; trying well-known package names"
sudo apt install python3-stem python3-requests python3-packaging cython3 -y
else
echo "Installing dependencies with pip3"
sudo pip3 install -r requirements.txt
fi
mkdir build
cd build
cython3 ../torswitch.py --embed -3 -o torswitch.c --verbose
if [ $? -eq 0 ]; then
echo [SUCCESS] Generated C code
else
echo [ERROR] Build failed. Unable to generate C code using cython3
exit 1
fi
# TODO: detect currently installed python version and use it
gcc -Os -static -I/usr/include/python3.8 -o torswitch torswitch.c -lpython3.8 -lpthread -lm -lutil -ldl
if [ $? -eq 0 ]; then
echo [SUCCESS] Compiled to static binary
else
echo [ERROR] Build failed
exit 2
fi
sudo cp -r torswitch /usr/bin/
if [ $? -eq 0 ]; then
echo [SUCCESS] Copied binary to /usr/bin
else
echo [ERROR] Unable to copy
exit 3
fi