From de9ae6eaa9dc7f9eb2affd04a2bda7efec73b56e Mon Sep 17 00:00:00 2001 From: "push-app-to-main[bot]" <203845782+push-app-to-main[bot]@users.noreply.github.com> Date: Thu, 15 May 2025 15:22:16 +0200 Subject: [PATCH] bitmagnet (#4493) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 'Add new script' * -fsSL * -fsSL * add alpine bitmagnet * add alpine bitmagnet * Update alpine-bitmagnet.sh * Update alpine-bitmagnet-install.sh * Update alpine-bitmagnet.sh * Update bitmagnet.sh * Update bitmagnet.json --------- Co-authored-by: push-app-to-main[bot] <203845782+push-app-to-main[bot]@users.noreply.github.com> Co-authored-by: CanbiZ <47820557+MickLesk@users.noreply.github.com> Co-authored-by: Slaviša Arežina <58952836+tremor021@users.noreply.github.com> --- ct/alpine-bitmagnet.sh | 89 ++++++++++++++++++++++++++ ct/bitmagnet.sh | 98 +++++++++++++++++++++++++++++ ct/headers/bitmagnet | 6 ++ frontend/public/json/bitmagnet.json | 51 +++++++++++++++ install/alpine-bitmagnet-install.sh | 85 +++++++++++++++++++++++++ install/bitmagnet-install.sh | 78 +++++++++++++++++++++++ 6 files changed, 407 insertions(+) create mode 100644 ct/alpine-bitmagnet.sh create mode 100644 ct/bitmagnet.sh create mode 100644 ct/headers/bitmagnet create mode 100644 frontend/public/json/bitmagnet.json create mode 100644 install/alpine-bitmagnet-install.sh create mode 100644 install/bitmagnet-install.sh diff --git a/ct/alpine-bitmagnet.sh b/ct/alpine-bitmagnet.sh new file mode 100644 index 000000000..0b69962d6 --- /dev/null +++ b/ct/alpine-bitmagnet.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/bitmagnet-io/bitmagnet + +APP="Alpine-bitmagnet" +var_tags="${var_tags:-alpine;torrent}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-1024}" +var_disk="${var_disk:-3}" +var_os="${var_os:-alpine}" +var_version="${var_version:-3.21}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + + if [[ ! -d /opt/bitmagnet ]]; then + msg_error "No ${APP} Installation Found!" + exit 1 + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [ "${RELEASE}" != "$(cat /opt/bitmagnet_version.txt)" ] || [ ! -f /opt/bitmagnet_version.txt ]; then + msg_info "Backing up database" + rm -f /tmp/backup.sql + $STD sudo -u postgres pg_dump \ + --column-inserts \ + --data-only \ + --on-conflict-do-nothing \ + --rows-per-insert=1000 \ + --table=metadata_sources \ + --table=content \ + --table=content_attributes \ + --table=content_collections \ + --table=content_collections_content \ + --table=torrent_sources \ + --table=torrents \ + --table=torrent_files \ + --table=torrent_hints \ + --table=torrent_contents \ + --table=torrent_tags \ + --table=torrents_torrent_sources \ + --table=key_values \ + bitmagnet \ + >/tmp/backup.sql + mv /tmp/backup.sql /opt/ + msg_ok "Database backed up" + + msg_info "Updating ${APP} from $(cat /opt/bitmagnet_version.txt) to ${RELEASE}" + $STD apk -U upgrade + $STD service bitmagnet stop + [ -f /opt/bitmagnet/.env ] && cp /opt/bitmagnet/.env /opt/ + [ -f /opt/bitmagnet/config.yml ] && cp /opt/bitmagnet/config.yml /opt/ + rm -rf /opt/bitmagnet/* + temp_file=$(mktemp) + curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" + tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet + cd /opt/bitmagnet + VREL=v$RELEASE + $STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL" + chmod +x bitmagnet + [ -f "/opt/.env" ] && cp "/opt/.env" /opt/bitmagnet/ + [ -f "/opt/config.yml" ] && cp "/opt/config.yml" /opt/bitmagnet/ + rm -f "$temp_file" + echo "${RELEASE}" >/opt/bitmagnet_version.txt + $STD service bitmagnet start + msg_ok "Updated Successfully" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + fi + + exit 0 +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following IP:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3333${CL}" diff --git a/ct/bitmagnet.sh b/ct/bitmagnet.sh new file mode 100644 index 000000000..f0012ebb1 --- /dev/null +++ b/ct/bitmagnet.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/bitmagnet/bitmagnet + +APP="Bitmagnet" +var_tags="${var_tags:-os}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-1024}" +var_disk="${var_disk:-4}" +var_os="${var_os:-debian}" +var_version="${var_version:-12}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + if [[ ! -d /opt/bitmagnet ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + msg_info "Stopping Service" + systemctl stop bitmagnet-web + msg_ok "Stopped Service" + + msg_info "Backing up database" + rm -f /tmp/backup.sql + $STD sudo -u postgres pg_dump \ + --column-inserts \ + --data-only \ + --on-conflict-do-nothing \ + --rows-per-insert=1000 \ + --table=metadata_sources \ + --table=content \ + --table=content_attributes \ + --table=content_collections \ + --table=content_collections_content \ + --table=torrent_sources \ + --table=torrents \ + --table=torrent_files \ + --table=torrent_hints \ + --table=torrent_contents \ + --table=torrent_tags \ + --table=torrents_torrent_sources \ + --table=key_values \ + bitmagnet \ + >/tmp/backup.sql + mv /tmp/backup.sql /opt/ + msg_ok "Database backed up" + + msg_info "Updating ${APP} to v${RELEASE}" + [ -f /opt/bitmagnet/.env ] && cp /opt/bitmagnet/.env /opt/ + [ -f /opt/bitmagnet/config.yml ] && cp /opt/bitmagnet/config.yml /opt/ + rm -rf /opt/bitmagnet/* + temp_file=$(mktemp) + curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" + tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet + cd /opt/bitmagnet + VREL=v$RELEASE + $STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL" + chmod +x bitmagnet + [ -f "/opt/.env" ] && cp "/opt/.env" /opt/bitmagnet/ + [ -f "/opt/config.yml" ] && cp "/opt/config.yml" /opt/bitmagnet/ + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated $APP to v${RELEASE}" + + msg_info "Starting Service" + systemctl start bitmagnet-web + msg_ok "Started Service" + + msg_info "Cleaning up" + rm -f "$temp_file" + msg_ok "Cleaned" + msg_ok "Updated Successfully" + else + msg_ok "No update required. ${APP} is already at v${RELEASE}" + fi + exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3333${CL}" diff --git a/ct/headers/bitmagnet b/ct/headers/bitmagnet new file mode 100644 index 000000000..b508b34a0 --- /dev/null +++ b/ct/headers/bitmagnet @@ -0,0 +1,6 @@ + ____ _ __ __ + / __ )(_) /_____ ___ ____ _____ _____ ___ / /_ + / __ / / __/ __ `__ \/ __ `/ __ `/ __ \/ _ \/ __/ + / /_/ / / /_/ / / / / / /_/ / /_/ / / / / __/ /_ +/_____/_/\__/_/ /_/ /_/\__,_/\__, /_/ /_/\___/\__/ + /____/ diff --git a/frontend/public/json/bitmagnet.json b/frontend/public/json/bitmagnet.json new file mode 100644 index 000000000..21f990925 --- /dev/null +++ b/frontend/public/json/bitmagnet.json @@ -0,0 +1,51 @@ +{ + "name": "Bitmagnet", + "slug": "bitmagnet", + "categories": [ + 11 + ], + "date_created": "2025-05-13", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 3333, + "documentation": "https://bitmagnet.io/setup.html", + "website": "https://bitmagnet.io/", + "logo": "https://raw.githubusercontent.com/selfhst/icons/refs/heads/main/webp/bitmagnet.webp", + "config_path": "`/opt/bitmagnet/config.yml` or `/opt/bitmagnet/.env`", + "description": "A self-hosted BitTorrent indexer, DHT crawler, content classifier and torrent search engine with web UI, GraphQL API and Servarr stack integration.", + "install_methods": [ + { + "type": "default", + "script": "ct/bitmagnet.sh", + "resources": { + "cpu": 2, + "ram": 1024, + "hdd": 4, + "os": "debian", + "version": "12" + } + }, + { + "type": "alpine", + "script": "ct/alpine-bitmagnet.sh", + "resources": { + "cpu": 2, + "ram": 1024, + "hdd": 3, + "os": "alpine", + "version": "3.21" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "During installation you will be asked to enter your TMDB API key, if you wanna use it. Make sure you have it ready.", + "type": "info" + } + ] +} diff --git a/install/alpine-bitmagnet-install.sh b/install/alpine-bitmagnet-install.sh new file mode 100644 index 000000000..0a88b507d --- /dev/null +++ b/install/alpine-bitmagnet-install.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/bitmagnet-io/bitmagnet + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing dependencies" +$STD apk add --no-cache \ + gcc \ + musl-dev \ + git \ + iproute2-ss \ + sudo +$STD apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community go +msg_ok "Installed dependencies" + +msg_info "Installing PostgreSQL" +$STD apk add --no-cache \ + postgresql16 \ + postgresql16-contrib \ + postgresql16-openrc +$STD rc-update add postgresql +$STD rc-service postgresql start +msg_ok "Installed PostreSQL" + +RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + +msg_info "Installing bitmagnet v${RELEASE}" +mkdir -p /opt/bitmagnet +temp_file=$(mktemp) +curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" +tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet +cd /opt/bitmagnet +VREL=v$RELEASE +$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL" +chmod +x bitmagnet +$STD su - postgres -c "psql -c 'CREATE DATABASE bitmagnet;'" +echo "${RELEASE}" >/opt/bitmagnet_version.txt +msg_ok "Installed bitmagnet v${RELEASE}" + +read -rp "${TAB3}Enter your TMDB API key if you have one: " tmdbapikey + +msg_info "Enabling bitmagnet Service" +cat </etc/init.d/bitmagnet +#!/sbin/openrc-run +description="bitmagnet Service" +directory="/opt/bitmagnet" +command="/opt/bitmagnet/bitmagnet" +command_args="worker run --all" +command_background="true" +command_user="root" +pidfile="/var/run/bitmagnet.pid" + +depend() { + use net +} + +start_pre() { + export TMDB_API_KEY="$tmdbapikey" +} +EOF +chmod +x /etc/init.d/bitmagnet +$STD rc-update add bitmagnet default +msg_ok "Enabled bitmagnet Service" + +msg_info "Starting bitmagnet" +$STD service bitmagnet start +msg_ok "Started bitmagnet" + +motd_ssh +customize + +msg_info "Cleaning up" +rm -f "$temp_file" +$STD apk cache clean +msg_ok "Cleaned" diff --git a/install/bitmagnet-install.sh b/install/bitmagnet-install.sh new file mode 100644 index 000000000..7ccdb8c67 --- /dev/null +++ b/install/bitmagnet-install.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/bitmagnet-io/bitmagnet + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get install -y \ + iproute2 \ + gcc \ + musl-dev +msg_ok "Installed Dependencies" + +PG_VERSION="16" install_postgresql +install_go +RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + +msg_info "Installing bitmagnet v${RELEASE}" +mkdir -p /opt/bitmagnet +temp_file=$(mktemp) +curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file" +tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet +cd /opt/bitmagnet +VREL=v$RELEASE +$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL" +chmod +x bitmagnet +POSTGRES_PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13) +$STD sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD';" +$STD sudo -u postgres psql -c "CREATE DATABASE bitmagnet;" +{ + echo "PostgreSQL Credentials" + echo "" + echo "postgres user password: $POSTGRES_PASSWORD" +} >>~/postgres.creds +echo "${RELEASE}" >/opt/bitmagnet_version.txt +msg_ok "Installed bitmagnet v${RELEASE}" + +read -r -p "${TAB3}Enter your TMDB API key if you have one: " tmdbapikey + +msg_info "Creating Service" +cat </etc/systemd/system/bitmagnet-web.service +[Unit] +Description=bitmagnet Web GUI +After=network-online.target + +[Service] +Type=simple +User=root +WorkingDirectory=/opt/bitmagnet +ExecStart=/opt/bitmagnet/bitmagnet worker run --all +Environment=POSTGRES_HOST=localhost +Environment=POSTGRES_PASSWORD=$POSTGRES_PASSWORD +Environment=TMDB_API_KEY=$tmdbapikey +Restart=on-failure + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now bitmagnet-web +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +rm -f "$temp_file" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned"