functions.sh 866 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Colors
  2. RED="\e[31m"
  3. GREEN="\e[32m"
  4. YELLOW="\e[33m"
  5. RESET="\e[0m"
  6. # Functions colors echo text
  7. echo_error() {
  8. echo -e "${RED}$1${RESET}"
  9. }
  10. echo_warning() {
  11. echo -e "${YELLOW}$1${RESET}"
  12. }
  13. echo_success() {
  14. echo -e "${GREEN}$1${RESET}"
  15. }
  16. # Function to check if a repository exists and perform git pull or git clone
  17. update_repository() {
  18. local repo_url="$1"
  19. local repo_dir="$2"
  20. local repo_branch="$3"
  21. if [ -d "$repo_dir" ]; then
  22. # If the directory exists, then do a git pull
  23. echo_warning "Updating $repo_dir..."
  24. cd "$repo_dir" || exit
  25. git checkout $repo_branch
  26. git pull
  27. cd - || exit
  28. else
  29. # If the directory does not exist, then do a git clone
  30. echo_warning "Cloning $repo_url into $repo_dir..."
  31. git clone -b "$repo_branch" "$repo_url" "$repo_dir"
  32. fi
  33. }