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.

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