You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4 KiB

  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-3.0+
  3. # Copyright (C) 2018, Martin Kepplinger <martink@posteo.de>
  4. set -e
  5. source functions.sh
  6. usage()
  7. {
  8. echo "Skulls for the X230"
  9. echo ""
  10. echo " This script checks if there's a newer"
  11. echo " release of the X230 Skulls package available."
  12. echo ""
  13. echo "Usage: $0"
  14. }
  15. args=$(getopt -o h -- "$@")
  16. if [ $? -ne 0 ] ; then
  17. usage
  18. exit 1
  19. fi
  20. eval set -- "$args"
  21. while [ $# -gt 0 ]
  22. do
  23. case "$1" in
  24. -h)
  25. usage
  26. exit 1
  27. ;;
  28. --)
  29. shift
  30. break
  31. ;;
  32. *)
  33. echo "Invalid option: $1"
  34. exit 1
  35. ;;
  36. esac
  37. shift
  38. done
  39. warn_not_root
  40. command -v curl >/dev/null 2>&1 || { echo -e >&2 "${RED}Please install curl.${NC}"; exit 1; }
  41. CURRENT_VERSION=$(head -2 NEWS | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
  42. UPSTREAM_FILE=$(curl -s https://api.github.com/repos/merge/skulls/releases/latest | grep browser_download_url | cut -d'"' -f4 | cut -d'/' -f9 | head -n 1)
  43. UPSTREAM_VERSION=$(curl -s https://api.github.com/repos/merge/skulls/releases/latest | grep browser_download_url | cut -d'"' -f4 | cut -d'/' -f9 | head -n 1 | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
  44. UPSTREAM_X230=$(echo ${UPSTREAM_FILE} | grep x230)
  45. if [[ -z "$UPSTREAM_X230" ]] ; then
  46. echo "The latest release didn't include the X230"
  47. exit 0
  48. fi
  49. if [[ "$CURRENT_VERSION" = "$UPSTREAM_VERSION" ]] ; then
  50. echo -e "${GREEN}You are using the latest version of Skulls for the X230${NC}"
  51. exit 0
  52. elif [[ "$CURRENT_VERSION" < "$UPSTREAM_VERSION" ]] ; then
  53. echo -e "${RED}You have ${CURRENT_VERSION} but there is version ${UPSTREAM_VERSION} available for the X230. Please update.${NC}"
  54. read -r -p "Download it to the parent directory now? [y/N] " response
  55. case "$response" in
  56. [yY][eE][sS]|[yY])
  57. UPSTREAM_URL=$(curl -s https://api.github.com/repos/merge/skulls/releases/latest | grep browser_download_url | cut -d'"' -f4 | head -n 1)
  58. UPSTREAM_URL_SHA256=$(curl -s https://api.github.com/repos/merge/skulls/releases/latest | grep browser_download_url | cut -d'"' -f4 | head -n 3 | tail -n 1)
  59. cd ..
  60. curl -LO ${UPSTREAM_URL}
  61. curl -LO ${UPSTREAM_URL_SHA256}
  62. sha256sum -c ${UPSTREAM_FILE}.sha256
  63. mkdir skulls-x230-${UPSTREAM_VERSION}
  64. tar -xf ${UPSTREAM_FILE} -C skulls-x230-${UPSTREAM_VERSION}/
  65. echo "Version ${UPSTREAM_VERSION} extracted to ../skulls-x230-${UPSTREAM_VERSION}/"
  66. ;;
  67. *)
  68. exit 0
  69. ;;
  70. esac
  71. else
  72. echo "You seem to use a development version. Please use release package skulls-x230 ${UPSTREAM_VERSION} for flashing."
  73. fi