Skip to content

Instantly share code, notes, and snippets.

@onigoetz
Created November 5, 2016 21:35
Show Gist options
  • Save onigoetz/277df51931d2e6acdcee9dedd42fdf73 to your computer and use it in GitHub Desktop.
Save onigoetz/277df51931d2e6acdcee9dedd42fdf73 to your computer and use it in GitHub Desktop.
Unrar after download

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment