The script works with one entry parameter : a path.
The script will recursively check this path for .rar
files, then check the content of the file and if a file isn't extracted yet, It will extract it.
*/5 * * * * /bin/unrar_torrent.sh "/data/tv-sonarr" |
FROM lsiobase/alpine | |
MAINTAINER onigoetz <onigoetz@onigoetz.ch> | |
RUN apk add --no-cache bash unrar | |
COPY crontab /var/spool/cron/crontabs/abc | |
COPY ./unrar.sh /bin/unrar_torrent.sh | |
RUN chmod +x /bin/unrar_torrent.sh | |
VOLUME /data | |
CMD ["crond", "-l", "2", "-f"] |
#!/usr/bin/env bash | |
DIR="$1" | |
function extractRar() { | |
_DIRNAME="$1" | |
_RAR="$2" | |
_FILES="$3" | |
while read -r FILE; do | |
if [ ! -f "$_DIRNAME/$FILE" ]; then | |
echo "Extracting" | |
unrar x $_RAR $_DIRNAME | |
fi | |
done <<< "$_FILES"; | |
} | |
echo "Starting UNRAR" | |
while IFS= read -r -d $'\0'; do | |
echo "=> $(basename $REPLY)" | |
DIRNAME=$(dirname $REPLY) | |
FILES=$(unrar lb $REPLY | grep -v '.txt' | grep -v '.nfo') | |
extractRar $DIRNAME $REPLY $FILES | |
done < <(find $DIR -name '*.rar' -print0) | |
echo "UNRAR Done" |