#!/bin/sh
#
# linbo_mktorrent
# thomas@linuxmuster.net
# 20250423
#

usage(){
  RC="$1"
  echo
  echo "Creates torrent file for image."
  echo
  echo "Usage: linbo_mktorrent <imagefile> | [help]"
  echo
  exit "$RC"
}

# print help
[ -z "$1" -o "$1" = "help" ] && usage 0

# get environment
source /usr/share/linbo/shell_functions
echo "### $timestamp $(basename "$0") $@ ###"

isinteger "$PIECELEN" && plopt="-l $PIECELEN"

echo "### linbo_mktorrent $1"

linbo_mountcache &> /dev/null || exit 1

curdir="$(pwd)"
cd /cache

[ -s "$1" ] || usage 1

RC="0"
echo "Creating $1.torrent ..."
rm -f "$1".torrent
ctorrent -t -u http://"$LINBOSERVER":6969/announce $plopt -s "$1".torrent "$1" || RC="1"

cd "$curdir"

exit "$RC"
