feat: initial open-source project structure
Agent Skill for searching and downloading torrents via TorrentClaw. Includes SKILL.md with OpenClaw metadata, bash scripts for torrent client detection, CONTRIBUTING.md, CHANGELOG.md, CI/CD with GitHub Actions (shellcheck + conventional commits), lefthook git hooks, Makefile, and .editorconfig.
This commit is contained in:
parent
b0c4fc2e21
commit
98c550feb0
14 changed files with 1096 additions and 0 deletions
105
scripts/add-torrent.sh
Executable file
105
scripts/add-torrent.sh
Executable file
|
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env bash
|
||||
# Adds a magnet link to a detected torrent client.
|
||||
# Usage: ./add-torrent.sh "<magnet_url>" [--client transmission|aria2] [--download-dir /path]
|
||||
#
|
||||
# Exit codes:
|
||||
# 0 - Success
|
||||
# 1 - Invalid parameters
|
||||
# 2 - No torrent client found
|
||||
# 3 - Client error (failed to add)
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- Parse Arguments ---
|
||||
magnet_url=""
|
||||
client=""
|
||||
download_dir=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--client)
|
||||
client="$2"
|
||||
shift 2
|
||||
;;
|
||||
--download-dir)
|
||||
download_dir="$2"
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
echo "Error: Unknown option $1" >&2
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
if [ -z "$magnet_url" ]; then
|
||||
magnet_url="$1"
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$magnet_url" ]; then
|
||||
echo "Error: Magnet URL is required" >&2
|
||||
echo "Usage: $0 \"<magnet_url>\" [--client transmission|aria2] [--download-dir /path]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Auto-detect client if not specified ---
|
||||
if [ -z "$client" ]; then
|
||||
if command -v transmission-remote >/dev/null 2>&1; then
|
||||
client="transmission"
|
||||
elif command -v aria2c >/dev/null 2>&1; then
|
||||
client="aria2"
|
||||
else
|
||||
echo "Error: No torrent client detected. Install transmission-cli or aria2." >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- Add torrent ---
|
||||
case "$client" in
|
||||
transmission)
|
||||
args=(-a "$magnet_url")
|
||||
if [ -n "$download_dir" ]; then
|
||||
args+=(-w "$download_dir")
|
||||
fi
|
||||
echo "Adding to Transmission..."
|
||||
if transmission-remote "${args[@]}"; then
|
||||
echo "Torrent added to Transmission successfully."
|
||||
else
|
||||
echo "Error: Failed to add torrent to Transmission. Is the daemon running?" >&2
|
||||
echo "Start it with: transmission-daemon" >&2
|
||||
exit 3
|
||||
fi
|
||||
;;
|
||||
aria2)
|
||||
# Check if aria2 RPC is running
|
||||
if curl -sf http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"test","method":"aria2.getVersion"}' >/dev/null 2>&1; then
|
||||
echo "Adding to aria2 via RPC..."
|
||||
dir_param=""
|
||||
if [ -n "$download_dir" ]; then
|
||||
dir_param=",{\"dir\":\"$download_dir\"}"
|
||||
fi
|
||||
result=$(curl -sf http://localhost:6800/jsonrpc -d "{\"jsonrpc\":\"2.0\",\"id\":\"add\",\"method\":\"aria2.addUri\",\"params\":[[\"$magnet_url\"]$dir_param]}")
|
||||
if echo "$result" | grep -q '"result"'; then
|
||||
echo "Torrent added to aria2 successfully."
|
||||
else
|
||||
echo "Error: aria2 RPC rejected the request." >&2
|
||||
exit 3
|
||||
fi
|
||||
else
|
||||
# Direct download mode
|
||||
echo "Adding to aria2 (direct mode)..."
|
||||
args=("$magnet_url")
|
||||
if [ -n "$download_dir" ]; then
|
||||
args+=(--dir="$download_dir")
|
||||
fi
|
||||
aria2c "${args[@]}" &
|
||||
echo "aria2 download started in background (PID: $!)."
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown client '$client'. Supported: transmission, aria2" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
78
scripts/detect-client.sh
Executable file
78
scripts/detect-client.sh
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bash
|
||||
# Detects installed torrent clients and outputs JSON.
|
||||
# Usage: ./detect-client.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# --- OS Detection ---
|
||||
os_name=$(uname -s)
|
||||
distro="unknown"
|
||||
|
||||
case "$os_name" in
|
||||
Linux)
|
||||
if [ -f /etc/os-release ]; then
|
||||
# shellcheck source=/dev/null
|
||||
distro=$(. /etc/os-release && echo "${ID:-unknown}")
|
||||
fi
|
||||
;;
|
||||
Darwin)
|
||||
distro="macos"
|
||||
;;
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
os_name="Windows"
|
||||
distro="windows"
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Client Detection ---
|
||||
|
||||
# Transmission
|
||||
transmission_path=$(command -v transmission-remote 2>/dev/null || true)
|
||||
transmission_installed="false"
|
||||
transmission_daemon="false"
|
||||
if [ -n "$transmission_path" ]; then
|
||||
transmission_installed="true"
|
||||
if transmission-remote -l >/dev/null 2>&1; then
|
||||
transmission_daemon="true"
|
||||
fi
|
||||
fi
|
||||
|
||||
# aria2
|
||||
aria2_path=$(command -v aria2c 2>/dev/null || true)
|
||||
aria2_installed="false"
|
||||
aria2_daemon="false"
|
||||
if [ -n "$aria2_path" ]; then
|
||||
aria2_installed="true"
|
||||
if curl -sf http://localhost:6800/jsonrpc -d '{"jsonrpc":"2.0","id":"test","method":"aria2.getVersion"}' >/dev/null 2>&1; then
|
||||
aria2_daemon="true"
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- Preferred Client ---
|
||||
preferred="none"
|
||||
if [ "$transmission_installed" = "true" ]; then
|
||||
preferred="transmission"
|
||||
elif [ "$aria2_installed" = "true" ]; then
|
||||
preferred="aria2"
|
||||
fi
|
||||
|
||||
# --- JSON Output ---
|
||||
cat <<EOF
|
||||
{
|
||||
"os": "$os_name",
|
||||
"distro": "$distro",
|
||||
"clients": {
|
||||
"transmission": {
|
||||
"installed": $transmission_installed,
|
||||
"path": $([ -n "$transmission_path" ] && echo "\"$transmission_path\"" || echo "null"),
|
||||
"daemonRunning": $transmission_daemon
|
||||
},
|
||||
"aria2": {
|
||||
"installed": $aria2_installed,
|
||||
"path": $([ -n "$aria2_path" ] && echo "\"$aria2_path\"" || echo "null"),
|
||||
"daemonRunning": $aria2_daemon
|
||||
}
|
||||
},
|
||||
"preferred": "$preferred"
|
||||
}
|
||||
EOF
|
||||
122
scripts/install-guide.sh
Executable file
122
scripts/install-guide.sh
Executable file
|
|
@ -0,0 +1,122 @@
|
|||
#!/usr/bin/env bash
|
||||
# Shows OS-specific installation instructions for torrent clients.
|
||||
# Usage: ./install-guide.sh [transmission|aria2]
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
client="${1:-transmission}"
|
||||
|
||||
# --- OS Detection ---
|
||||
os_name=$(uname -s)
|
||||
distro="unknown"
|
||||
|
||||
case "$os_name" in
|
||||
Linux)
|
||||
if [ -f /etc/os-release ]; then
|
||||
# shellcheck source=/dev/null
|
||||
distro=$(. /etc/os-release && echo "${ID:-unknown}")
|
||||
fi
|
||||
;;
|
||||
Darwin)
|
||||
distro="macos"
|
||||
;;
|
||||
MINGW*|MSYS*|CYGWIN*)
|
||||
distro="windows"
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "=== Install $client ==="
|
||||
echo ""
|
||||
|
||||
case "$client" in
|
||||
transmission)
|
||||
case "$distro" in
|
||||
ubuntu|debian|pop|linuxmint|elementary)
|
||||
echo "Ubuntu/Debian:"
|
||||
echo " sudo apt update && sudo apt install -y transmission-cli transmission-daemon"
|
||||
echo ""
|
||||
echo "Start daemon:"
|
||||
echo " sudo systemctl start transmission-daemon"
|
||||
;;
|
||||
fedora|rhel|centos|rocky|alma)
|
||||
echo "Fedora/RHEL:"
|
||||
echo " sudo dnf install -y transmission-cli transmission-daemon"
|
||||
echo ""
|
||||
echo "Start daemon:"
|
||||
echo " sudo systemctl start transmission-daemon"
|
||||
;;
|
||||
arch|manjaro|endeavouros)
|
||||
echo "Arch Linux:"
|
||||
echo " sudo pacman -S transmission-cli"
|
||||
echo ""
|
||||
echo "Start daemon:"
|
||||
echo " sudo systemctl start transmission"
|
||||
;;
|
||||
macos)
|
||||
echo "macOS:"
|
||||
echo " brew install transmission-cli"
|
||||
echo ""
|
||||
echo "Start daemon:"
|
||||
echo " transmission-daemon"
|
||||
;;
|
||||
windows)
|
||||
echo "Windows:"
|
||||
echo " Option 1: Use WSL and install with apt (recommended)"
|
||||
echo " wsl sudo apt install -y transmission-cli transmission-daemon"
|
||||
echo ""
|
||||
echo " Option 2: Download Transmission for Windows"
|
||||
echo " https://transmissionbt.com/download/"
|
||||
;;
|
||||
*)
|
||||
echo "Install transmission-cli using your distribution's package manager."
|
||||
echo "Package name is usually: transmission-cli or transmission-daemon"
|
||||
;;
|
||||
esac
|
||||
echo ""
|
||||
echo "Verify installation:"
|
||||
echo " transmission-remote --version"
|
||||
;;
|
||||
aria2)
|
||||
case "$distro" in
|
||||
ubuntu|debian|pop|linuxmint|elementary)
|
||||
echo "Ubuntu/Debian:"
|
||||
echo " sudo apt update && sudo apt install -y aria2"
|
||||
;;
|
||||
fedora|rhel|centos|rocky|alma)
|
||||
echo "Fedora/RHEL:"
|
||||
echo " sudo dnf install -y aria2"
|
||||
;;
|
||||
arch|manjaro|endeavouros)
|
||||
echo "Arch Linux:"
|
||||
echo " sudo pacman -S aria2"
|
||||
;;
|
||||
macos)
|
||||
echo "macOS:"
|
||||
echo " brew install aria2"
|
||||
;;
|
||||
windows)
|
||||
echo "Windows:"
|
||||
echo " Option 1: Use WSL and install with apt (recommended)"
|
||||
echo " wsl sudo apt install -y aria2"
|
||||
echo ""
|
||||
echo " Option 2: Download aria2 for Windows"
|
||||
echo " https://github.com/aria2/aria2/releases"
|
||||
;;
|
||||
*)
|
||||
echo "Install aria2 using your distribution's package manager."
|
||||
echo "Package name is usually: aria2"
|
||||
;;
|
||||
esac
|
||||
echo ""
|
||||
echo "Verify installation:"
|
||||
echo " aria2c --version"
|
||||
echo ""
|
||||
echo "Optional - Start RPC daemon for remote control:"
|
||||
echo " aria2c --enable-rpc --rpc-listen-port=6800 --daemon"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown client: $client"
|
||||
echo "Supported clients: transmission, aria2"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Loading…
Add table
Add a link
Reference in a new issue