From 18e6eed981986eca4deb63ea8181d29831cc8e2d Mon Sep 17 00:00:00 2001 From: stickz Date: Mon, 15 May 2023 12:14:51 -0400 Subject: [PATCH 1/4] rTorrent: Parallel dependency installation This commit allows modular and parallel building of rTorrent dependencies. Output is appended to `swizzin.log` afterwards more cleanly than before. Temporary log files are used to prevent race conditions from happening. Threads counts and task concurrency are limited to ensure stable installation times. --- sources/build/libudns.sh | 18 ++++++++++++++ sources/build/mktorrent.sh | 18 ++++++++++++++ sources/functions/rtorrent | 51 +++++++++++++++++++++++--------------- 3 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 sources/build/libudns.sh create mode 100644 sources/build/mktorrent.sh diff --git a/sources/build/libudns.sh b/sources/build/libudns.sh new file mode 100644 index 000000000..a69587a46 --- /dev/null +++ b/sources/build/libudns.sh @@ -0,0 +1,18 @@ +#!/usr/bin/bash +# libudns Builder + +udnslog=$1 + +source /etc/swizzin/sources/functions/utils +rm_if_exists $udnslog +touch $udnslog + +rm_if_exists "/tmp/udns" +git clone -q https://github.com/shadowsocks/libudns /tmp/udns >> $udnslog 2>&1 +cd /tmp/udns +./autogen.sh >> $udnslog 2>&1 +./configure --prefix=/usr >> $udnslog 2>&1 +make CFLAGS="-w -flto -O2 -fPIC" >> $udnslog 2>&1 +make -s install >> $udnslog 2>&1 +cd /tmp +rm -rf udns* diff --git a/sources/build/mktorrent.sh b/sources/build/mktorrent.sh new file mode 100644 index 000000000..061a752a7 --- /dev/null +++ b/sources/build/mktorrent.sh @@ -0,0 +1,18 @@ +#!/usr/bin/bash +# mktorrent Builder + +mklog=$1 + +source /etc/swizzin/sources/functions/utils +rm_if_exists $mklog +touch $mklog + +cd /tmp +curl -sL https://github.com/Rudde/mktorrent/archive/v1.1.zip -o mktorrent.zip >> $mklog 2>&1 +rm_if_exists "/tmp/mktorrent" +unzip -d mktorrent -j mktorrent.zip >> $mklog 2>&1 +cd mktorrent +make >> $mklog 2>&1 +make install PREFIX=/usr >> $mklog 2>&1 +cd /tmp +rm -rf mktorrent* diff --git a/sources/functions/rtorrent b/sources/functions/rtorrent index 954a485c6..7d3055b37 100644 --- a/sources/functions/rtorrent +++ b/sources/functions/rtorrent @@ -82,6 +82,21 @@ function configure_rtorrent() { } function depends_rtorrent() { + # mktorrent and libudns from source + echo_info "Building source dependencies" + local mklog="/root/logs/mktorrent.log" + local udnslog="/root/logs/libudns.log" + bash "/etc/swizzin/sources/build/mktorrent.sh" $mklog & + if [[ ${libudns} == "true" ]]; then + bash "/etc/swizzin/sources/build/libudns.sh" $udnslog & + fi + + # wait for building to complete if less than 4 threads, otherwise it will take longer + if [ $(nproc) -lt 4 ]; then + wait + fi + + # package installation of dependencies if [[ ! $rtorrentver == repo ]]; then APT='subversion dos2unix bc screen zip unzip sysstat build-essential comerr-dev dstat automake libtool libcppunit-dev libssl-dev pkg-config libcurl4-openssl-dev @@ -96,31 +111,27 @@ function depends_rtorrent() { apt_install $APT fi - # mktorrent from source - cd /tmp - curl -sL https://github.com/Rudde/mktorrent/archive/v1.1.zip -o mktorrent.zip >> $log 2>&1 - . /etc/swizzin/sources/functions/utils - rm_if_exists "/tmp/mktorrent" - unzip -d mktorrent -j mktorrent.zip >> $log 2>&1 - cd mktorrent - make >> $log 2>&1 - make install PREFIX=/usr >> $log 2>&1 - cd /tmp - rm -rf mktorrent* + # Wait for build tasks to complete + wait - # libudns from source + # mktorrent and udns log append + rt_build_log_append "mktorrent" $mklog if [[ ${libudns} == "true" ]]; then - git clone -q https://github.com/shadowsocks/libudns /tmp/udns >> $log 2>&1 - cd /tmp/udns - ./autogen.sh >> $log 2>&1 - ./configure --prefix=/usr >> $log 2>&1 - make -j$(nproc) CFLAGS="-w ${rtorrentflto} ${rtorrentpipe} -O2 -fPIC" >> $log 2>&1 - make -s install >> $log 2>&1 - cd /tmp - rm -rf udns* + rt_build_log_append "libudns" $udnslog fi } +function rt_build_log_append() { + local binary=$1 + local file=$2 + + echo -e "\nBegin of $binary build log" >> $log 2>&1 + cat $file >> $log 2>&1 + echo -e "End of $binary build log\n" >> $log 2>&1 + . /etc/swizzin/sources/functions/utils + rm_if_exists $file +} + function build_xmlrpc-c() { cd "/tmp" . /etc/swizzin/sources/functions/utils From e7b4b7dd7eeb200a71e6043c151fb3da35044469 Mon Sep 17 00:00:00 2001 From: stickz Date: Tue, 16 May 2023 06:16:04 -0400 Subject: [PATCH 2/4] rTorrent: Source file preparation --- sources/build/prepare_lt_rakshasa.sh | 66 +++++++++++ sources/build/prepare_rtorrent.sh | 52 +++++++++ sources/build/prepare_xmlrpc.sh | 20 ++++ sources/functions/rtorrent | 159 +++++++++++---------------- 4 files changed, 202 insertions(+), 95 deletions(-) create mode 100644 sources/build/prepare_lt_rakshasa.sh create mode 100644 sources/build/prepare_rtorrent.sh create mode 100644 sources/build/prepare_xmlrpc.sh diff --git a/sources/build/prepare_lt_rakshasa.sh b/sources/build/prepare_lt_rakshasa.sh new file mode 100644 index 000000000..1f3285d7a --- /dev/null +++ b/sources/build/prepare_lt_rakshasa.sh @@ -0,0 +1,66 @@ +#!/usr/bin/bash +# libtorrent rakshasa source file preperation + +llog=$1 +elog=$2 +tpath=$3 +version=$4 +udns=$5 +libtorrentloc="https://github.com/rakshasa/libtorrent/archive/refs/tags/v${version}.tar.gz" + +source /etc/swizzin/sources/functions/utils +rm_if_exists $llog +rm_if_exists $elog +rm_if_exists $tpath +touch $llog +touch $elog +mkdir $tpath + +curl -sL $libtorrentloc -o "$tpath-$version.tar.gz" +tar -xf "$tpath-$version.tar.gz" -C $tpath --strip-components=1 >> $llog 2>&1 +rm_if_exists "$tpath-$version.tar.gz" + +cd $tpath >> $llog 2>&1 + +# Look for custom source file patches based on the libtorrent version +if [[ -f /root/libtorrent-rakshasa-$version.patch ]]; then + patch -p1 < /root/libtorrent-rakshasa-$version.patch >> $llog 2>&1 || { + echo "Something went wrong when patching libtorrent-rakshasa" >> $elog 2>&1 + rm_if_exists $tpath + exit 1 + } + echo "Libtorrent-rakshasa patch found and applied!" >> $llog 2>&1 +else + echo "No libtorrent-rakshasa patch found at /root/libtorrent-rakshasa-$version.patch" >> $llog 2>&1 +fi + +# Apply source file patches based on the libtorrent version +case $version in + 0.13.6) + patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 + if pkg-config --atleast-version=1.14 cppunit; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/cppunit-libtorrent.patch >> $llog 2>&1 + fi + patch -p1 < /etc/swizzin/sources/patches/rtorrent/bencode-libtorrent.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.6.patch >> $llog 2>&1 + ;; + + 0.13.7) + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 + ;; + + 0.13.8) + if [[ $udns == "true" ]]; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-udns-0.13.8.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-scanf-0.13.8.patch >> $llog 2>&1 + fi + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 + ;; +esac + +# Generate source files for compile +./autogen.sh >> $llog 2>&1 + +# Echo PASSED to elog if we make it this far +echo "PASSED" >> $elog 2>&1 diff --git a/sources/build/prepare_rtorrent.sh b/sources/build/prepare_rtorrent.sh new file mode 100644 index 000000000..778237319 --- /dev/null +++ b/sources/build/prepare_rtorrent.sh @@ -0,0 +1,52 @@ +#!/usr/bin/bash +# rtorrent source file preperation + +rlog=$1 +elog=$2 +tpath=$3 +version=$4 +udns=$5 +rtorrentloc="https://github.com/rakshasa/rtorrent/archive/refs/tags/v$version.tar.gz" + +source /etc/swizzin/sources/functions/utils +rm_if_exists $rlog +rm_if_exists $elog +rm_if_exists $tpath +touch $rlog +touch $elog +mkdir $tpath + +curl -sL $rtorrentloc -o "$tpath-$version.tar.gz" +tar -xf "$tpath-$version.tar.gz" -C $tpath --strip-components=1 >> $rlog 2>&1 +rm_if_exists "$tpath-$version.tar.gz" + +cd $tpath >> $rlog 2>&1 +# Look for custom source file patches based on the rtorrent version +if [[ -f /root/rtorrent-$version.patch ]]; then + patch -p1 < /root/rtorrent-$version.patch >> $rlog 2>&1 || { + echo "Something went wrong when patching rTorrent" >> $elog 2>&1 + rm_if_exists $tpath + exit 1 + } + echo "rTorrent patch found and applied!" >> $rlog 2>&1 +else + echo "No rTorrent patch found at /root/rtorrent-$version.patch" >> $rlog 2>&1 +fi +# Apply tracker scape patch for rTorrent if udns is enabled +if [[ $udns == "true" ]]; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/rtorrent-scrape-0.9.8.patch >> $rlog 2>&1 +fi +# Apply lockfile-fix to all rtorrents +patch -p1 < /etc/swizzin/sources/patches/rtorrent/lockfile-fix.patch >> $rlog 2>&1 +# Apply xmlrpc-fix to all rtorrents +patch -p1 < /etc/swizzin/sources/patches/rtorrent/xmlrpc-fix.patch >> $rlog 2>&1 +# Use pkgconfig for cppunit if 0.9.6 +if [[ $version == "0.9.6" ]]; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/rtorrent-0.9.6.patch >> $rlog 2>&1 +fi + +# Generate source files for compile +./autogen.sh >> $rlog 2>&1 + +# Echo PASSED to elog if we make it this far +echo "PASSED" >> $elog 2>&1 diff --git a/sources/build/prepare_xmlrpc.sh b/sources/build/prepare_xmlrpc.sh new file mode 100644 index 000000000..1954a1038 --- /dev/null +++ b/sources/build/prepare_xmlrpc.sh @@ -0,0 +1,20 @@ +#!/usr/bin/bash +# xmlrpc-c source file preperation + +xlog=$1 +tpath=$2 +XMLRPC_REV=2954 + +source /etc/swizzin/sources/functions/utils +rm_if_exists $xlog +rm_if_exists $tpath +touch $xlog +mkdir $tpath + +svn co http://svn.code.sf.net/p/xmlrpc-c/code/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 || { + svn co https://github.com/mirror/xmlrpc-c/trunk/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1; +} + +cd $tpath >> $xlog 2>&1 +cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.guess config.guess >> $xlog 2>&1 +cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.sub config.sub >> $xlog 2>&1 diff --git a/sources/functions/rtorrent b/sources/functions/rtorrent index 7d3055b37..441f6111a 100644 --- a/sources/functions/rtorrent +++ b/sources/functions/rtorrent @@ -82,20 +82,12 @@ function configure_rtorrent() { } function depends_rtorrent() { - # mktorrent and libudns from source - echo_info "Building source dependencies" - local mklog="/root/logs/mktorrent.log" - local udnslog="/root/logs/libudns.log" - bash "/etc/swizzin/sources/build/mktorrent.sh" $mklog & - if [[ ${libudns} == "true" ]]; then - bash "/etc/swizzin/sources/build/libudns.sh" $udnslog & - fi - - # wait for building to complete if less than 4 threads, otherwise it will take longer + build_deps_rtorrent + sources_rtorrent + # wait for tasks to complete if less than 4 threads, otherwise it will take longer if [ $(nproc) -lt 4 ]; then wait fi - # package installation of dependencies if [[ ! $rtorrentver == repo ]]; then APT='subversion dos2unix bc screen zip unzip sysstat build-essential comerr-dev @@ -110,38 +102,74 @@ function depends_rtorrent() { APT='screen zip unzip bc mediainfo curl' apt_install $APT fi - - # Wait for build tasks to complete + # Wait for tasks to complete wait - - # mktorrent and udns log append - rt_build_log_append "mktorrent" $mklog + log_deps_rtorrent +} +function build_deps_rtorrent() { + # mktorrent and libudns from source + echo_info "Building source dependencies" + mklog="/root/logs/mktorrent.log" + udnslog="/root/logs/libudns.log" + bash "/etc/swizzin/sources/build/mktorrent.sh" $mklog & if [[ ${libudns} == "true" ]]; then - rt_build_log_append "libudns" $udnslog + bash "/etc/swizzin/sources/build/libudns.sh" $udnslog & fi } - -function rt_build_log_append() { +function sources_rtorrent() { + echo_info "Preparing source files" + # Prepare xmlrpc source files + xlog="/root/logs/xmlrpc.log" + xpath="/tmp/xmlrpc-c" + bash "/etc/swizzin/sources/build/prepare_xmlrpc.sh" $xlog $xpath & + # Prepare libtorrent source files + llog="/root/logs/lt_rakshasa.log" + lelog="/root/logs/lt_rkshasa_errors.log" + lpath="/tmp/libtorrent" + bash "/etc/swizzin/sources/build/prepare_lt_rakshasa.sh" $llog $lelog $lpath $libtorrentver $libudns & + # Prepare rtorrent source files + rlog="/root/logs/rtorrent.log" + relog="/root/logs/rtorrent_errors.log" + rpath="/tmp/rtorrent" + bash "/etc/swizzin/sources/build/prepare_rtorrent.sh" $rlog $relog $rpath $rtorrentver $libudns & +} +function log_deps_rtorrent() { + # Append output to swizzin log file and remove log files + rt_log_append "mktorrent" $mklog "build" + if [[ ${libudns} == "true" ]]; then + rt_log_append "libudns" $udnslog "build" + fi + rt_log_append "xmlrc" $xlog "prepare" + rt_log_append "libtorrent" $llog "prepare" + rt_log_append "rtorrent" $rlog "prepare" + # Check for errors, remove error files and exit script on error + rt_error_check $lelog + rt_error_check $relog +} +function rt_log_append() { local binary=$1 local file=$2 - - echo -e "\nBegin of $binary build log" >> $log 2>&1 + local type=$3 + echo -e "\nBegin of $binary $type log" >> $log 2>&1 cat $file >> $log 2>&1 - echo -e "End of $binary build log\n" >> $log 2>&1 + echo -e "End of $binary $type log\n" >> $log 2>&1 . /etc/swizzin/sources/functions/utils rm_if_exists $file } - -function build_xmlrpc-c() { - cd "/tmp" +function rt_error_check() { + local file=$1 . /etc/swizzin/sources/functions/utils - rm_if_exists "/tmp/xmlrpc-c" - rm_if_exists "/tmp/dist/xmlrpc-c " - XMLRPC_REV=2954 - svn co http://svn.code.sf.net/p/xmlrpc-c/code/advanced@$XMLRPC_REV /tmp/xmlrpc-c >> $log 2>&1 || { svn co https://github.com/mirror/xmlrpc-c/trunk/advanced@$XMLRPC_REV /tmp/xmlrpc-c >> $log 2>&1; } - cd /tmp/xmlrpc-c - cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.guess config.guess >> $log 2>&1 - cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.sub config.sub >> $log 2>&1 + if [[ $(grep -c "PASSED" $file) -lt 1 ]]; then + local error=$(cat $file) + echo_error $error + rm_if_exists $file + exit 1 + fi + rm_if_exists $file +} + +function build_xmlrpc-c() { + cd "/tmp/xmlrpc-c" ./configure --prefix=/usr --disable-cplusplus --disable-wininet-client --disable-libwww-client >> $log 2>&1 || { echo_error "Something went wrong while configuring xmlrpc" exit 1 @@ -162,43 +190,8 @@ function build_xmlrpc-c() { } function build_libtorrent_rakshasa() { - libtorrentloc="https://github.com/rakshasa/libtorrent/archive/refs/tags/v${libtorrentver}.tar.gz" - cd "/tmp" - . /etc/swizzin/sources/functions/utils - rm_if_exists "/tmp/libtorrent" - mkdir /tmp/libtorrent - curl -sL ${libtorrentloc} -o /tmp/libtorrent-${libtorrentver}.tar.gz VERSION=$libtorrentver - tar -xf /tmp/libtorrent-${libtorrentver}.tar.gz -C /tmp/libtorrent --strip-components=1 >> $log 2>&1 - cd /tmp/libtorrent >> $log 2>&1 - - if [[ -f /root/libtorrent-rakshasa-${libtorrentver}.patch ]]; then - patch -p1 < /root/libtorrent-rakshasa-${libtorrentver}.patch >> ${log} 2>&1 || { - echo _error "Something went wrong when patching libtorrent-rakshasa" - exit 1 - } - echo_info "Libtorrent-rakshasa patch found and applied!" - else - echo_log_only "No libtorrent-rakshasa patch found at /root/libtorrent-rakshasa-${libtorrentver}.patch" - fi - if [[ ${libudns} == "true" ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-udns-0.13.8.patch >> "$log" 2>&1 - patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-scanf-0.13.8.patch >> "$log" 2>&1 - fi - if [[ ${libtorrentver} =~ ^("0.13.7"|"0.13.8")$ ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> "$log" 2>&1 - fi - if [[ ${libtorrentver} =~ ^("0.13.6"|"0.13.7")$ ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> "$log" 2>&1 - if pkg-config --atleast-version=1.14 cppunit && [[ ${libtorrentver} == 0.13.6 ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/cppunit-libtorrent.patch >> "$log" 2>&1 - fi - if [[ ${libtorrentver} == "0.13.6" ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/bencode-libtorrent.patch >> "$log" 2>&1 - patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.6.patch >> "$log" 2>&1 - fi - fi - ./autogen.sh >> $log 2>&1 + cd "/tmp/libtorrent" ./configure --prefix=/usr >> $log 2>&1 || { echo_error "Something went wrong while configuring libtorrent" exit 1 @@ -218,38 +211,12 @@ function build_libtorrent_rakshasa() { } function build_rtorrent() { - rtorrentloc="https://github.com/rakshasa/rtorrent/archive/refs/tags/v${rtorrentver}.tar.gz" - cd "/tmp" - . /etc/swizzin/sources/functions/utils - rm_if_exists "/tmp/rtorrent*" - mkdir /tmp/rtorrent - curl -sL ${rtorrentloc} -o /tmp/rtorrent-${rtorrentver}.tar.gz - tar -xzf /tmp/rtorrent-${rtorrentver}.tar.gz -C /tmp/rtorrent --strip-components=1 >> $log 2>&1 + cd "/tmp/rtorrent" VERSION=$rtorrentver - cd /tmp/rtorrent - if [[ -f /root/rtorrent-${rtorrentver}.patch ]]; then - patch -p1 < /root/rtorrent-${rtorrentver}.patch >> ${log} 2>&1 || { - echo _error "Something went wrong when patching rTorrent" - exit 1 - } - echo_info "rTorrent patch found and applied!" - else - echo_log_only "No rTorrent patch found at /root/rtorrent-${rtorrentver}.patch" - fi - if [[ ${libudns} == "true" ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/rtorrent-scrape-0.9.8.patch >> "$log" 2>&1 - fi - #apply lockfile-fix to all rtorrents - patch -p1 < /etc/swizzin/sources/patches/rtorrent/lockfile-fix.patch >> "$log" 2>&1 - #apply xmlrpc-fix to all rtorrents - patch -p1 < /etc/swizzin/sources/patches/rtorrent/xmlrpc-fix.patch >> "$log" 2>&1 - #use pkgconfig for cppunit if 0.9.6 stdc= if [[ ${rtorrentver} == "0.9.6" ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/rtorrent-0.9.6.patch >> "$log" 2>&1 stdc="-std=c++11" fi - ./autogen.sh >> $log 2>&1 ./configure --prefix=/usr --with-xmlrpc-c >> $log 2>&1 || { echo_error "Something went wrong while configuring rtorrent" exit 1 @@ -267,6 +234,8 @@ function build_rtorrent() { ldconfig >> $log 2>&1 rm -rf rtorrent* >> $log 2>&1 rm -rf /tmp/dist/rtorrent + rm_if_exists /root/dist + rm_if_exists /tmp/dist apt-mark hold rtorrent >> ${log} 2>&1 } From e5b263027b3631a6b8a21007080c366b04ffe2bc Mon Sep 17 00:00:00 2001 From: stickz Date: Tue, 16 May 2023 07:56:20 -0400 Subject: [PATCH 3/4] Fix formatting --- sources/build/prepare_lt_rakshasa.sh | 38 ++++++++++++++-------------- sources/build/prepare_xmlrpc.sh | 4 +-- sources/functions/rtorrent | 6 ++--- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/sources/build/prepare_lt_rakshasa.sh b/sources/build/prepare_lt_rakshasa.sh index 1f3285d7a..72cc60cdd 100644 --- a/sources/build/prepare_lt_rakshasa.sh +++ b/sources/build/prepare_lt_rakshasa.sh @@ -36,27 +36,27 @@ fi # Apply source file patches based on the libtorrent version case $version in - 0.13.6) - patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 - if pkg-config --atleast-version=1.14 cppunit; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/cppunit-libtorrent.patch >> $llog 2>&1 - fi - patch -p1 < /etc/swizzin/sources/patches/rtorrent/bencode-libtorrent.patch >> $llog 2>&1 - patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.6.patch >> $llog 2>&1 - ;; + 0.13.6) + patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 + if pkg-config --atleast-version=1.14 cppunit; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/cppunit-libtorrent.patch >> $llog 2>&1 + fi + patch -p1 < /etc/swizzin/sources/patches/rtorrent/bencode-libtorrent.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.6.patch >> $llog 2>&1 + ;; - 0.13.7) - patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 - patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 - ;; + 0.13.7) + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/openssl.patch >> $llog 2>&1 + ;; - 0.13.8) - if [[ $udns == "true" ]]; then - patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-udns-0.13.8.patch >> $llog 2>&1 - patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-scanf-0.13.8.patch >> $llog 2>&1 - fi - patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 - ;; + 0.13.8) + if [[ $udns == "true" ]]; then + patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-udns-0.13.8.patch >> $llog 2>&1 + patch -p1 < /etc/swizzin/sources/patches/rtorrent/libtorrent-scanf-0.13.8.patch >> $llog 2>&1 + fi + patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 + ;; esac # Generate source files for compile diff --git a/sources/build/prepare_xmlrpc.sh b/sources/build/prepare_xmlrpc.sh index 1954a1038..b1f3caff5 100644 --- a/sources/build/prepare_xmlrpc.sh +++ b/sources/build/prepare_xmlrpc.sh @@ -11,8 +11,8 @@ rm_if_exists $tpath touch $xlog mkdir $tpath -svn co http://svn.code.sf.net/p/xmlrpc-c/code/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 || { - svn co https://github.com/mirror/xmlrpc-c/trunk/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1; +svn co http://svn.code.sf.net/p/xmlrpc-c/code/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 || { + svn co https://github.com/mirror/xmlrpc-c/trunk/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 } cd $tpath >> $xlog 2>&1 diff --git a/sources/functions/rtorrent b/sources/functions/rtorrent index 441f6111a..21e5b550b 100644 --- a/sources/functions/rtorrent +++ b/sources/functions/rtorrent @@ -120,7 +120,7 @@ function sources_rtorrent() { echo_info "Preparing source files" # Prepare xmlrpc source files xlog="/root/logs/xmlrpc.log" - xpath="/tmp/xmlrpc-c" + xpath="/tmp/xmlrpc-c" bash "/etc/swizzin/sources/build/prepare_xmlrpc.sh" $xlog $xpath & # Prepare libtorrent source files llog="/root/logs/lt_rakshasa.log" @@ -137,7 +137,7 @@ function log_deps_rtorrent() { # Append output to swizzin log file and remove log files rt_log_append "mktorrent" $mklog "build" if [[ ${libudns} == "true" ]]; then - rt_log_append "libudns" $udnslog "build" + rt_log_append "libudns" $udnslog "build" fi rt_log_append "xmlrc" $xlog "prepare" rt_log_append "libtorrent" $llog "prepare" @@ -168,7 +168,7 @@ function rt_error_check() { rm_if_exists $file } -function build_xmlrpc-c() { +function build_xmlrpc-c() { cd "/tmp/xmlrpc-c" ./configure --prefix=/usr --disable-cplusplus --disable-wininet-client --disable-libwww-client >> $log 2>&1 || { echo_error "Something went wrong while configuring xmlrpc" From 56a712f8ca1a44d95b2a3d54f1c6b0dd993064e0 Mon Sep 17 00:00:00 2001 From: stickz Date: Tue, 30 May 2023 07:40:36 -0400 Subject: [PATCH 4/4] rTorrent: Refactor Fixes --- scripts/remove/rtorrent.sh | 6 +-- scripts/upgrade/rtorrent.sh | 10 ++-- sources/build/prepare_lt_rakshasa.sh | 10 ++-- sources/build/prepare_rtorrent.sh | 4 +- sources/build/prepare_xmlrpc.sh | 7 ++- sources/functions/rtorrent | 70 ++++++++++++++++------------ 6 files changed, 60 insertions(+), 47 deletions(-) diff --git a/scripts/remove/rtorrent.sh b/scripts/remove/rtorrent.sh index 5e715cd3c..f2d3e2461 100755 --- a/scripts/remove/rtorrent.sh +++ b/scripts/remove/rtorrent.sh @@ -12,14 +12,14 @@ for u in ${users}; do rm -f /home/${u}/.rtorrent.rc done +# We need to run our own script to ensure xmlrpc and libtorrent is removed properly. We can't relay on apt remove. . /etc/swizzin/sources/functions/rtorrent isdeb=$(dpkg -l | grep rtorrent) echo_progress_start "Removing old rTorrent binaries and libraries ... " -if [[ -z $isdeb ]]; then - remove_rtorrent_legacy -else +if [[ -n $isdeb ]]; then remove_rtorrent fi +remove_rtorrent_legacy echo_progress_done for a in rutorrent flood; do diff --git a/scripts/upgrade/rtorrent.sh b/scripts/upgrade/rtorrent.sh index 672f7f3b0..e950fc0f0 100755 --- a/scripts/upgrade/rtorrent.sh +++ b/scripts/upgrade/rtorrent.sh @@ -22,14 +22,14 @@ if [[ -n $noexec ]]; then mount -o remount,exec /tmp noexec=1 fi + +# Upgrade script will automatically remove left over binares, we only need to remove apt packages ourselves isdeb=$(dpkg -l | grep rtorrent) -echo_progress_start "Removing old rTorrent binaries and libraries ... " -if [[ -z $isdeb ]]; then - remove_rtorrent_legacy -else +if [[ -n $isdeb ]]; then + echo_progress_start "Removing old rTorrent binaries and libraries ... " remove_rtorrent + echo_progress_done fi -echo_progress_done echo_progress_start "Checking rTorrent Dependencies ... " depends_rtorrent diff --git a/sources/build/prepare_lt_rakshasa.sh b/sources/build/prepare_lt_rakshasa.sh index 72cc60cdd..81055cfc3 100644 --- a/sources/build/prepare_lt_rakshasa.sh +++ b/sources/build/prepare_lt_rakshasa.sh @@ -16,12 +16,12 @@ touch $llog touch $elog mkdir $tpath +# Retreive libtorrent then extract and remove tar.gz file curl -sL $libtorrentloc -o "$tpath-$version.tar.gz" tar -xf "$tpath-$version.tar.gz" -C $tpath --strip-components=1 >> $llog 2>&1 rm_if_exists "$tpath-$version.tar.gz" - +# Change directory to libtorrent temp path cd $tpath >> $llog 2>&1 - # Look for custom source file patches based on the libtorrent version if [[ -f /root/libtorrent-rakshasa-$version.patch ]]; then patch -p1 < /root/libtorrent-rakshasa-$version.patch >> $llog 2>&1 || { @@ -33,7 +33,6 @@ if [[ -f /root/libtorrent-rakshasa-$version.patch ]]; then else echo "No libtorrent-rakshasa patch found at /root/libtorrent-rakshasa-$version.patch" >> $llog 2>&1 fi - # Apply source file patches based on the libtorrent version case $version in 0.13.6) @@ -58,9 +57,10 @@ case $version in patch -p1 < /etc/swizzin/sources/patches/rtorrent/throttle-fix-0.13.7-8.patch >> $llog 2>&1 ;; esac - # Generate source files for compile ./autogen.sh >> $llog 2>&1 - +# Whipe any existing libtorrent binaries +./configure --prefix=/usr >> $llog 2>&1 +make uninstall >> $llog 2>&1 # Echo PASSED to elog if we make it this far echo "PASSED" >> $elog 2>&1 diff --git a/sources/build/prepare_rtorrent.sh b/sources/build/prepare_rtorrent.sh index 778237319..e2882fbc3 100644 --- a/sources/build/prepare_rtorrent.sh +++ b/sources/build/prepare_rtorrent.sh @@ -44,9 +44,9 @@ patch -p1 < /etc/swizzin/sources/patches/rtorrent/xmlrpc-fix.patch >> $rlog 2>&1 if [[ $version == "0.9.6" ]]; then patch -p1 < /etc/swizzin/sources/patches/rtorrent/rtorrent-0.9.6.patch >> $rlog 2>&1 fi - # Generate source files for compile ./autogen.sh >> $rlog 2>&1 - +# Remove any existing rtorrent binaries +rm -rf /usr/bin/rtorrent >> $rlog 2>&1 # Echo PASSED to elog if we make it this far echo "PASSED" >> $elog 2>&1 diff --git a/sources/build/prepare_xmlrpc.sh b/sources/build/prepare_xmlrpc.sh index b1f3caff5..11960ba2c 100644 --- a/sources/build/prepare_xmlrpc.sh +++ b/sources/build/prepare_xmlrpc.sh @@ -11,10 +11,15 @@ rm_if_exists $tpath touch $xlog mkdir $tpath +# Retreive xmlrpc source code svn co http://svn.code.sf.net/p/xmlrpc-c/code/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 || { svn co https://github.com/mirror/xmlrpc-c/trunk/advanced@$XMLRPC_REV $tpath >> $xlog 2>&1 } - +# Change directory to xmlrpc temp path cd $tpath >> $xlog 2>&1 +# Patch latest CPU architectures, so configure works properly on ARM64 cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.guess config.guess >> $xlog 2>&1 cp -rf /etc/swizzin/sources/patches/rtorrent/xmlrpc-config.sub config.sub >> $xlog 2>&1 +# Whipe any existing xmlrpc binaries +./configure >> $xlog 2>&1 +make uninstall >> $xlog 2>&1 diff --git a/sources/functions/rtorrent b/sources/functions/rtorrent index 21e5b550b..52b867d90 100644 --- a/sources/functions/rtorrent +++ b/sources/functions/rtorrent @@ -118,20 +118,25 @@ function build_deps_rtorrent() { } function sources_rtorrent() { echo_info "Preparing source files" - # Prepare xmlrpc source files + # Create logging and temp paths for xmlrpc, libtorrent and rtorrent + rt_create_source_paths + # Prepare xmlrpc, libtorrent and rtorrent source files + bash "/etc/swizzin/sources/build/prepare_xmlrpc.sh" $xlog $xpath & + bash "/etc/swizzin/sources/build/prepare_lt_rakshasa.sh" $llog $lelog $lpath $libtorrentver $libudns & + bash "/etc/swizzin/sources/build/prepare_rtorrent.sh" $rlog $relog $rpath $rtorrentver $libudns & +} +function rt_create_source_paths() { + # XMLRPC-C xlog="/root/logs/xmlrpc.log" xpath="/tmp/xmlrpc-c" - bash "/etc/swizzin/sources/build/prepare_xmlrpc.sh" $xlog $xpath & - # Prepare libtorrent source files + # Libtorrent llog="/root/logs/lt_rakshasa.log" lelog="/root/logs/lt_rkshasa_errors.log" lpath="/tmp/libtorrent" - bash "/etc/swizzin/sources/build/prepare_lt_rakshasa.sh" $llog $lelog $lpath $libtorrentver $libudns & - # Prepare rtorrent source files + # rTorrent rlog="/root/logs/rtorrent.log" relog="/root/logs/rtorrent_errors.log" rpath="/tmp/rtorrent" - bash "/etc/swizzin/sources/build/prepare_rtorrent.sh" $rlog $relog $rpath $rtorrentver $libudns & } function log_deps_rtorrent() { # Append output to swizzin log file and remove log files @@ -142,9 +147,13 @@ function log_deps_rtorrent() { rt_log_append "xmlrc" $xlog "prepare" rt_log_append "libtorrent" $llog "prepare" rt_log_append "rtorrent" $rlog "prepare" - # Check for errors, remove error files and exit script on error + # Check for errors, remove error files rt_error_check $lelog rt_error_check $relog + # Exit script if error is found when checking + if [[ $rtinstallerror == "true" ]]; then + exit 1 + fi } function rt_log_append() { local binary=$1 @@ -158,18 +167,18 @@ function rt_log_append() { } function rt_error_check() { local file=$1 + rtinstallerror="false" . /etc/swizzin/sources/functions/utils if [[ $(grep -c "PASSED" $file) -lt 1 ]]; then local error=$(cat $file) echo_error $error - rm_if_exists $file - exit 1 + rtinstallerror="true" fi rm_if_exists $file } function build_xmlrpc-c() { - cd "/tmp/xmlrpc-c" + cd $xpath ./configure --prefix=/usr --disable-cplusplus --disable-wininet-client --disable-libwww-client >> $log 2>&1 || { echo_error "Something went wrong while configuring xmlrpc" exit 1 @@ -184,14 +193,13 @@ function build_xmlrpc-c() { mkdir -p /root/dist fpm -f -C /tmp/dist/xmlrpc-c -p /root/dist/xmlrpc-c_VERSION.deb -s dir -t deb -n xmlrpc-c --version ${VERSION} --description "xmlrpc-c compiled by swizzin" > /dev/null 2>&1 dpkg -i /root/dist/xmlrpc-c_${VERSION}.deb >> $log 2>&1 - cd /tmp - rm -rf xmlrpc-c + rm -rf $xpath rm -rf /tmp/dist/xmlrpc-c } function build_libtorrent_rakshasa() { VERSION=$libtorrentver - cd "/tmp/libtorrent" + cd $lpath ./configure --prefix=/usr >> $log 2>&1 || { echo_error "Something went wrong while configuring libtorrent" exit 1 @@ -205,13 +213,12 @@ function build_libtorrent_rakshasa() { mkdir -p /root/dist fpm -f -C /tmp/dist/libtorrent-rakshasa -p /root/dist/libtorrent-rakshasa_VERSION.deb -s dir -t deb -n libtorrent-rakshasa --version ${VERSION} --description "libtorrent-rakshasa compiled by swizzin" > /dev/null 2>&1 dpkg -i /root/dist/libtorrent-rakshasa_${VERSION}.deb >> $log 2>&1 - cd /tmp rm -rf /tmp/dist/libtorrent-rakshasa - rm -rf libtorrent* + rm -rf $lpath } function build_rtorrent() { - cd "/tmp/rtorrent" + cd $rpath VERSION=$rtorrentver stdc= if [[ ${rtorrentver} == "0.9.6" ]]; then @@ -230,9 +237,8 @@ function build_rtorrent() { mkdir -p /root/dist fpm -f -C /tmp/dist/rtorrent -p /root/dist/rtorrent_VERSION.deb -s dir -t deb -n rtorrent --version ${VERSION} --description "rtorrent compiled by swizzin" > /dev/null 2>&1 dpkg -i /root/dist/rtorrent_${VERSION}.deb >> $log 2>&1 - cd "/tmp" ldconfig >> $log 2>&1 - rm -rf rtorrent* >> $log 2>&1 + rm -rf $rpath >> $log 2>&1 rm -rf /tmp/dist/rtorrent rm_if_exists /root/dist rm_if_exists /tmp/dist @@ -249,20 +255,22 @@ function remove_rtorrent() { if [[ -n $repo ]]; then toclean+=($repo) fi - for c in ${toclean[@]}; do - # TODO add option to pass extra flags - apt-get remove -y -q --allow-change-held-packages $c >> $log 2>&1 - done + apt_remove --purge $toclean } function remove_rtorrent_legacy() { - rm -rf /usr/bin/rtorrent - cd /tmp - git clone https://github.com/rakshasa/libtorrent.git libtorrent >> /dev/null 2>&1 - cd libtorrent - ./autogen.sh >> $log 2>&1 - ./configure --prefix=/usr >> $log 2>&1 - make uninstall >> $log 2>&1 - cd - - rm -rf /tmp/libtorrent + # Create logging and temp paths for xmlrpc and libtorrent + rt_create_source_paths + # Run prepare script to remove xmlrpc and libtorrent using make uninstall + bash "/etc/swizzin/sources/build/prepare_xmlrpc.sh" $xlog $xpath & + bash "/etc/swizzin/sources/build/prepare_lt_rakshasa.sh" $llog "/dev/null" $lpath "0.13.8" "false" & + # Remove rtorrent from the bin file + rm -rf /usr/bin/rtorrent >> $log 2>&1 + # Wait for make uninstall to complete + wait + # Log our actions and remove temp files + rt_log_append "xmlrc" $xlog "remove" + rt_log_append "libtorrent" $llog "remove" + rm_if_exists $xpath + rm_if_exists $lpath }