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.

56 lines
1.4 KiB

  1. #!/bin/bash
  2. REPO_TYPE=$1
  3. REPO_NAME=$2
  4. function usage() {
  5. local BASECMD=$(basename "$0")
  6. echo 'usage: <REPO_TYPE> <REPO_NAME> [DESTINATION]'
  7. echo 'example:'
  8. echo -e '\t# REPO_TYPE=github'
  9. echo -e "\t$BASECMD github Dolibarr/dolibarr\n"
  10. echo -e '\t# REPO_TYPE=artcode'
  11. echo -e "\t$BASECMD artcode pvincent/debian-gnome\n"
  12. exit -1
  13. }
  14. function get_github() {
  15. local all_releases=$(git ls-remote --tags --sort="v:refname" git://github.com/$REPO_NAME | grep -Eo "v?([0-9]\.)+[0-9]+")
  16. # extract only VERSION without 'v'
  17. local non_v_release=$(echo "$all_releases" |
  18. grep -v "refs/tags/v" | grep -v v | tail -n1 | cut -f2 | cut -d '/' -f3)
  19. non_v_release=${non_v_release%^\{\}} # remove extra characters ^{} from github
  20. [ -n "$non_v_release" ] && echo $non_v_release && return
  21. # extract remaining version including 'v'
  22. local v_release=$(echo "$all_releases" | tail -n1 | cut -f2 | cut -d '/' -f3)
  23. v_release=${v_release%^\{\}} # remove extra characters ^{} from github
  24. echo $v_release
  25. }
  26. function get_artcode() {
  27. release=$(git ls-remote --tags --sort="v:refname" \
  28. https://git.artcode.re/$REPO_NAME |
  29. tail -n1 | cut -f2 | cut -d '/' -f3)
  30. echo $release
  31. }
  32. [[ $# -ne 2 ]] && usage
  33. if [ -z "$(command -v git)" ]; then
  34. echo "INSTALLING PACKAGE <GIT> required"
  35. sudo apt install -y git
  36. fi
  37. case $REPO_TYPE in
  38. github)
  39. get_github
  40. ;;
  41. artcode)
  42. get_artcode
  43. ;;
  44. *)
  45. echo "repository type <${REPO_TYPE}> not yet supported!" && exit 1
  46. ;;
  47. esac