summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorPellegrino Prevete2022-06-12 18:55:00 +0000
committerPellegrino Prevete2022-06-12 18:55:00 +0000
commitc251a0fa10f982f321a89e0b943b9e46f06556dc (patch)
tree175918afca9f61ff514164072647fe7c2cb9c7b8
downloadaur-c251a0fa10f982f321a89e0b943b9e46f06556dc.tar.gz
move to transmission-makepkg
-rw-r--r--.SRCINFO17
-rw-r--r--PKGBUILD26
-rw-r--r--makepkg.conf148
-rw-r--r--transmission-dlagent105
-rw-r--r--transmission-quit30
5 files changed, 326 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..a983f38d0936
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,17 @@
+pkgbase = transmission-dlagent
+ pkgdesc = makepkg download agent for magnet URIs
+ pkgver = 1.0
+ pkgrel = 1
+ url = https://aur.archlinux.org/packages/transmission-dlagent
+ arch = any
+ license = AGPL3
+ depends = python
+ depends = transmission-cli
+ source = transmission-dlagent
+ source = transmission-quit
+ source = makepkg.conf
+ sha256sums = f2ca5106d9eee48ae9702a27ebe90b0bd4c7fdf2cffa6f953773105acac614cc
+ sha256sums = b07e32b4c1424d8e62adf5c05acd02e82be0a6549c49879aebeaa813b4840411
+ sha256sums = 849a4b3b5f574105f4b5e4afac7c1b16cebd805c8a3ba22910a30a432cc679c6
+
+pkgname = transmission-dlagent
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..71099f8d2c0c
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,26 @@
+# Maintainer: Pellegrino Prevete <pellegrinoprevete@gmail.com>
+
+pkgname=transmission-dlagent
+pkgver=1.0
+pkgrel=1
+pkgdesc="makepkg download agent for magnet URIs"
+arch=('any')
+url="https://aur.archlinux.org/packages/transmission-dlagent"
+depends=('python' 'transmission-cli')
+license=("AGPL3")
+source=("transmission-dlagent"
+ "transmission-quit"
+ "makepkg.conf")
+sha256sums=("f2ca5106d9eee48ae9702a27ebe90b0bd4c7fdf2cffa6f953773105acac614cc"
+ "b07e32b4c1424d8e62adf5c05acd02e82be0a6549c49879aebeaa813b4840411"
+ "849a4b3b5f574105f4b5e4afac7c1b16cebd805c8a3ba22910a30a432cc679c6")
+
+package() {
+ local _dest="${pkgdir}/usr/share/${pkgname}"
+ local _bin="${pkgdir}/usr/bin"
+ mkdir -p "${_dest}"
+ mkdir -p "${_bin}"
+ install -Dm755 "${pkgname}" "${_bin}"
+ install -Dm755 "transmission-quit" "${_bin}"
+ install -Dm644 "makepkg.conf" "${_dest}"
+}
diff --git a/makepkg.conf b/makepkg.conf
new file mode 100644
index 000000000000..9c0da97954b9
--- /dev/null
+++ b/makepkg.conf
@@ -0,0 +1,148 @@
+#!/hint/bash
+#
+# /etc/makepkg.conf
+#
+
+#########################################################################
+# SOURCE ACQUISITION
+#########################################################################
+#
+#-- The download utilities that makepkg should use to acquire sources
+# Format: 'protocol::agent'
+DLAGENTS=('file::/usr/bin/curl -gqC - -o %o %u'
+ 'ftp::/usr/bin/curl -gqfC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
+ 'http::/usr/bin/curl -gqb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'https::/usr/bin/curl -gqb "" -fLC - --retry 3 --retry-delay 3 -o %o %u'
+ 'magnet::/usr/bin/transmission-dlagent %u %o'
+ 'rsync::/usr/bin/rsync --no-motd -z %u %o'
+ 'scp::/usr/bin/scp -C %u %o')
+
+# Other common tools:
+# /usr/bin/snarf
+# /usr/bin/lftpget -c
+# /usr/bin/wget
+
+#-- The package required by makepkg to download VCS sources
+# Format: 'protocol::package'
+VCSCLIENTS=('bzr::bzr'
+ 'git::git'
+ 'hg::mercurial'
+ 'svn::subversion')
+
+#########################################################################
+# ARCHITECTURE, COMPILE FLAGS
+#########################################################################
+CARCH="x86_64"
+CHOST="x86_64-pc-linux-gnu"
+
+#-- Compiler and Linker Flags
+CPPFLAGS="-D_FORTIFY_SOURCE=2"
+# Intel 930
+CFLAGS="-march=nehalem -mtune=nehalem -O3 -pipe -fno-plt"
+CXXFLAGS="-march=corei7 -mtune=corei7 -O3 -pipe -fno-plt"
+LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
+#-- Make Flags: change this for DistCC/SMP systems
+MAKEFLAGS="-j8"
+#-- Debugging flags
+# Bug on
+# -fvar-tracking-assignments"
+DEBUG_CFLAGS="-g"
+DEBUG_CXXFLAGS="-g"
+
+#########################################################################
+# BUILD ENVIRONMENT
+#########################################################################
+#
+# Defaults: BUILDENV=(!distcc !color !ccache check !sign)
+# A negated environment option will do the opposite of the comments below.
+#
+#-- distcc: Use the Distributed C/C++/ObjC compiler
+#-- color: Colorize output messages
+#-- ccache: Use ccache to cache compilation
+#-- check: Run the check() function if present in the PKGBUILD
+#-- sign: Generate PGP signature file
+#
+BUILDENV=(!distcc color !ccache check !sign)
+#
+#-- If using DistCC, your MAKEFLAGS will also need modification. In addition,
+#-- specify a space-delimited list of hosts running in the DistCC cluster.
+#DISTCC_HOSTS=""
+#
+#-- Specify a directory for package building.
+BUILDDIR=/tmp/makepkg
+
+#########################################################################
+# GLOBAL PACKAGE OPTIONS
+# These are default values for the options=() settings
+#########################################################################
+#
+# Default: OPTIONS=(!strip docs libtool staticlibs emptydirs !zipman !purge !debug)
+# A negated option will do the opposite of the comments below.
+#
+#-- strip: Strip symbols from binaries/libraries
+#-- docs: Save doc directories specified by DOC_DIRS
+#-- libtool: Leave libtool (.la) files in packages
+#-- staticlibs: Leave static library (.a) files in packages
+#-- emptydirs: Leave empty directories in packages
+#-- zipman: Compress manual (man and info) pages in MAN_DIRS with gzip
+#-- purge: Remove files specified by PURGE_TARGETS
+#-- debug: Add debugging flags as specified in DEBUG_* variables
+#
+OPTIONS=(strip !docs !libtool !staticlibs emptydirs zipman purge !debug)
+
+#-- File integrity checks to use. Valid: md5, sha1, sha256, sha384, sha512
+INTEGRITY_CHECK=(md5)
+#-- Options to be used when stripping binaries. See `man strip' for details.
+STRIP_BINARIES="--strip-all"
+#-- Options to be used when stripping shared libraries. See `man strip' for details.
+STRIP_SHARED="--strip-unneeded"
+#-- Options to be used when stripping static libraries. See `man strip' for details.
+STRIP_STATIC="--strip-debug"
+#-- Manual (man and info) directories to compress (if zipman is specified)
+MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info})
+#-- Doc directories to remove (if !docs is specified)
+DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc})
+#-- Files to be removed from all packages (if purge is specified)
+PURGE_TARGETS=(usr/{,share}/info/dir .packlist *.pod)
+#-- Directory to store source code in for debug packages
+DBGSRCDIR="/usr/src/debug"
+
+#########################################################################
+# PACKAGE OUTPUT
+#########################################################################
+#
+# Default: put built package and cached source in build directory
+#
+#-- Destination: specify a fixed directory where all packages will be placed
+#PKGDEST=/home/packages
+#-- Source cache: specify a fixed directory where source files will be cached
+#SRCDEST=/home/sources
+#-- Source packages: specify a fixed directory where all src packages will be placed
+#SRCPKGDEST=/home/srcpackages
+#-- Log files: specify a fixed directory where all log files will be placed
+#LOGDEST=/home/makepkglogs
+#-- Packager: name/email of the person or organization building packages
+#PACKAGER=""
+#-- Specify a key to use for package signing
+#GPGKEY=""
+
+#########################################################################
+# COMPRESSION DEFAULTS
+#########################################################################
+#
+COMPRESSGZ=(gzip -c -f -n)
+COMPRESSBZ2=(bzip2 -c -f)
+COMPRESSXZ=(xz -c -z -)
+COMPRESSZST=(zstd -c -z -q -)
+COMPRESSLRZ=(lrzip -q)
+COMPRESSLZO=(lzop -q)
+COMPRESSZ=(compress -c -f)
+COMPRESSLZ4=(lz4 -q)
+COMPRESSLZ=(lzip -c -f)
+
+#########################################################################
+# EXTENSION DEFAULTS
+#########################################################################
+#
+PKGEXT='.pkg.tar.xz'
+SRCEXT='.src.tar.gz'
diff --git a/transmission-dlagent b/transmission-dlagent
new file mode 100644
index 000000000000..b6443f72b1c4
--- /dev/null
+++ b/transmission-dlagent
@@ -0,0 +1,105 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# transmission-dlagent
+#
+# ----------------------------------------------------------------------
+# Copyright © 2022 Pellegrino Prevete
+#
+# All rights reserved
+# ----------------------------------------------------------------------
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+
+from argparse import ArgumentParser
+from os import getcwd
+from os.path import basename
+from os.path import join as path_join
+from shutil import move as mv
+from shutil import Error as MoveError
+from subprocess import CalledProcessError, Popen, check_output, run
+
+def makepkg_to_magnet(link):
+ link = link.replace("://", ":?")
+ path_marker = "#path="
+ path = ""
+ if path_marker in link:
+ link, path = link.split(path_marker)
+ return link, path
+
+def magnet_makepkg(link, output_path, download_dir=getcwd()):
+ output_file = output_path.replace(".part", "")
+ magnet_link, torrent_path = makepkg_to_magnet(link)
+ torrent_output_path = path_join(download_dir, torrent_path)
+ output_path = path_join(download_dir, output_file)
+
+ btt_cmd = ["/usr/bin/transmission-cli",
+ f"{magnet_link}",
+ f"--download-dir={download_dir}",
+ "--portmap",
+ f"--finish /usr/bin/transmission-quit",
+ "|| echo 0"]
+
+ try:
+ btt_out = check_output(btt_cmd)
+
+ except CalledProcessError as err:
+ if f"Failed opening torrent file `{magnet_link}" in str(err.stderr):
+ print(f"Error in the magnet link '{magnet_link}'")
+ else:
+ if err.stderr:
+ error = err.stderr.decode("utf-8")
+ error = error.split("\n")
+ for line in error:
+ print(line)
+
+ try:
+ mv(torrent_output_path, output_path)
+ except MoveError as e:
+ print(e)
+ return e
+
+def main():
+ parser = ArgumentParser(description="Parse magnet link in makepkg format for Transmission")
+
+ magnet_link = {'args': ['magnet_link'],
+ 'kwargs': {'nargs': '+',
+ 'action': 'store',
+ 'help': "magnet link in makepkg format"}}
+
+ output_file = {'args': ['output_file'],
+ 'kwargs': {'nargs': 1,
+ 'action': 'store',
+ 'default': [""],
+ 'help': "output file"}}
+
+ download_dir = {'args': ['--download-dir'],
+ 'kwargs': {'nargs': 1,
+ 'action': 'store',
+ 'default': [getcwd()],
+ 'help': "download directory"}}
+
+ parser.add_argument(*magnet_link['args'], **magnet_link['kwargs'])
+ parser.add_argument(*output_file['args'], **output_file['kwargs'])
+ parser.add_argument(*download_dir['args'], **download_dir['kwargs'])
+
+ args = parser.parse_args()
+
+ return magnet_makepkg(args.magnet_link[0],
+ args.output_file[0],
+ download_dir=args.download_dir[0])
+
+if __name__ == "__main__":
+ main()
diff --git a/transmission-quit b/transmission-quit
new file mode 100644
index 000000000000..92c8c5005146
--- /dev/null
+++ b/transmission-quit
@@ -0,0 +1,30 @@
+#!/bin/sh
+# -*- coding: utf-8 -*-
+
+# transmission-quit
+#
+# ----------------------------------------------------------------------
+# Copyright © 2022 Pellegrino Prevete
+#
+# All rights reserved
+# ----------------------------------------------------------------------
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+#
+
+_transmission_quit() {
+ /usr/bin/killall -s TERM transmission-cli
+}
+
+_transmission_quit