Debian Codegraph @

scripts/CheckSFV

raw
1 #!/bin/bash
2 #
3 # +---------------------------------------+
4 # | == CheckSFV == |
5 # | This is a GNOME Nautilus script. |
6 # | Save it in the scripts dir: |
7 # | ~/.gnome2/nautilus-scripts |
8 # | |
9 # | DEPENDENCIES |
10 # | - zenity |
11 # | - cksfv |
12 # | |
13 # | When you have made it executable, |
14 # | right click an SFV file, |
15 # | select CheckSFV from the Script |
16 # | menu and let it check |
17 # | the CRCs inside the file! |
18 # | |
19 # | Copyright (C) 2007 Mike Appelman |
20 # | [[email protected]] |
21 # | |
22 # | License: GNU GPL v2 and later |
23 # +---------------------------------------+
24
25 function temp_file_error() {
26 zenity --error --text="Could not get a temporary file" --title="No temporary file"
27 exit 1
28 }
29
30 if [ $# -ne 1 ] ; then
31 zenity --error --text="Can check only one file at a time!" --title="Too many files"
32 exit 1
33 elif [ ${1##*.} != 'sfv' ] ; then
34 zenity --error --text="File \'$1\' doesn't have .sfv extension and will not be checked." --title="Wrong extension"
35 exit 1
36 fi
37
38 declare -i x=0
39 while [ $x -lt $(cat "$1" | wc -l) ] ; do
40 declare -i let x=x+1
41 head -n $x "$1" | tail -n 1 > /dev/null
42 done
43
44 (
45 declare -i p=0
46 while [ $p -lt $x ] ; do
47 p=$((p+1))
48
49 tmpfile1=$(tempfile)
50 if test "$?" != "0" ; then
51 temp_file_error
52 fi
53 tmpfile2=$(tempfile)
54 if test "$?" != "0" ; then
55 temp_file_error
56 fi
57
58 head -n $p "$1" | tail -n 1 > "$tmpfile1"
59 cksfv -f "$tmpfile1" 2> "$tmpfile2"
60 check=$?
61 file=$(tail -n 3 "$tmpfile2" | head -n 1 | awk '{ print $1 }')
62
63 if [ $check -ne 0 ] ; then
64 zenity --error --text="CRC Check failed: \'$file\'" --title="Check failed"
65 exit 1
66 else
67 percent=$(((100 * p) / x))
68 echo "$percent%"
69 echo '#'"Checking \'$file\' ... $percent%"
70 fi
71 done
72 )| zenity --progress --text="Loading \'$1\'..." --title="Checking..." --auto-close
73 exit 0