File: CheckSFV

package info (click to toggle)
cksfv 1.3.14-2
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 368 kB
  • sloc: ansic: 819; sh: 314; makefile: 35
file content (73 lines) | stat: -rwxr-xr-x 2,172 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#
# +---------------------------------------+
# |          == CheckSFV ==               |
# |  This is a GNOME Nautilus script.     |
# |    Save it in the scripts dir:        |
# |    ~/.gnome2/nautilus-scripts         |
# |                                       |
# |          DEPENDENCIES                 |
# |            - zenity                   |
# |            - cksfv                    |
# |                                       |
# |  When you have made it executable,    |
# |       right click an SFV file,        |
# |    select CheckSFV from the Script    |
# |        menu and let it check          |
# |      the CRCs inside the file!        |
# |                                       |
# |     Copyright (C) 2007 Mike Appelman  |
# |        [chokuchou@gmail.com]          |
# |                                       |
# |     License: GNU GPL v2 and later     |
# +---------------------------------------+

function temp_file_error() {
	zenity --error --text="Could not get a temporary file" --title="No temporary file"
	exit 1
}

if [ $# -ne 1 ] ; then
	zenity --error --text="Can check only one file at a time!" --title="Too many files"
	exit 1
elif [ ${1##*.} != 'sfv' ] ; then
	zenity --error --text="File \'$1\' doesn't have .sfv extension and will not be checked." --title="Wrong extension"
	exit 1
fi

declare -i x=0
while [ $x -lt $(cat "$1" | wc -l) ] ; do
	declare -i let x=x+1
	head -n $x "$1" | tail -n 1 > /dev/null
done

(
	declare -i p=0
	while [ $p -lt $x ] ; do
       		p=$((p+1))

		tmpfile1=$(tempfile)
		if test "$?" != "0" ; then
			temp_file_error
		fi
		tmpfile2=$(tempfile)
		if test "$?" != "0" ; then
			temp_file_error
		fi

	       	head -n $p "$1" | tail -n 1 > "$tmpfile1"
		cksfv -f "$tmpfile1" 2> "$tmpfile2"
		check=$?
		file=$(tail -n 3 "$tmpfile2" | head -n 1 | awk '{ print $1 }')

		if [ $check -ne 0 ] ; then
			zenity --error --text="CRC Check failed: \'$file\'" --title="Check failed"
			exit 1
		else
			percent=$(((100 * p) / x))
			echo "$percent%"
			echo '#'"Checking \'$file\' ... $percent%"
		fi
	done
)| zenity --progress --text="Loading \'$1\'..." --title="Checking..." --auto-close
exit 0