Skip to content

Instantly share code, notes, and snippets.

@userdocs
Last active December 31, 2023 13:30
Show Gist options
  • Save userdocs/57dd0ef38cc255464aa944be194521f0 to your computer and use it in GitHub Desktop.
Save userdocs/57dd0ef38cc255464aa944be194521f0 to your computer and use it in GitHub Desktop.
A modern and complete qbitorrent build script.
#! /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="$(git ls-remote -t --refs https://github.com/qbittorrent/qBittorrent.git | awk '{sub("refs/tags/release-", "");sub("(.*)(rc|alpha|beta)(.*)", ""); print $2 }' | awk '!/^$/' | sort -rV | head -n1)"
qt_tags="$(git ls-remote -t --refs https://github.com/qt/qtbase.git | awk '{sub("refs/tags/", "");sub("(.*)(v6|rc|alpha|beta|-)(.*)", ""); print $2 }' | awk '!/^$/' | sort -rV)"
#
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
cd "${build_dir}/libtorrent" || exit
"${BOOST_ROOT}/b2" -j"$(nproc)" optimization=speed crypto=openssl cxxstd=17 variant=release threading=multi link=static boost-link=static install --prefix="${lt_prefix}"
#
# 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=static boost-link=static install_module python-install-scope=user
}
qt() {
cd "${build_dir}" || exit
[[ "$(source /etc/os-release && printf "%s" "${VERSION_CODENAME}")" = 'stretch' ]] && QT_VERSION=$(grep -Eom1 "v5.12.([0-9]{1,2})" <<< ${qt_tags}) || QT_VERSION=$(grep -Eom1 "v5.15.([0-9]{1,2})" <<< ${qt_tags})
SKIP_QT=False
if [[ -f ${QT_PREFIX}/lib/libQt5Core.so ]]; then
if strings "${QT_PREFIX}/lib/libQt5Core.so" |& grep -E ^"${QT_VERSION#v}"$ &> /dev/null; then
SKIP_QT=True
fi
fi
if [[ $SKIP_QT == False ]]; then
[[ -d qtbase ]] && rm -rf qtbase
git clone --single-branch --branch "${QT_VERSION}" --shallow-submodules --recurse-submodules --depth 1 https://github.com/qt/qtbase
cd qtbase || exit
./configure --prefix="${QT_PREFIX}" -opensource -confirm-license -openssl-linked -c++std c++17 -release -qt-pcre -no-iconv -no-feature-glib -no-feature-opengl -no-feature-dbus -no-feature-gui -no-feature-widgets -no-feature-testlib -no-compile-examples
make -j"$(nproc)"
make install
rm -rf qtbase
cd "${build_dir}" || exit
[[ -d qttools ]] && rm -rf qttools
git clone -b "${QT_VERSION}" --recurse-submodules https://github.com/qt/qttools
cd qttools || exit
"${QT_PREFIX}/bin/qmake" -set prefix "${QT_PREFIX}"
"${QT_PREFIX}/bin/qmake"
make -j"$(nproc)"
make install
cd "${build_dir}" || exit
rm -rf qttools
fi
}
qbittorrent() {
cd "${build_dir}" || exit
[[ -d qBittorrent ]] && rm -rf qBittorrent
git clone --single-branch --branch "release-${QBT_VERSION}" --shallow-submodules --recurse-submodules --depth 1 https://github.com/qbittorrent/qBittorrent
cd "${build_dir}/qBittorrent" || exit
#
[[ "${1}" == 'bug' ]] && CXXFLAGS="" || CXXFLAGS="-I${BOOST_ROOT}"
#
./configure --prefix="${qbit_install_dir}" "$BUG" --with-boost="${BOOST_ROOT}" --with-boost-libdir="${lt_prefix}/lib" LDFLAGS="-Wl,--no-as-needed" CXXFLAGS="-std=c++17 -march=native" libtorrent_LIBS="-L${lt_prefix}/lib -l:libtorrent.a" libtorrent_CFLAGS="-I${lt_prefix}/include" --disable-gui
make -j"$(nproc)"
make install
cd "${build_dir}" || exit
}
deps "${@}"
boost
libtorrent
qt
qbittorrent "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment