Skip to content

Commit

Permalink
rTorrent: Refactor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stickz committed May 30, 2023
1 parent e5b2630 commit 56a712f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
6 changes: 3 additions & 3 deletions scripts/remove/rtorrent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions scripts/upgrade/rtorrent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions sources/build/prepare_lt_rakshasa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {
Expand All @@ -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)
Expand All @@ -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
4 changes: 2 additions & 2 deletions sources/build/prepare_rtorrent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion sources/build/prepare_xmlrpc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 39 additions & 31 deletions sources/functions/rtorrent
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}

0 comments on commit 56a712f

Please sign in to comment.