Advertisement
plirof2

bash execute latest version

Dec 2nd, 2023
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. folder_path="/tmp/Internet/"
  4. prefix="ungoogled-chromium_"
  5. extension=".AppImage"
  6.  
  7. # Navigate to the specified folder
  8. cd "$folder_path" || exit
  9.  
  10. # Find files with the specified prefix and extension
  11. files=($(find . -type f -name "$prefix*$extension"))
  12.  
  13. # If no matching files are found, exit
  14. if [ ${#files[@]} -eq 0 ]; then
  15.   echo "No matching files found."
  16.   exit
  17. fi
  18.  
  19. # Extract version numbers and find the file with the highest version
  20. latest_version=""
  21. latest_file=""
  22. for file in "${files[@]}"; do
  23.   version=$(echo "$file" | grep -oP "(?<=${prefix})[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" | head -n 1)
  24.   if [ -n "$version" ]; then
  25.     echo "Detected version number: $version"
  26.     IFS='.' read -ra version_parts <<< "$version"
  27.     if [ -z "$latest_version" ] || [ "${version_parts[0]}" -gt "${latest_version_parts[0]}" ] || [ "${version_parts[1]}" -gt "${latest_version_parts[1]}" ] || [ "${version_parts[2]}" -gt "${latest_version_parts[2]}" ] || [ "${version_parts[3]}" -gt "${latest_version_parts[3]}" ]; then
  28.       latest_version="$version"
  29.       latest_version_parts=("${version_parts[@]}")
  30.       latest_file="$file"
  31.     fi
  32.   fi
  33. done
  34.  
  35.  
  36. # Execute the file with the latest version
  37. #echo "Executing the latest version: $latest_file"
  38. echo $latest_file
  39. echo $latest_version
  40.  
  41.  
  42. # Execute the file with the latest version
  43. if [ -n "$latest_file" ]; then
  44.   echo "Executing the latest version: $latest_file"
  45.   chmod +x "$latest_file"
  46.   ./"$latest_file"
  47. else
  48.   echo "No valid version number detected in any file."
  49. fi
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement