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