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.

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