Advertisement
MaxDjently

update_dependencies-wsl.sh

Mar 27th, 2025 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.50 KB | Software | 0 0
  1. # List of dependencies
  2. dependencies=("yt-dlp" "jq")
  3.  
  4. # Temporary file to store timestamps
  5. timestamp_file="dependency_timestamps.txt"
  6.  
  7. # Function to check and install dependencies
  8. check_and_install() {
  9.     for dep in "${dependencies[@]}"; do
  10.         if ! command -v $dep &> /dev/null; then
  11.             echo "$dep is not installed. Installing..."
  12.             if [ "$dep" == "yt-dlp" ]; then
  13.                 sudo apt install yt-dlp -y
  14.             elif [ "$dep" == "jq" ]; then
  15.                 sudo apt install jq -y
  16.             fi
  17.         else
  18.             echo "$dep is already installed."
  19.         fi
  20.     done
  21. }
  22.  
  23. # Function to update dependencies
  24. update_dependencies() {
  25.     echo "Updating Dependencies..."
  26.     sudo apt update && sudo apt upgrade -y
  27. }
  28.  
  29. # Check if the timestamp file exists
  30. if [ ! -f "$timestamp_file" ]; then
  31.     echo "Timestamp file not found. Creating..."
  32.     touch "$timestamp_file"
  33.     date +%s > "$timestamp_file"
  34.     update_dependencies
  35.     check_and_install
  36. else
  37.     last_update=$(cat "$timestamp_file")
  38.     current_time=$(date +%s)
  39.     time_diff=$((current_time - last_update))
  40.     # Update dependencies if more than a week has passed (604800 seconds)
  41.     if [ $time_diff -gt 604800 ]; then
  42.         update_dependencies
  43.         check_and_install
  44.         date +%s > "$timestamp_file"
  45.     else
  46.         echo "Dependencies were updated recently. No need to update now."
  47.     fi
  48. fi
  49.  
  50. # Check and install dependencies
  51.  
  52.  
  53. echo "Dependency check and update process completed!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement