| 1 | #!/bin/bash | 
|---|
| 2 |  | 
|---|
| 3 | sourceFolder=$1 | 
|---|
| 4 | destFolder=$2 | 
|---|
| 5 | suffix=$3 | 
|---|
| 6 |  | 
|---|
| 7 | if [ "$#" != "3" ] | 
|---|
| 8 | then | 
|---|
| 9 | echo "Please specify source and dest folders and suffix. Aborting" | 
|---|
| 10 | exit | 
|---|
| 11 | fi | 
|---|
| 12 |  | 
|---|
| 13 | if [ $1 == "" ] | 
|---|
| 14 | then | 
|---|
| 15 | echo "Source folder is empty. Aborting" | 
|---|
| 16 | exit | 
|---|
| 17 | fi | 
|---|
| 18 |  | 
|---|
| 19 | if [ $2 == "" ] | 
|---|
| 20 | then | 
|---|
| 21 | echo "Dest folder is empty. Aborting" | 
|---|
| 22 | exit | 
|---|
| 23 | fi | 
|---|
| 24 |  | 
|---|
| 25 | #first let's make sure that source and dest folders do exist, and that dest is writable | 
|---|
| 26 | if [ -d $1 ] | 
|---|
| 27 | then | 
|---|
| 28 | sourceFolder=$1 | 
|---|
| 29 | else | 
|---|
| 30 | echo "Source folder "$1" does not exist (or cannnot be read.) Aborting" | 
|---|
| 31 | exit | 
|---|
| 32 | fi | 
|---|
| 33 |  | 
|---|
| 34 | if [ -d $2 ] | 
|---|
| 35 | then | 
|---|
| 36 | if [ -d $2"/etiennetest" ] | 
|---|
| 37 | then | 
|---|
| 38 | echo "Test folder already exist. Aborting" | 
|---|
| 39 | exit | 
|---|
| 40 | fi | 
|---|
| 41 | mkdir $2"/etiennetest" 2>/dev/null | 
|---|
| 42 | if [ -d $2"/etiennetest" ] | 
|---|
| 43 | then | 
|---|
| 44 | rm -rf $2"/etiennetest" | 
|---|
| 45 | destFolder=$2 | 
|---|
| 46 | else | 
|---|
| 47 | echo "Dest folder is not writable. Aborting" | 
|---|
| 48 | exit | 
|---|
| 49 | fi | 
|---|
| 50 | else | 
|---|
| 51 | echo "Dest folder does not exist. Aborting" | 
|---|
| 52 | exit | 
|---|
| 53 | fi | 
|---|
| 54 |  | 
|---|
| 55 | #files=`ls $destFolder` | 
|---|
| 56 | #if [ "$files" != "" ] | 
|---|
| 57 | #then | 
|---|
| 58 | #       echo "Dest folder is not empty. Aborting" | 
|---|
| 59 | #       exit | 
|---|
| 60 | #fi | 
|---|
| 61 | sourceFolder=${sourceFolder%/} | 
|---|
| 62 | destFolder=${destFolder%/} | 
|---|
| 63 | echo "Will start ingesting files from "$sourceFolder" to "$destFolder | 
|---|
| 64 |  | 
|---|
| 65 | #list all the files in sourceFolder, and copy then with the same structure to destfolder | 
|---|
| 66 |  | 
|---|
| 67 | entries=`find $sourceFolder -type f -name '*.fits' | sort` | 
|---|
| 68 |  | 
|---|
| 69 | for entry in ${entries[@]} | 
|---|
| 70 | do | 
|---|
| 71 | #first construct the correct file name | 
|---|
| 72 | targetFileName=`correctFileName $entry` | 
|---|
| 73 | #second construct the destination path. | 
|---|
| 74 | filenameonly=${entry##*/} | 
|---|
| 75 | pathonly=${entry%$filenameonly} | 
|---|
| 76 | extrapathonly=${pathonly#$sourceFolder/} | 
|---|
| 77 | targetFolder=$destFolder"/"$extrapathonly | 
|---|
| 78 | if [ ! -d $targetFolder ] | 
|---|
| 79 | then | 
|---|
| 80 | mkdir -p $targetFolder | 
|---|
| 81 | fi | 
|---|
| 82 |  | 
|---|
| 83 | #check if the file already exist there | 
|---|
| 84 | targetFile=$targetFolder"/"$targetFileName | 
|---|
| 85 | echo "$targetFile" | 
|---|
| 86 | if [ -a $targetFile ] | 
|---|
| 87 | then | 
|---|
| 88 | echo "File $targetFile already exist. Skipping it" >> report_$suffix.txt | 
|---|
| 89 | continue | 
|---|
| 90 | fi | 
|---|
| 91 | cp $entry $targetFile | 
|---|
| 92 | #if not, do the copying, fixing and checking | 
|---|
| 93 |  | 
|---|
| 94 | #       grouping=`/home/isdc/lyard/FACT++/fitsdump $targetFile -h 2>/dev/null | grep GROUPING` | 
|---|
| 95 |  | 
|---|
| 96 | #       grouping=`grep 'GROUPING' "temp.txt"` | 
|---|
| 97 |  | 
|---|
| 98 | #       if [ "$grouping" == "" ] | 
|---|
| 99 | #       then | 
|---|
| 100 |  | 
|---|
| 101 | repairAuxFile.sh $targetFile ENDerrors_$suffix.txt MJDerror_$suffix.txt report_$suffix.txt processErrors_$suffix.txt | 
|---|
| 102 |  | 
|---|
| 103 | if [ -a $targetFile ] | 
|---|
| 104 | then | 
|---|
| 105 | fixAuxKeyWords.sh $targetFile reportTwo_$suffix.txt processErrors_$suffix.txt | 
|---|
| 106 | result=`fverify $targetFile 2>/dev/null | grep '0 error(s)'` | 
|---|
| 107 | if [ "$result" == "" ] | 
|---|
| 108 | then | 
|---|
| 109 | echo "$targetFile" >> stillHasProblems_$suffix.txt | 
|---|
| 110 | rm $targetFile | 
|---|
| 111 | fi | 
|---|
| 112 | fi | 
|---|
| 113 | done | 
|---|
| 114 |  | 
|---|
| 115 | #set the correct permissions | 
|---|
| 116 | find $destFolder -type f -exec chmod 640 {} \; | 
|---|
| 117 | find $destFolder -type d -exec chmod 750 {} \; | 
|---|
| 118 | find $destFolder -exec chgrp fact {} \; | 
|---|
| 119 |  | 
|---|
| 120 |  | 
|---|
| 121 |  | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 |  | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 |  | 
|---|
| 134 |  | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 |  | 
|---|
| 139 |  | 
|---|
| 140 |  | 
|---|