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.

57 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)
  16. # extract only VERSION without 'v'
  17. local non_v_release=$(echo "$all_releases" |
  18. grep -v "refs/tags/v" | grep -v dev | grep -v rc | 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" |
  23. grep -v dev | grep -v rc | tail -n1 | cut -f2 | cut -d '/' -f3)
  24. v_release=${v_release%^\{\}} # remove extra characters ^{} from github
  25. echo $v_release
  26. }
  27. function get_artcode() {
  28. release=$(git ls-remote --tags --sort="v:refname" \
  29. https://git.artcode.re/$REPO_NAME |
  30. tail -n1 | cut -f2 | cut -d '/' -f3)
  31. echo $release
  32. }
  33. [[ $# -ne 2 ]] && usage
  34. if [ -z "$(command -v git)" ]; then
  35. echo "INSTALLING PACKAGE <GIT> required"
  36. sudo apt install -y git
  37. fi
  38. case $REPO_TYPE in
  39. github)
  40. get_github
  41. ;;
  42. artcode)
  43. get_artcode
  44. ;;
  45. *)
  46. echo "repository type <${REPO_TYPE}> not yet supported!" && exit 1
  47. ;;
  48. esac