Skip to content

Instantly share code, notes, and snippets.

@pettazz
Last active November 15, 2022 21:52
Show Gist options
  • Select an option

  • Save pettazz/0818c4e8399c740a1a5e to your computer and use it in GitHub Desktop.

Select an option

Save pettazz/0818c4e8399c740a1a5e to your computer and use it in GitHub Desktop.
#!/bin/bash
UNRAR_LOG="/config/unrar.log"
UNRAR_DESTINATION="$TR_TORRENT_DIR"
echo "unrar for $TR_TORRENT_NAME, in $UNRAR_DESTINATION" >> $UNRAR_LOG
cd $UNRAR_DESTINATION;
if [ -n "$TR_TORRENT_NAME" ]; then
if [ -f $TR_TORRENT_NAME ]; then
unrar e "$TR_TORRENT_NAME" "$UNRAR_DESTINATION" >> $UNRAR_LOG;
elif [ -d $TR_TORRENT_NAME ]; then
echo "entering $TR_TORRENT_NAME" >> $UNRAR_LOG;
UNRAR_DESTINATION="$UNRAR_DESTINATION/$TR_TORRENT_NAME"
echo "new unrar destination $UNRAR_DESTINATION" >> $UNRAR_LOG
cd "$TR_TORRENT_NAME";
if [ -f *.rar ]; then
echo ".rar file found" >> $UNRAR_LOG;
files=(*.rar)
elif [ -f *.part01.rar ]; then
echo ".part01.rar file found" >> $UNRAR_LOG;
files=(*.part01.rar)
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!\ncouldn't match file pattern pls help\n!!!!!!!!!!!!!!!!!!!!!!!!!" >> $UNRAR_LOG;
exit 1
fi
for file in ${files[*]}; do
unrar e $file "$UNRAR_DESTINATION" >> $UNRAR_LOG;
done
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!\nthis should be impossible. help?\n!!!!!!!!!!!!!!!!!!!!!!!!!" >> $UNRAR_LOG;
exit 1
fi
else
echo "no name given" >> $UNRAR_LOG;
exit 1
fi
@pettazz
Copy link
Author

pettazz commented May 15, 2016

In bash, quoting a wildcard makes it lose its special powers and becomes a literal. So, if [ -f *.rar ]; then is not the same as if [ -f "*.rar" ]; then.

@pettazz
Copy link
Author

pettazz commented May 15, 2016

Okay now we support multiple files and actually exit 1 when it fails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment