-
Notifications
You must be signed in to change notification settings - Fork 12
/
Checksum_check_checker.sh
146 lines (111 loc) · 3.53 KB
/
Checksum_check_checker.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/bash
source $HOME/.bash_profile;
DOWNLOAD_FOLDER=/mnt/s2bl2a_rep/CHECKSUM_TEST/;
RUNFILE=/data/tools/Checksum_check_checker/run.lock;
LIST=$DOWNLOAD_FOLDER/LISTS/DownloadList.txt;
ERROR_FOLDER=$DOWNLOAD_FOLDER/ERROR_FOLDER/;
CALCULATE_CHECKSUM_FOLDER=$DOWNLOAD_FOLDER/CALCULATE_CHECKSUM_FOLDER/;
LIST_TO_CALCULATE=$DOWNLOAD_FOLDER/LISTS/list_to_calculate.zip
LASTDATETIME=`cat $DOWNLOAD_FOLDER/LISTS/LASTDATETIME.txt`
NOW=`date -u +"%Y-%m-%d %H:%M:%S UTC"`;
TODAY=`date -u +"%Y%m%d"`;
LASTDATETIME_TEMP=$DOWNLOAD_FOLDER/LISTS/lastdatetime_temp.txt;
CHECKSUM_VALUES_ERROR=$DOWNLOAD_FOLDER/LISTS/checksums_error.txt;
CHECKSUM_VALUES=$DOWNLOAD_FOLDER/LISTS/checksums.txt;
SYSMA=$DOWNLOAD_FOLDER/SYSMA;
LOG_ZIP=/data/tools/Checksum_check_checker/log/log_zip_$TODAY.txt
function mainmenu {
echo ""
echo "Do you want to delete zip files in $CALCULATE_CHECKSUM_FOLDER ?"
ls -ltr $CALCULATE_CHECKSUM_FOLDER/*.zip;
echo ""
echo "Press y to delete"
echo "Press q to exit script without deleting"
echo ""
read -n 1 -p "Input Selection:" menuinput
if [ "$menuinput" = "y" ]; then
rm -f $CALCULATE_CHECKSUM_FOLDER/*.zip;
echo "";
elif [ "$menuinput" = "q" ]; then
echo "";
else
echo ""
echo "You have entered an invalid selection!"
echo "Please try again!"
echo ""
echo "Press any key to continue..."
read -n 1
clear
mainmenu
fi
}
function download_product {
LINE=${1};
CONTAINER=`echo $LINE | cut -d';' -f2`;
NAME=`echo $LINE | cut -d';' -f3`;
cd $DOWNLOAD_FOLDER;
/usr/local/bin/swift download $CONTAINER $NAME;
}
function test_zip {
ZIP=${1};
ZIPNAME=`basename $ZIP`;
unzip -t $ZIP >> $LOG_ZIP;
retVal=$?;
if [ $retVal -ne 0 ]; then
mv $ZIP $ERROR_FOLDER;
else
mv $ZIP $CALCULATE_CHECKSUM_FOLDER;
echo $CALCULATE_CHECKSUM_FOLDER/$ZIPNAME >> $LIST_TO_CALCULATE;
fi
}
function calculate_checksum {
FILE=${1};
FILENAME=`basename $FILE`
md5=`md5sum $FILE |awk '{print $1'}`;
retVal=$?;
product_id=`grep $FILENAME $LIST | cut -d',' -f1`;
if [ $retVal -ne 0 ]; then
echo $FILENAME","$product_id >> ${CHECKSUM_VALUES_ERROR%.*}\_$TODAY.txt;
else
echo $FILENAME","$md5","$product_id >> ${CHECKSUM_VALUES%.*}\_$TODAY.txt;
touch $SYSMA/${FILENAME%.*}\.txt;
fi
}
if [ -f "$RUNFILE" ];
then
echo "ERROR: Script is still running Exiting...";
exit 1;
fi
touch $RUNFILE;
source /data/tools/swift_env.sh;
retVal=$?;
if [ $retVal -ne 0 ]; then
echo "ERROR in source /data/tools/swift_env.sh"
exit $retVal;
fi
psql -h s2rep-pg-01.s2rep.local s2rephub -c "copy(select id,value from products p left join checksums c on (p.id=product_id) join keystoreentries k on k.entrykey=p.uuid where created > '$LASTDATETIME' and c.download_checksum_value is null and tag='unaltered' and keystore like 'datastore-s%')to stdout with delimiter ','" > $LIST;
echo $NOW > $LASTDATETIME_TEMP;
for PROD in `cat $LIST`;
do
download_product $PROD;
done
for FILE in `ls $DOWNLOAD_FOLDER/*.zip`;
do
test_zip $FILE;
done
for FILE_CHECKSUM in `cat $LIST_TO_CALCULATE`;
do
calculate_checksum $FILE_CHECKSUM;
done
rm $LIST_TO_CALCULATE;
mv $LASTDATETIME_TEMP $DOWNLOAD_FOLDER/LISTS/LASTDATETIME.txt;
rm -f $CALCULATE_CHECKSUM_FOLDER/*.zip;
rm $RUNFILE;
#mainmenu;
echo "";
echo "Created ${CHECKSUM_VALUES%.*}_$TODAY.txt containing checksums"
echo "";
echo "Created ${CHECKSUM_VALUES_ERROR%.*}_$TODAY.txt containing list of corrupted ZIP files"
echo "";
echo "To insert checksum value into the DB please run Checksum_inserter.sh ${CHECKSUM_VALUES%.*}_$TODAY.txt";
exit 0