#!/bin/bash # # gonX@overclocked.net # # 1) takes the specified .zip files (works with archives from What.cd) # 2) extracts them # 3) and then moves all .torrent files to the designated dir. # ##### vars, change these if you will: _DESTDIR='/mnt/net2/torrentin/' _TMPDIR='/tmp/torrents/' # _FILE is the var in the for loop _PID=$$ ##### end vars ##### if [ -z "$1" ]; then echo ' -- you must specify an argument!' else # do the files exist? for _TEST in "$@"; do if [ ! -e $_TEST ]; then echo " -- $_TEST does not exist! aborting... "; kill -9 $_PID fi if [ ! ${_TEST: -4} == ".zip" ]; then echo " -- $_TEST is not a .zip file! aborting... "; kill -9 $_PID fi done echo " -- specified files: $@ " for _FILE in "$@" do echo " Current file: $_FILE " echo ' -- making temporary copy of files ' mv "${_FILE}" "${_FILE}.tmp" echo ' -- making tempdir, deleting if it exists ' rm -rf "$_TMPDIR" mkdir -p "$_TMPDIR" echo ' -- copying temporary file to tempdir ' cp "${_FILE}.tmp" "$_TMPDIR" echo ' -- changing dir ' cd "$_TMPDIR" echo ' -- unzipping ' unzip -q "/tmp/torrents/${_FILE}.tmp" rm "/tmp/torrents/${_FILE}.tmp" echo ' -- finding .torrents and moving them ' find -name "*.torrent" -exec mv "{}" $_DESTDIR \; echo ' -- marking temporary copy as done ' cd $OLDPWD mv "${_FILE}.tmp" "${_FILE}.done" done fi