#!/bin/bash #Company: PowerCraft Technology #Author: Copyright Jelle de Jong #Note: Please send me an email if you enhanced this script #Version: 0.0.2 #Date: 23-09-2006 / 06-04-2007 #System: Ubuntu/Debian GNU/Linux #Information: man unar, man par2 #Category Thunar scripts #Name: Process Download #Description: Process directory with *.par2 and *.rar file(s) #Command: xfce4-terminal --disable-server --hide-toolbars --execute /usr/share/pct-thunar-scripts/scripts/directory-unrar-par %F #Patterns: * #Directories: True # Did the script work for you? # Yes # Yes, but with some errors # Yes, but I had to change some things # Not at all # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=${0##*/} NAME=$"Process Download" DESCRIPTION=$"Process directory with *.par2 and *.rar file(s)" cecho() { case "$1" in "black") echo -ne "\E[30m" ;; "red") echo -ne "\E[31m" ;; "green") echo -ne "\E[32m" ;; "yellow") echo -ne "\E[33m" ;; "blue") echo -ne "\E[34m" ;; "magenta") echo -ne "\E[35m" ;; "cyan") echo -ne "\E[36m" ;; *) echo -ne "\E[30m" exit ;; esac echo "$2" "$3" tput sgr0 } cecho "green" $"program:" echo "$0" cecho "green" $"description:" echo "$DESCRIPTION" echo $"Process these directory(s):" for I in "$@" do cecho "blue" "$I" done #extractdirectory="/media/sda3/downloads/usenet/" #repairdirectory="/media/sda3/downloads/usenet/" extractdirectory="/media/disk/" repairdirectory="/media/disk/" echo $"Working Location(s):" cecho "blue" "$extractdirectory" cecho "blue" "$repairdirectory" echo -n $"are you sure you want to continue [Y/n]? " read input if [ "$input" = "n" ] then exit 0 fi if [ ! -e "$extractdirectory" ] then mkdir -p "$extractdirectory" fi if [ ! -e "$repairdirectory" ] then mkdir -p "$repairdirectory" fi for I in "$@" do echo $"starting with: " cecho "blue" "$I" cd "$I" for file in * do if [ ! -e "$file" ] then continue fi filelink="" filename="" type1=".part1.rar" type2=".part01.rar" type3=".part001.rar" type4=".r00" type5a=".rar" type5b=".part" rar=`echo "$file" | grep "$type1"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type1'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type2"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type2'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type3"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type3'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type5a"` part=`echo "$file" | grep "$type5b"` if [ "$rar" != "" -a "$part" = "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type5a'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` fi if [ "$filename" != "" ] then cecho "magenta" $"extracting $filelink" location="$PWD" #cecho "red" "$location" cd "$extractdirectory" if [ ! -d "$filename" ] then mkdir "$filename" fi cd "$filename" info=`time(nice -n 19 unrar x "$location/$filelink" 2>&1)` good=$(echo "$info" | grep "All OK") cd "$location" if [ "$good" = "" ] then cecho "red" "$filelink error" echo "$info " > "$filelink-error.txt" cecho "blue" $"moving" mv "$filename"* "$repairdirectory" else cecho "green" "$filelink processed" cecho "blue" $"removing" rm -rf "$filename"* fi fi done if [ -d "$repairdirectory" ] then cd "$repairdirectory" cecho "red" "------------" fi for file in * do if [ ! -f "$file" ] then continue fi filename="" type1=".par2" par2=`echo "$file" | grep "$type1"` if [ "$par2" = "" ] then continue fi #par2list+=";" #par2list+="$par2" #filename=`echo "$par2" | cut -f 1 -d '.'` filename=`echo "$par2" | sed 's/'$type1'//'` cecho "green" "$filename" if [ "$filename" = "" ] then continue fi cecho "magenta" "par2repair $par2" info=`time(nice -n 19 par2repair "$par2" 2>&1)` good=$(echo "$info" | grep "All files are correct") good=$(echo "$info" | grep "Repair complete") if [ "$good" = "" ] then cecho "red" "$filename is bad" echo "$info " > "$par2 error.txt" if [ ! -d "bad" ] then mkdir bad fi cecho "blue" "moving" mv "$filename"* bad else cecho "green" "$filename is good" if [ ! -d "repaired" ] then mkdir repaired fi cecho "blue" "moving" mv "$filename"* repaired fi done if [ -d "repaired" ] then cd "repaired" cecho "red" "------------" fi for file in * do if [ ! -e "$file" ] then continue fi filelink="" filename="" type1=".part1.rar" type2=".part01.rar" type3=".part001.rar" type4=".r00" type5a=".rar" type5b=".part" rar=`echo "$file" | grep "$type1"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type1'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type2"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type2'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type3"` if [ "$rar" != "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type3'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` cecho "green" "$filename" fi rar=`echo "$file" | grep "$type5a"` part=`echo "$file" | grep "$type5b"` if [ "$rar" != "" -a "$part" = "" ] then filelink="$rar" filename=`echo "$rar" | sed 's/'$type5a'//'` #filename=`echo "$rar" | cut -f 1 -d '.'` fi if [ "$filename" != "" ] then cecho "magenta" $"extracting $filelink" location="$PWD" #cecho "red" "$location" cd "$extractdirectory" if [ ! -d "$filename" ] then mkdir "$filename" fi cd "$filename" info=`time(nice -n 19 unrar x "$location/$filelink" 2>&1)` good=$(echo "$info" | grep "All OK") cd "$location" if [ "$good" = "" ] then cecho "red" "$filelink error" echo "$info " > "$filelink-error.txt" cecho "blue" $"moving" mv "$filename"* "$repairdirectory" else cecho "green" "$filelink processed" cecho "blue" $"removing" rm -rf "$filename"* fi fi done cecho "green" $"completed" cecho "blue" "---------------" done cecho "green" $"done" echo -n $"are you sure you want to exit [Y/n]? " read input if [ "$input" = "n" ] then exit 0 fi