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.

88 lines
2.4 KiB

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