MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
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.

60 lines
1.5 KiB

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