Browse Source

check remote image before downloading

master
Robin Thoni 8 years ago
parent
commit
539cf22e6f
1 changed files with 17 additions and 0 deletions
  1. 17
    0
      update_img.sh

+ 17
- 0
update_img.sh View File

@@ -4,6 +4,23 @@ img="prololive.img"
4 4
 img_tmp="${img}.tmp"
5 5
 img_url="http://srv.ordiclic.eu/prololive.img"
6 6
 
7
+if [ ! -f "${img}" ]
8
+then
9
+  local_size=0
10
+  remote_size=1
11
+else
12
+  remote_size=$(curl -s --head "${img_url}" | grep Content-Length | grep -oE [0-9]+)
13
+  local_size=$(stat --printf="%s" "${img}")
14
+fi
15
+
16
+if [ "${local_size}" -eq "${remote_size}" ]
17
+then
18
+  echo "Remote image is probably the same"
19
+  exit
20
+fi
21
+
22
+rm -f "${img}"
23
+
7 24
 wget "${img_url}" -O "${img_tmp}" || {
8 25
   rm "${img_tmp}"
9 26
   echo "Failed to download image" >&2

Loading…
Cancel
Save