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/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/build/prepare_lt_rakshasa.sh b/sources/build/prepare_lt_rakshasa.sh new file mode 100644 index 000000000..81055cfc3 --- /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 + +# 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 || { + 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 +# 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 new file mode 100644 index 000000000..e2882fbc3 --- /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 +# 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 new file mode 100644 index 000000000..11960ba2c --- /dev/null +++ b/sources/build/prepare_xmlrpc.sh @@ -0,0 +1,25 @@ +#!/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 + +# 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 954a485c6..52b867d90 100644 --- a/sources/functions/rtorrent +++ b/sources/functions/rtorrent @@ -82,6 +82,13 @@ function configure_rtorrent() { } function depends_rtorrent() { + 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 dstat automake libtool libcppunit-dev libssl-dev pkg-config libcurl4-openssl-dev @@ -95,42 +102,83 @@ function depends_rtorrent() { APT='screen zip unzip bc mediainfo curl' 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* - - # libudns from source + # Wait for tasks to complete + wait + 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 + bash "/etc/swizzin/sources/build/libudns.sh" $udnslog & + fi +} +function sources_rtorrent() { + echo_info "Preparing 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" + # Libtorrent + llog="/root/logs/lt_rakshasa.log" + lelog="/root/logs/lt_rkshasa_errors.log" + lpath="/tmp/libtorrent" + # rTorrent + rlog="/root/logs/rtorrent.log" + relog="/root/logs/rtorrent_errors.log" + rpath="/tmp/rtorrent" +} +function log_deps_rtorrent() { + # Append output to swizzin log file and remove log files + rt_log_append "mktorrent" $mklog "build" 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_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 + 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 + local file=$2 + local type=$3 + echo -e "\nBegin of $binary $type log" >> $log 2>&1 + cat $file >> $log 2>&1 + echo -e "End of $binary $type log\n" >> $log 2>&1 + . /etc/swizzin/sources/functions/utils + rm_if_exists $file +} +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 + rtinstallerror="true" + fi + rm_if_exists $file +} function build_xmlrpc-c() { - cd "/tmp" - . /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 + 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 @@ -145,49 +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() { - 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 $lpath ./configure --prefix=/usr >> $log 2>&1 || { echo_error "Something went wrong while configuring libtorrent" exit 1 @@ -201,44 +213,17 @@ 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() { - 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 $rpath 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 @@ -252,10 +237,11 @@ 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 apt-mark hold rtorrent >> ${log} 2>&1 } @@ -269,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 }