Skip to content

Instantly share code, notes, and snippets.

@jfeilbach
Last active April 15, 2023 18:24
Show Gist options
  • Save jfeilbach/75244095d58e98bd7068a247a0f67de8 to your computer and use it in GitHub Desktop.
Save jfeilbach/75244095d58e98bd7068a247a0f67de8 to your computer and use it in GitHub Desktop.
docker pull, stop container, rm container, rotate log file, backup config, start new image as container, add dig, check public ip address
#!/bin/bash
host=<>
name=transmission-openvpn
log=transmission-openvpn.log
echo "Stopping ${name}"
/usr/bin/docker stop ${name}
echo "Removing ${name}"
/usr/bin/docker rm ${name}
# backup config, resume, and torrents
date=$(date +%Y_%m_%d)
work_dir=/dl_2/transmission-home
/usr/bin/zip -r \
${work_dir}/transmission-3.00_${date}.zip \
${work_dir}/*.json \
${work_dir}/dht.dat \
${work_dir}/blocklists/ \
${work_dir}/resume/ \
${work_dir}/torrents/
echo "Finished archiving torrent files."
echo "Starting rsync to host ${host}..."
rsync -avhP ${work_dir}/*.zip user@host:/opt/user/config/
echo "Restarting ${name}"
docker run --cap-add=NET_ADMIN -d \
--name=transmission-openvpn \
--restart=always \
-e PUID=1000 \
-e PGID=1000 \
-v /dl_2/:/data \
-v /etc/localtime:/etc/localtime:ro \
-e CREATE_TUN_DEVICE=true \
-e OPENVPN_PROVIDER=<> \
-e OPENVPN_CONFIG=<> \
-e OPENVPN_USERNAME=<> \
-e OPENVPN_PASSWORD=<> \
-e WEBPROXY_ENABLED=false \
-e LOCAL_NETWORK=192.168.0.0/16 \
--log-driver json-file \
--log-opt max-size=10m \
-p 9092:9091 \
haugene/transmission-openvpn
info=$(docker ps | grep transmission |awk '{ print $1 "\t" $2 }')
ver=$(docker exec -it transmission-openvpn bash -c "cat /etc/os-release")
tr_ver=$(docker exec -it transmission-openvpn bash -c "transmission-daemon --version")
echo ""
echo "Inspecting ${name}; saving to ${log}"
# # rotate the log file
#mv -v /dl_2/transmission-home/transmission.log /dl_2/transmission-home/transmission.log.$(date +%Y%m%d)
mv ${log} ${log}-$(date +%Y%m%d)
docker container inspect transmission-openvpn >> ${log}
echo ""
echo "Pausing (1/3)..."
sleep 5
echo ""
echo "Checking container info..."
echo "${info}"
echo ""
echo "Pausing again (2/3)..."
sleep 5
echo ""
echo "Getting container OS version info..."
echo "${ver}"
echo ""
echo "Getting container transmission version info..."
echo -e "${tr_ver}"
echo ""
echo "Pausing one last time (3/3)..."
sleep 6
echo ""
#echo "Installing dig (bind-tools) via APK... (sometimes this can take a while)"
echo "Checking for bind-tools..."
echo ""
#docker exec -it ${name} bash -c "apk add bind-tools"
docker exec -it ${name} bash -c "/usr/bin/dig -v"
#docker exec -it transmission-openvpn bash -c "/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com"
docker_ip=$(docker exec -it transmission-openvpn bash -c "/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com")
#ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
ip=$(curl -s http://ifconfig.me)
echo ""
echo "This host ${HOSTNAME} public IP address is: ${ip}"
echo "The docker container ${name} public IP address is: ${docker_ip}"
if [ "$ip" = "$docker_ip" ] ; then
echo -e "\n"
echo " >>> Warning. Public IP address in ${name} container is the same as our WAN public IP address. Warning. <<<"
echo -e "\nExiting. Please STOP the container and FIX.\n"
exit 1
else
echo ""
echo "We appear to be operating safely, with a proper VPN tunnel for torrents. Carry on."
echo ""
fi
port=$(docker port transmission-openvpn)
echo "${name} Transmission RPC/web TCP port information: ${port}"
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment