Initial import from 0.5a version.
[secure-linux-project.git] / encrypt / search_hdd.sh
1 #!/bin/sh
2 ##############################################
3 # Script for Secure Linux Project            #
4 # Copyright(c) 2005, 2006 by Roland Haeder   #
5 ##############################################
6 # Purpose: See below                         #
7 ##############################################
8 # This software is licensed under the GNU    #
9 # General Public License Version 2 or either #
10 # and comes with ABSOLUTELY NO WARRANTY      #
11 # neither implied nor explicit.              #
12 ##############################################
13
14 # The purpose of this script is to search for lost/deleted scripts (plain text)
15 # or which you have maybe overwritten by "echo foo>bar" and bar was a very
16 # important 12600 Bytes long script for you.
17
18 #### Configuration ######
19
20 # The MEDIUM holding the filesystem where you have deleted/overwritten the
21 # script. This can also be a partition! E.g. /dev/hda
22 MEDIUM=""
23
24 # Search string you are looking for. This shall be a string within middle of
25 # The lost file. It shall be unique so you have beeter search results in first
26 # run.
27 SEARCH=""
28
29 # Skipped bytes by dd command
30 # Enter the value which you get from grep command -2048 here and run this
31 # script again.
32 SKIP=""
33
34 # Size in bytes; no exact value here. Give +4096 more for looking around target
35 # area)
36 SIZE=""
37
38 # The target file we shall write the found data. This *shall better* be
39 # an other drive/partition than MEDIUM. Or else maybe some data could be
40 # overwritten by this command which you also want to restore!
41 TARGET=""
42 # Do *always* enter a filename here (like /var/test.sh; where /var/ is mounted
43 # on other partition as MEDIUM
44
45 # Self-test, you need "grep" and "dd" for this script!
46 DD=`which dd`
47 GREP=`which grep`
48 if test "$DD" == "" || test "$GREP" == ""; then
49         echo "$0: Self-test failed! Cannot find dd or grep!"
50         echo
51         echo "DD   = $DD"
52         echo "GREP = $GREP"
53 else
54         echo "$0: Self-test passed."
55 fi
56
57 if test "$SKIP" != "" && test "$SIZE" != ""; then
58         # Output data to TARGET
59         echo -n "$0: Writing $SIZE Bytes to $TARGET... "
60         dd if=$MEDIUM skip=$SKIP bs=1 count=$SIZE > $TARGET
61         echo "done"
62         # Hint: You may have to experiment a little with SIZE and SKIP until
63         # you find your lost file. But -2048 for SKIP and +4096 for SIZE might
64         # be a good starting point.
65 elif test "$SEARCH" != "" && test "$MEDIUM" != ""; then
66         # Search on MEDIUM for SEARCH. This may take long!
67         echo "$0: Searching for $SEARCH ... This may take loooong . . ."
68         grep --text -b $SEARCH $MEDIUM
69 else
70         # Please setup me!
71         echo "$0: You have to setup this script ($0) first!"    
72 fi