MikaelTradera commited on
Commit
8b71bd0
·
verified ·
1 Parent(s): daf39e0

Update dlmodels.sh

Browse files
Files changed (1) hide show
  1. dlmodels.sh +25 -13
dlmodels.sh CHANGED
@@ -9,41 +9,53 @@ fi
9
  # Set the input file from the first argument
10
  INPUT_FILE="$1"
11
 
12
- # Function to download files with progress display
13
  download_file() {
14
  local filepath="$1"
15
  local url="$2"
16
 
 
 
 
 
17
  if [[ -f "$filepath" ]]; then
18
- # Check if the existing file size matches the remote size
19
  remote_size=$(curl -sI "$url" | awk '/Content-Length/ {print $2}' | tr -d '\r')
 
20
  local_size=$(stat -c%s "$filepath")
21
 
 
22
  if [[ "$remote_size" == "$local_size" ]]; then
23
- echo "[] File already exists and is complete: $filepath"
24
  return 0
25
  else
26
- echo "[] File exists but is incomplete, re-downloading: $filepath"
27
- rm -f "$filepath"
28
  fi
29
  else
30
- echo "[] Starting download: $filepath"
31
  fi
32
 
33
- # Use wget with a progress bar for clean output
34
- wget -c --progress=bar:force:noscroll -O "$filepath" "$url" 2>&1 | \
35
- sed -u -e "s/^/[→] Downloading $filepath: /"
 
 
 
 
 
36
  }
37
 
38
  # Process each line in the specified input file
39
- cat "$INPUT_FILE" | while read -r line; do
40
  # Split each line into filepath and URL
41
  filepath=$(echo "$line" | awk '{print $1}')
42
  url=$(echo "$line" | awk '{print $2}')
43
 
44
- # Download the file
45
  download_file "$filepath" "$url" &
46
- done
47
 
 
48
  wait
49
- echo "[✔] All downloads completed."
 
9
  # Set the input file from the first argument
10
  INPUT_FILE="$1"
11
 
12
+ # Function to check file existence and download integrity
13
  download_file() {
14
  local filepath="$1"
15
  local url="$2"
16
 
17
+ # Display progress message
18
+ echo -e "\nChecking file: $filepath"
19
+
20
+ # If file already exists
21
  if [[ -f "$filepath" ]]; then
22
+ # Get remote file size
23
  remote_size=$(curl -sI "$url" | awk '/Content-Length/ {print $2}' | tr -d '\r')
24
+ # Get local file size
25
  local_size=$(stat -c%s "$filepath")
26
 
27
+ # Check if file sizes match
28
  if [[ "$remote_size" == "$local_size" ]]; then
29
+ echo -e "[SKIP] $filepath already exists and is complete."
30
  return 0
31
  else
32
+ echo -e "[RE-DOWNLOAD] $filepath is incomplete or corrupted, re-downloading..."
33
+ rm -f "$filepath" # Remove the corrupted file
34
  fi
35
  else
36
+ echo -e "[DOWNLOAD] Starting download of $filepath"
37
  fi
38
 
39
+ # Download the file with wget
40
+ wget -c --progress=dot -O "$filepath" "$url" 2>&1 | \
41
+ grep --line-buffered "%" | \
42
+ sed -u -e "s,\.,,g" | \
43
+ awk '{printf("\r[DOWNLOADING] %s - %s", "'$filepath'", $2)}'
44
+
45
+ # Confirm completion
46
+ echo -e "\n[COMPLETE] Downloaded $filepath"
47
  }
48
 
49
  # Process each line in the specified input file
50
+ while IFS= read -r line; do
51
  # Split each line into filepath and URL
52
  filepath=$(echo "$line" | awk '{print $1}')
53
  url=$(echo "$line" | awk '{print $2}')
54
 
55
+ # Call the download function
56
  download_file "$filepath" "$url" &
57
+ done < "$INPUT_FILE"
58
 
59
+ # Wait for all background jobs to finish
60
  wait
61
+ echo -e "\nAll downloads are completed."