@@ -18,21 +18,68 @@ echo "login $USER" >> "$NETRC"
18
18
echo " password $FTP_SECRET " >> " $NETRC "
19
19
chmod 600 " $NETRC "
20
20
21
+ # create_archive will create a tar ball from the out folder
22
+ # try to extract it to see if it is valid
23
+ # retry 3 times then fail
24
+ create_archive{
25
+ MAX_RETRIES=3
26
+ RETRY_COUNT=0
27
+
28
+ while (( RETRY_COUNT < MAX_RETRIES )) ; do
29
+ (cd out; tar czf $EMULATOR .tgz $EMULATOR )
30
+
31
+ # Verify the tarball
32
+ if tar tf $EMULATOR .tgz > /dev/null 2>&1 ; then
33
+ echo " Tarball is valid and can be expanded."
34
+ break
35
+ else
36
+ echo " Tarball is not valid or cannot be expanded. Retrying..."
37
+ RETRY_COUNT=$(( RETRY_COUNT + 1 ))
38
+ rm -f $EMULATOR .tgz
39
+ continue
40
+ fi
41
+ done
42
+
43
+ if (( RETRY_COUNT == MAX_RETRIES )) ; then
44
+ echo " Failed to create a valid tarball after $MAX_RETRIES attempts."
45
+ return 1
46
+ fi
47
+ }
48
+
49
+ # upload_file tries to upload the tar ball to the FTP server, will retry 5 times and then fail
21
50
upload_file (){
22
- (cd out; tar czf $EMULATOR .tgz $EMULATOR )
51
+ MAX_RETRIES=5
52
+ RETRY_COUNT=0
23
53
24
- echo " Deploying as $USER at $HOST "
54
+ while (( RETRY_COUNT < MAX_RETRIES )) ; do
55
+ echo " Deploying as $USER at $HOST "
25
56
26
- ftp " $HOST " << EOF
57
+ # Attempt to upload the file
58
+ if ftp " $HOST " << EOF
27
59
passive on
28
60
type image
29
61
cd $DIR
30
62
lcd out
31
63
put $EMULATOR .tgz
32
64
bye
33
65
EOF
66
+ then
67
+ echo " Upload successful."
68
+ break
69
+ else
70
+ echo " Upload failed. Retrying..."
71
+ RETRY_COUNT=$(( RETRY_COUNT + 1 ))
72
+ fi
73
+ done
74
+
75
+ if (( RETRY_COUNT == MAX_RETRIES )) ; then
76
+ echo " Failed to upload the file after $MAX_RETRIES attempts."
77
+ return 1
78
+ fi
34
79
}
35
80
81
+ # test_archive_integrity will download the tarball after successful upload and verify its integrity
82
+ # by binary comparing the contents of the source folder and the expanded folder
36
83
test_archive_integrity (){
37
84
echo " Testing download of $EMULATOR .tgz"
38
85
mkdir -p " $TESTDIR "
@@ -78,8 +125,9 @@ test_archive_integrity(){
78
125
fi
79
126
}
80
127
81
-
128
+ # main loop
82
129
while [ $retry_count -lt $RETRY_LIMIT ]; do
130
+ create_archive
83
131
upload_file
84
132
if test_archive_integrity; then
85
133
echo " File integrity verified successfully."
0 commit comments