@@ -15,15 +15,15 @@ function about
15
15
echo -e " \e[0K\r" " \e[38;5;${i} m\t\t\tWritten by Soham Bagayatkar\e[0m" ;
16
16
echo -en " \e[1A" ;
17
17
sleep .05;
18
- done ;
18
+ done ;
19
19
echo
20
20
echo -en " \e[1A" ;
21
21
echo -e " \e[0K\r" ;
22
22
}
23
23
function usage
24
24
{
25
25
cat << EOF
26
- Usage:
26
+ Usage:
27
27
filemoddetect [OPTION...] [FILE...] - File Modification Detector
28
28
29
29
Help Options:
@@ -119,7 +119,7 @@ if [ $colmode = true ]; then
119
119
lblue=' \033[1;34m' ; purple=' \033[0;35m' ; lpurple=' \033[1;35m'
120
120
cyan=' \033[0;36m' ; lcyan=' \033[1;36m' ; lgray=' \033[0;37m'
121
121
white=' \033[1;37m' ;
122
-
122
+
123
123
fg_black=$( tput setaf 0) ; fg_red=$( tput setaf 1) ; fg_green=$( tput setaf 2)
124
124
fg_yellow=$( tput setaf 3) ; fg_blue=$( tput setaf 4) ; fg_magenta=$( tput setaf 5)
125
125
fg_cyan=$( tput setaf 6) ; fg_white=$( tput setaf 7)
@@ -130,7 +130,7 @@ if [ $colmode = true ]; then
130
130
fi
131
131
nc=' \033[0m' # No Color
132
132
revcol=$( tput rev)
133
-
133
+
134
134
blink=$( tput blink) ; bold=$( tput bold) ; dim=$( tput dim) ; nc=$( tput sgr0)
135
135
defforcol=$( tput setaf sgr9) ; defbackcol=$( tput setab sgr9)
136
136
@@ -209,7 +209,7 @@ if [ "$1" != "" ]; then
209
209
-e | --exclude=* )
210
210
if [[ $1 = " --exclude=" * ]]; then
211
211
te=$1 ; te=${te: 10}
212
- excludefile+=(` readlink -f " $te " ` ); excludeon=true
212
+ excludefile+=(` readlink -f " $te " ` ); excludeon=true
213
213
echo -e " \nExcluding file/directory: ${excludefile[-1]} \n"
214
214
else
215
215
if [[ -z $2 ]]; then
@@ -256,7 +256,7 @@ if [ "$1" != "" ]; then
256
256
fi
257
257
done
258
258
fi
259
- unset $IFS # or IFS=$' \t\n'
259
+ unset $IFS # or IFS=$' \t\n'
260
260
261
261
if [[ $excludeon = true ]]; then
262
262
unset excludefile[0]
@@ -272,7 +272,7 @@ printf "\nCurrent directory $filepath\n\n"
272
272
273
273
if [[ $logmode = true ]]; then
274
274
logat=$( date +" %m-%d-%y--%T" )
275
- echo -e " ${logat} \t\tCurrent directory $filepath " >> $logname
275
+ echo -e " ${logat} \t\tCurrent directory $filepath " >> $logname
276
276
fi
277
277
278
278
if [ $optionerror = true ]; then
282
282
if [ $colmode = false ]; then
283
283
black=' ' ; dgray=' ' ; red=' ' ; lred=' ' ; green=' ' ; lgreen=' ' ; brownorange=' ' ; yellow=' ' ; blue=' ' ;
284
284
lblue=' ' ; purple=' ' ; lpurple=' ' ; cyan=' ' ; lcyan=' ' ; lgray=' ' white=' ' ;
285
-
285
+
286
286
fg_black=' ' ; fg_red=' ' ; fg_green=' '
287
287
fg_yellow=' ' ; fg_blue=' ' ; fg_magenta=' '
288
288
fg_cyan=' ' ; fg_white=' '
295
295
# check size
296
296
if [[ -d $filepath ]]; then
297
297
if [ -r $filepath ]; then
298
- if [[ $recmode == true ]]; then
298
+ if [[ $recmode == true ]]; then
299
299
CHECK=" ` du -hs $filepath | cut -f1` "
300
300
else
301
301
CHECK=" ` find $filepath -maxdepth 1 -type f -printf " %s + " | dc -e0 -f- -ep` "
@@ -340,7 +340,7 @@ if [[ $excludeon = true && $recmode == false ]]; then #if this condition then ma
340
340
fi
341
341
fi
342
342
fi
343
-
343
+
344
344
else
345
345
if [[ $excludeon = true ]]; then
346
346
if (( ${# excludefile[@]} < 2 )) ; then
380
380
# echo -en "${green}${bold}${#files[@]}$nc files found ~ $lblue$bold$CHECK$nc & ${bold}${yellow}${directs}${nc} directories";
381
381
if [[ " ${directs} " == " 0" && " ${# files[@]} " == " 0" ]]; then
382
382
echo -e " Nothing found!" ;
383
-
383
+
384
384
if [[ $logmode = true ]]; then
385
385
logat=$( date +" %m-%d-%y--%T" )
386
- echo -e " ${logat} \t\tNothing found!" >> $logname
386
+ echo -e " ${logat} \t\tNothing found!" >> $logname
387
387
fi
388
388
exit
389
389
else
@@ -411,10 +411,10 @@ if [ $excludeon = true ]; then
411
411
unset $IFS # or IFS=$' \t\n'
412
412
else
413
413
echo -e " Directory '$exc ' has not given ${brownorange} read${nc} permission! (Try using sudo)"
414
-
414
+
415
415
if [[ $logmode = true ]]; then
416
416
logat=$( date +" %m-%d-%y--%T" )
417
- echo -e " ${logat} \t\tDirectory '$exc ' has not given read permission! (Try using sudo)" >> $logname
417
+ echo -e " ${logat} \t\tDirectory '$exc ' has not given read permission! (Try using sudo)" >> $logname
418
418
fi
419
419
exit
420
420
fi
@@ -428,7 +428,7 @@ if [ $excludeon = true ]; then
428
428
echo -e " File '$exc ' has not given ${brownorange} read${nc} permission! (Try using sudo)"
429
429
if [[ $logmode = true ]]; then
430
430
logat=$( date +" %m-%d-%y--%T" )
431
- echo -e " ${logat} \t\tFile '$exc ' has not given read permission! (Try using sudo)}" >> $logname
431
+ echo -e " ${logat} \t\tFile '$exc ' has not given read permission! (Try using sudo)}" >> $logname
432
432
fi
433
433
exit
434
434
fi
@@ -440,7 +440,7 @@ if [ $excludeon = true ]; then
440
440
fi
441
441
exit
442
442
fi
443
-
443
+
444
444
if [[ $failedbyfirst = true ]]; then
445
445
arrtemp=()
446
446
for i in " ${files[@]} " ; do
@@ -457,13 +457,13 @@ if [ $excludeon = true ]; then
457
457
echo " Excluding file/directory $exc is $excludelen in size."
458
458
if [[ $logmode = true ]]; then
459
459
logat=$( date +" %m-%d-%y--%T" )
460
- echo -e " ${logat} \t\tExcluding file/directory $exc is $excludelen in size." >> $logname
460
+ echo -e " ${logat} \t\tExcluding file/directory $exc is $excludelen in size." >> $logname
461
461
fi
462
462
fi
463
463
done
464
464
fi
465
465
466
- title=" Choose one of the following option"
466
+ title=" Choose one of the following option"
467
467
# printf "%*s\n" $(((${#title}+$COL)/2)) "$title"
468
468
echo
469
469
centerQ " $title "
529
529
echo -e " ${lred} Invalid response!${nc} "
530
530
if [[ $logmode = true ]]; then
531
531
logat=$( date +" %m-%d-%y--%T" )
532
- echo -e " ${logat} \t\tInvalid response!" >> $logname
532
+ echo -e " ${logat} \t\tInvalid response!" >> $logname
533
533
fi
534
534
fi
535
535
@@ -542,7 +542,7 @@ if [[ $checkmd = "scan" ]]; then
542
542
else
543
543
echo " Creating md5sums..."
544
544
fi
545
-
545
+
546
546
if [[ $logmode = true ]]; then
547
547
logat=$( date +" %m-%d-%y--%T" )
548
548
if [[ $renamemode = true ]]; then
@@ -552,19 +552,19 @@ if [[ $checkmd = "scan" ]]; then
552
552
fi
553
553
echo >> $logname
554
554
fi
555
-
555
+
556
556
filename=" $filepath /md5sum$now .txt"
557
557
num=1; i=0; errorocc=0; donesize=0
558
558
# declare -i totsize; declare -i donesize
559
- # totsize=`du -sb ${files[@] | cut -f1`;
559
+ # totsize=`du -sb ${files[@] | cut -f1`;
560
560
561
561
if [[ ( $failedbyfirst = false && ${# excludefile[@]} > 1 ) || ( $failedbyfirst = true && ${# excludefile[@]} > 0 ) ]]; then
562
562
# elif [[ $failedbyfirst = true && ${#excludefile[@]} > 0 ]]; then
563
563
for j in " ${excludefile[@]} " ; do
564
- echo " Skipping .... $j "
564
+ echo " Skipping .... $j "
565
565
if [[ $logmode = true ]]; then
566
566
logat=$( date +" %m-%d-%y--%T" )
567
- echo -e " ${logat} \t\tSkipping .... $j " >> $logname
567
+ echo -e " ${logat} \t\tSkipping .... $j " >> $logname
568
568
echo >> $logname
569
569
fi
570
570
done
@@ -579,7 +579,7 @@ if [[ $checkmd = "scan" ]]; then
579
579
echo -e " ${lred} File $i does not exist!${nc} "
580
580
if [[ $logmode = true ]]; then
581
581
logat=$( date +" %m-%d-%y--%T" )
582
- echo -e " ${logat} \t\tFile $i does not exist!" >> $logname
582
+ echo -e " ${logat} \t\tFile $i does not exist!" >> $logname
583
583
fi
584
584
fi
585
585
done
@@ -610,7 +610,7 @@ if [[ $checkmd = "scan" ]]; then
610
610
echo -e " \r${lred} Cancelled......${nc} @ ${percent} %\n\n"
611
611
if [[ $logmode = true ]]; then
612
612
logat=$( date +" %m-%d-%y--%T" )
613
- echo -e " ${logat} \t\tCancelled......" >> $logname
613
+ echo -e " ${logat} \t\tCancelled......" >> $logname
614
614
fi
615
615
temptime2=` date +%s`
616
616
temptime=$(( $temptime2 - $temptime ))
@@ -621,7 +621,7 @@ if [[ $checkmd = "scan" ]]; then
621
621
622
622
if [[ $logmode = true ]]; then
623
623
logat=$( date +" %m-%d-%y--%T" )
624
- echo -e " ${logat} \t\tResumed......" >> $logname
624
+ echo -e " ${logat} \t\tResumed......" >> $logname
625
625
626
626
if [[ $renamemode = true ]]; then
627
627
echo -e " ${lred} Last renaming of ${files[$((num-1))]} is failed!........${nc} (Reason: Due to inturruption)" 2>&1 | tee -a $logname
@@ -633,11 +633,11 @@ if [[ $checkmd = "scan" ]]; then
633
633
634
634
else
635
635
if [[ $renamemode = true ]]; then
636
- echo -e " ${lred} Last renaming of ${files[$((num-1))]} is failed!........${nc} (Reason: Due to inturruption)"
637
- echo -e " ${lcyan} Renaming last file........${nc} "
636
+ echo -e " ${lred} Last renaming of ${files[$((num-1))]} is failed!........${nc} (Reason: Due to inturruption)"
637
+ echo -e " ${lcyan} Renaming last file........${nc} "
638
638
else
639
- echo -e " ${lred} Last md5sum calculation of ${files[$((num-1))]} is failed!........${nc} (Reason: Due to inturruption)"
640
- echo -e " ${lcyan} Recalculating last md5sum........${nc} "
639
+ echo -e " ${lred} Last md5sum calculation of ${files[$((num-1))]} is failed!........${nc} (Reason: Due to inturruption)"
640
+ echo -e " ${lcyan} Recalculating last md5sum........${nc} "
641
641
fi
642
642
643
643
fi
@@ -658,7 +658,7 @@ if [[ $checkmd = "scan" ]]; then
658
658
logat=$( date +" %m-%d-%y--%T" )
659
659
echo -e " ${logat} \t\tProcessing.... ${files[num-1]} " >> $logname
660
660
fi
661
-
661
+
662
662
if [ -f ${files[num-1]} -a -r ${files[num-1]} ]; then
663
663
cursize=` du -sb ${files[num-1]} | cut -f1`
664
664
if [[ $renamemode = true ]]; then
@@ -698,7 +698,7 @@ if [[ $checkmd = "scan" ]]; then
698
698
echo -e " File ${files[num-1]} does not exist!"
699
699
if [[ $logmode = true ]]; then
700
700
logat=$( date +" %m-%d-%y--%T" )
701
- echo -e " ${logat} \t\tFile ${files[num-1]} does not exist!" >> $logname
701
+ echo -e " ${logat} \t\tFile ${files[num-1]} does not exist!" >> $logname
702
702
fi
703
703
(( errorocc++ ))
704
704
thisfilefailed=true
@@ -719,7 +719,7 @@ if [[ $checkmd = "scan" ]]; then
719
719
if [[ $logmode = true ]]; then
720
720
echo >> $logname
721
721
fi
722
-
722
+
723
723
if [[ $thisfilefailed = true ]]; then
724
724
echo -e " \e[0K\r${lred} Processing of ${files[num-1]}${nc} failed!"
725
725
if [[ $logmode = true ]]; then
@@ -738,7 +738,7 @@ if [[ $checkmd = "scan" ]]; then
738
738
if [ " $canc " != " Y" ]; then
739
739
# echo -en "\e[1A";
740
740
if (( "$errorocc " > "0 " )) ; then
741
- echo -e " \e[0K\rTotal ${yellow} " $(( num- errorocc)) " ${nc} of ${# files[@]} processed. ${lred}${errorocc} failed!${nc} "
741
+ echo -e " \e[0K\rTotal ${yellow} " $(( num- errorocc)) " ${nc} of ${# files[@]} processed. ${lred}${errorocc} failed!${nc} "
742
742
else
743
743
echo -e " \e[0K\rTotal $num of ${# files[@]} processed."
744
744
fi
@@ -760,7 +760,7 @@ if [[ $checkmd = "scan" ]]; then
760
760
logat=$( date +" %m-%d-%y--%T" )
761
761
echo -e " ${logat} \t\tGenerating grandmd5sum ...." >> $logname
762
762
fi
763
-
763
+
764
764
($( find $filepath -type f \( -name " md5sum*.txt" \) -exec md5sum {} + > $filepath /grandmd5sum$now .txt ) )
765
765
fi
766
766
# files=(`find $filepath -type f \( -regextype sed -not -regex ${regex} \) `)
@@ -897,7 +897,7 @@ elif [[ $checkmd = "check" ]]; then
897
897
echo
898
898
done
899
899
else
900
- echo " No files found for md5sum comparision ."
900
+ echo " No files found for md5sum comparison ."
901
901
fi
902
902
# error_exit "$LINENO: An error has occurred."
903
903
echo
0 commit comments