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

Update dlmodels.sh

Browse files
Files changed (1) hide show
  1. dlmodels.sh +12 -11
dlmodels.sh CHANGED
@@ -9,30 +9,30 @@ fi
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
- # If file already exists
18
  if [[ -f "$filepath" ]]; then
19
- # Get remote file size
20
  remote_size=$(curl -sI "$url" | awk '/Content-Length/ {print $2}' | tr -d '\r')
21
- # Get local file size
22
  local_size=$(stat -c%s "$filepath")
23
 
24
- # Check if file sizes match
25
  if [[ "$remote_size" == "$local_size" ]]; then
26
- echo "File $filepath already exists and is complete."
27
  return 0
28
  else
29
- echo "File $filepath is incomplete or corrupted, re-downloading..."
30
- rm -f "$filepath" # Remove the corrupted file
31
  fi
 
 
32
  fi
33
 
34
- # Download the file
35
- wget -c -O "$filepath" "$url"
 
36
  }
37
 
38
  # Process each line in the specified input file
@@ -41,8 +41,9 @@ cat "$INPUT_FILE" | while read -r line; do
41
  filepath=$(echo "$line" | awk '{print $1}')
42
  url=$(echo "$line" | awk '{print $2}')
43
 
44
- # Call the download function
45
  download_file "$filepath" "$url" &
46
  done
47
 
48
  wait
 
 
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
 
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."