Last active
November 15, 2022 21:52
-
-
Save pettazz/0818c4e8399c740a1a5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Author
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
In bash, quoting a wildcard makes it lose its special powers and becomes a literal. So,
if [ -f *.rar ]; thenis not the same asif [ -f "*.rar" ]; then.