forked from vimpunk/cratetorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_transmission_seed.sh
executable file
·93 lines (80 loc) · 2.38 KB
/
start_transmission_seed.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
set -e
source common.sh
function print_help {
echo -e "
This script starts a Transmission seed container with the specified parameters,
if it's not already running.
USAGE: $1 --name NAME
OPTIONS:
-n|--name The name to give to the container.
-h|--help Print this help message.
"
}
for arg in "$@"; do
case "${arg}" in
-n|--name)
name=$2
;;
--h|--help)
print_help
exit 0
;;
esac
shift
done
if [ -z "${name}" ]; then
echo "Error: --name must be set"
print_help
exit 1
fi
# where the torrent file and metainfo are saved
assets_dir="$(pwd)/assets"
if [ -f "${assets_dir}" ]; then
echo "Error: file found at assets directory path ${assets_dir} "
exit 2
elif [ ! -d "${assets_dir}" ]; then
echo "Creating assets directory ${assets_dir}"
mkdir "${assets_dir}"
fi
# initialize the directories of the seed, if needed
#
# NOTE: the paths given are on the host, not inside the container
tr_seed_dir="${assets_dir}/${name}"
if [ ! -d "${tr_seed_dir}" ]; then
echo "Creating seed ${name} directory at ${tr_seed_dir}"
mkdir "${tr_seed_dir}"
fi
tr_config_dir="${tr_seed_dir}/config"
tr_downloads_dir="${tr_seed_dir}/downloads"
tr_watch_dir="${tr_seed_dir}/watch"
# create the subdirectories that we're binding into the container (must exist
# before bind mounting)
for subdir in {"${tr_config_dir}","${tr_downloads_dir}","${tr_watch_dir}"}; do
if [ ! -d "${subdir}" ]; then
echo "Creating seed subdirectory ${subdir}"
mkdir "${subdir}"
fi
done
# check if the seed is running: if not, start it
if ! docker inspect --format '{{.State.Running}}' "${name}" &> /dev/null
then
echo "Starting Transmission seed container ${name} listening on port 51413"
docker run \
--rm \
--name "${name}" \
--env PUID=$UID \
--env PGID=$UID \
--mount type=bind,src="${tr_config_dir}",dst=/config \
--mount type=bind,src="${tr_downloads_dir}",dst=/downloads \
--mount type=bind,src="${tr_watch_dir}",dst=/watch \
--detach \
linuxserver/transmission
seed_ip="$(get_container_ip "${name}")"
echo "Seed available on local Docker net at IP: ${seed_ip}"
# wait for seed to come online
sleep 5
echo "Transmission seed ${name} started!"
else
echo "Transmission seed ${name} already running!"
fi