Added mirror torrents support

This commit is contained in:
Travis McCrea 2024-08-20 16:22:29 +07:00
parent 6d33478174
commit dcd71d0bba
6 changed files with 867 additions and 531 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
annastorrents.exe
annastorrents
torrents.db
torrents.db-shm
torrents.db-wal

View File

@ -31,23 +31,33 @@ You can just go to the releases and download the binary and skip the installatio
cd annas-archive-mirror
```
3. Build the application (see Building section below).
3. Build and Setup the Application:
```
sudo chmod +x install.sh
sudo install.sh
```
4. Run the application:
```
./annas-archive-mirror
sudo systemctl start annas-torrents.service
```
or
```
./annas-torrents
```
5. Access the web interface by opening a browser and navigating to `http://localhost:8080`
## Building
## Build Yourself
This application uses CGO and requires GCC to be installed on your system. Follow these steps to build the application:
1. Install Go (version 1.16 or later) from [golang.org](https://golang.org/)
2. Install GCC:
- On Ubuntu/Debian: `sudo apt-get install build-essentials`
- On Ubuntu/Debian: `sudo apt-get install build-essential`
- On macOS: Install Xcode Command Line Tools
- On Windows: Install MinGW-w64 (I didn't need to do this but other guides say you do)
@ -95,6 +105,7 @@ Example:
- `/stats/{btih}`: Detailed statistics for a specific torrent
- `/json`: Full torrent list in JSON format
- `/generate-torrent-list`: Endpoint for generating custom torrent lists
- `/assets`: Serves everything in the assets folder within --directory (so ./assets by default)
5. **Visualization**:
- It uses Chart.js to create visual representations of seeder statistics.

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

130
install.sh Normal file
View File

@ -0,0 +1,130 @@
#!/bin/bash
set -e
# Default values
DEFAULT_PORT=8080
DEFAULT_DIRECTORY="/var/annas-torrents"
# Function to install Go
install_go() {
echo "Installing Go..."
GO_VERSION="1.23.0" # Use the specific version you need
ARCH=$(uname -m)
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
GO_TARBALL="go${GO_VERSION}.linux-${ARCH}.tar.gz"
wget "https://go.dev/dl/${GO_TARBALL}"
sudo tar -C /usr/local -xzf "${GO_TARBALL}"
rm "${GO_TARBALL}"
export PATH=$PATH:/usr/local/go/bin
echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.bashrc
}
# Function to install GCC
install_gcc() {
echo "Installing GCC..."
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update
sudo apt-get install -y build-essential
elif [ -x "$(command -v yum)" ]; then
sudo yum groupinstall -y "Development Tools"
elif [ -x "$(command -v zypper)" ]; then
sudo zypper install -t pattern devel_basis
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -Sy --noconfirm base-devel
else
echo "Unsupported package manager. Please install GCC manually."
exit 1
fi
}
# Function to set up directory
setup_directory() {
echo "Setting up directory..."
sudo mkdir -p "$INSTALL_DIRECTORY"
sudo chown -R www-data:www-data "$INSTALL_DIRECTORY"
sudo chmod -R 755 "$INSTALL_DIRECTORY"
}
# Prompt for port
read -p "Enter the port you want to use (default is $DEFAULT_PORT): " PORT
PORT=${PORT:-$DEFAULT_PORT}
# Prompt for installation directory
read -p "Enter the installation directory (default is $DEFAULT_DIRECTORY): " INSTALL_DIRECTORY
INSTALL_DIRECTORY=${INSTALL_DIRECTORY:-$DEFAULT_DIRECTORY}
# Prompt for hosting torrents locally
read -p "Do you want to host torrent files locally? (y/n, default is n): " HOST_TORRENTS
HOST_TORRENTS=${HOST_TORRENTS:-n}
TORRENT_FLAG=""
if [[ "$HOST_TORRENTS" =~ ^[Yy]$ ]]; then
TORRENT_FLAG="--torrents true"
fi
# Check if Go is installed
if ! command -v go &> /dev/null; then
install_go
else
echo "Go is already installed."
fi
# Check if GCC is installed
if ! command -v gcc &> /dev/null; then
install_gcc
else
echo "GCC is already installed."
fi
# Install Go dependencies
echo "Installing Go dependencies..."
go get github.com/mattn/go-sqlite3
go get github.com/etix/goscrape
# Set up the directory with correct permissions
setup_directory
# Build the application
echo "Building the application..."
go build -o /usr/bin/annas-torrents
# If port 80 is selected, ensure the binary can bind to it
if [ "$PORT" -eq 80 ]; then
echo "You selected port 80. Configuring permissions..."
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/annas-torrents
fi
# Create systemd service file
echo "Creating systemd service..."
SERVICE_FILE="/etc/systemd/system/annas-torrents.service"
sudo bash -c "cat > $SERVICE_FILE" <<EOL
[Unit]
Description=Anna's Torrents Service
After=network.target
[Service]
ExecStart=/usr/bin/annas-torrents --port $PORT --directory $INSTALL_DIRECTORY $TORRENT_FLAG
User=www-data
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# Reload systemd, enable, and start the service
sudo systemctl daemon-reload
sudo systemctl enable annas-torrents.service
sudo systemctl start annas-torrents.service
echo "Installation and setup complete. Anna's Torrents is now running on port $PORT with files stored in $INSTALL_DIRECTORY."
if [[ "$HOST_TORRENTS" =~ ^[Yy]$ ]]; then
echo "Torrent files are being hosted locally."
fi

1237
main.go

File diff suppressed because one or more lines are too long

Binary file not shown.