db-update.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. TOKEN="$1"
  3. FILE="DB3LITEBIN"
  4. URL="https://www.ip2location.com/download/?token=${TOKEN}&file=${FILE}"
  5. FILE_ZIP_SOURCE="/tmp/db.zip"
  6. FILE_BIN_SOURCE="/tmp/IP2LOCATION-LITE-DB3.BIN"
  7. FILE_BIN_TARGET="$2"
  8. if [ "${TOKEN}" = "" ]; then
  9. echo "Please, set token"
  10. exit 1
  11. fi
  12. # Download
  13. echo "Download ip2location file..."
  14. curl -s -o "${FILE_ZIP_SOURCE}" "${URL}"
  15. # Check
  16. if [ ! -f "${FILE_ZIP_SOURCE}" ]; then
  17. echo "ZIP file is not exists"
  18. exit 1
  19. fi
  20. SIZE=$(stat --printf="%s" "${FILE_ZIP_SOURCE}")
  21. if [ ${SIZE} -lt 1024 ]; then
  22. echo "ZIP file is small: ${SIZE}"
  23. cat "${FILE_ZIP_SOURCE}"
  24. echo "" && rm "${FILE_ZIP_SOURCE}"
  25. exit 1
  26. fi
  27. # Unpack
  28. unzip -p "${FILE_ZIP_SOURCE}" "IP2LOCATION-LITE-DB3.BIN" > "${FILE_BIN_SOURCE}"
  29. rm "${FILE_ZIP_SOURCE}"
  30. # Check
  31. if [ ! -f "${FILE_BIN_SOURCE}" ]; then
  32. echo "BIN file is not exists"
  33. exit 1
  34. fi
  35. SIZE=$(stat --printf="%s" "${FILE_BIN_SOURCE}")
  36. if [ ${SIZE} -lt 1024 ]; then
  37. echo "BIN file is small: ${SIZE}"
  38. rm "${FILE_BIN_SOURCE}"
  39. exit 1
  40. fi
  41. # Replace
  42. mv "${FILE_BIN_SOURCE}" "${FILE_BIN_TARGET}"