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.

58 lines
1.5 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
  1. #!/bin/bash
  2. REPO_TYPE=$1
  3. REPO_NAME=$2
  4. function usage {
  5. local basecmd
  6. basecmd=$(basename "$0")
  7. echo 'usage: <REPO_TYPE> <REPO_NAME> [DESTINATION]'
  8. echo 'example:'
  9. echo -e '\t# REPO_TYPE=github'
  10. echo -e "\t${basecmd} github Dolibarr/dolibarr\n"
  11. echo -e '\t# REPO_TYPE=artcode'
  12. echo -e "\t${basecmd} artcode libre/libre-gnome\n"
  13. exit 1
  14. }
  15. function get_github {
  16. local all_releases=$(git ls-remote --tags --sort="v:refname" https://github.com/"$REPO_NAME" | grep -Eo "v?([0-9]+\.){2}[0-9]+$")
  17. # extract only VERSION without 'v'
  18. local non_v_release=$(echo "$all_releases" | grep -v v | tail -n1 | cut -f2 | cut -d '/' -f3)
  19. non_v_release=${non_v_release%^\{\}} # remove extra characters ^{} from github
  20. # extract remaining version including 'v'
  21. local v_release=$(echo "$all_releases" | tail -n1 | cut -f2 | cut -d '/' -f3)
  22. v_release=${v_release%^\{\}} # remove extra characters ^{} from github
  23. # compare which newer from non_v_release to v_release
  24. if [ -n "$non_v_release" ] && [ "v$non_v_release" \> "$v_release" ]; then
  25. echo $non_v_release
  26. else
  27. echo $v_release
  28. fi
  29. }
  30. function get_artcode {
  31. git ls-remote --tags --sort="v:refname" "https://git.artcode.re/$REPO_NAME" | tail -n1 | cut -f2 | cut -d '/' -f3
  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