Skip to content

Instantly share code, notes, and snippets.

@userdocs
Created January 17, 2021 12:18
Show Gist options
  • Save userdocs/fbe89dcb59d3e7177504be4da213bd6d to your computer and use it in GitHub Desktop.
Save userdocs/fbe89dcb59d3e7177504be4da213bd6d to your computer and use it in GitHub Desktop.
python binding
#! /usr/bin/env bash
#
# shellcheck disable=SC1091,SC2034 # sourced files
#
set -a
#
export DEBIAN_FRONTEND="noninteractive" TZ="Europe/London"
#
cr="\e[31m" # [c]olor[r]ed
cg="\e[32m" # [c]olor[g]reen
cend="\e[0m" # [c]olor[end]
#
build_dir="$HOME/qbit"
qbit_install_dir="${build_dir}/local"
mkdir -p "${build_dir}"
#
boost_version_1="1.75.0"
boost_version_2="boost_${boost_version_1//\./_}"
#
lt_prefix="${build_dir}/local"
#
BOOST_ROOT="${build_dir}/${boost_version_2}"
BOOST_INCLUDEDIR="${BOOST_ROOT}/boost"
BOOST_BUILD_PATH="${BOOST_ROOT}"
#
QT_PREFIX="${build_dir}/local"
QT_QMAKE="${QT_PREFIX}/bin"
#
QBT_VERSION="4.3.2"
#
deps() {
apt-get update
#
echo
qb_required_pkgs=("ca-certificates" "curl" "build-essential" "pkg-config" "git" "zlib1g-dev" "libicu-dev" "libssl-dev" "python3" "python3-dev")
for pkg in "${qb_required_pkgs[@]}"; do
pkgman() { dpkg -s "${pkg}"; }
if pkgman > /dev/null 2>&1; then
echo -e "Dependency - ${cg}OK${cend} - ${pkg}"
else
echo -e "Dependency - ${cr}NO${cend} - ${pkg}"
qb_checked_required_pkgs+=("$pkg")
fi
done
echo
if [[ ${#qb_checked_required_pkgs[@]} -eq 0 ]]; then
echo "All deps installed"
else
if ! apt-get -y install --no-install-recommends "${qb_checked_required_pkgs[@]}"; then
exit
fi
fi
echo
#
if [[ "$1" == 'deps' ]]; then exit; fi
}
boost() {
cd "${build_dir}" || exit
curl -sL "https://dl.bintray.com/boostorg/release/${boost_version_1}/source/${boost_version_2}.tar.gz" -o "${boost_version_2}.tar.gz"
tar xf "${boost_version_2}.tar.gz"
cd "${boost_version_2}" || exit
./bootstrap.sh
}
libtorrent() {
python_major="$(python3 -c "import sys; print(sys.version_info[0])")"
python_minor="$(python3 -c "import sys; print(sys.version_info[1])")"
python_short_version="${python_major}.${python_minor}"
#
echo -e "using gcc : : : <cflags>-march=native -std=c++17 <cxxflags>-march=native -std=c++17 ;\nusing python : ${python_short_version} : /usr/bin/python${python_short_version} : /usr/include/python${python_short_version} : /usr/lib/python${python_short_version} ;" > "/root/user-config.jam"
cd "${build_dir}" || exit
[[ -d libtorrent ]] && rm -rf libtorrent
git clone --single-branch --branch RC_1_2 --shallow-submodules --recurse-submodules --depth 1 https://github.com/arvidn/libtorrent
#
# libtorrent python binding
cd "${build_dir}/libtorrent/bindings/python" || exit
"${BOOST_ROOT}/b2" -j"$(nproc)" fpic=on optimization=speed crypto=openssl cxxstd=17 variant=release threading=multi libtorrent-link=shared boost-link=shared install_module python-install-scope=user stage_dependencies install-dependencies=on
}
deps "${@}"
boost
libtorrent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment