Skip to content

Commit

Permalink
update fn_bootstrap_fetch_file
Browse files Browse the repository at this point in the history
  • Loading branch information
dgibbs64 committed Sep 29, 2024
1 parent 058f63d commit 2700fa6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions lgsm/modules/core_dl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ fn_fetch_file() {
counter=1
remote_fileurls_array=(remote_fileurl)
fi

for remote_fileurl_array in "${remote_fileurls_array[@]}"; do
if [ "${remote_fileurl_array}" == "remote_fileurl" ]; then
fileurl="${remote_fileurl}"
Expand Down
2 changes: 1 addition & 1 deletion lgsm/modules/install_server_dir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ if [ -z "${autoinstall}" ]; then
fi
fi
if [ ! -d "${serverfiles}" ]; then
mkdir -v "${serverfiles}"
mkdir "${serverfiles}"
fi
41 changes: 26 additions & 15 deletions linuxgsm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ fn_bootstrap_fetch_file() {
chmodx="${7:-0}"
run="${8:-0}"
forcedl="${9:-0}"
md5="${10:-0}"
hash="${10:-0}"

# Download file if missing or download forced.
if [ ! -f "${local_filedir}/${local_filename}" ] || [ "${forcedl}" == "forcedl" ]; then
# If backup fileurl exists include it.
Expand Down Expand Up @@ -108,43 +109,53 @@ fn_bootstrap_fetch_file() {
fi
# Trap will remove part downloaded files if canceled.
trap fn_fetch_trap INT
# Larger files show a progress bar.

echo -en "fetching ${fileurl_name} [ ${local_filename} ]\c"
curlcmd=$(curl --connect-timeout 3 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)

local exitcode=$?
curlcmd=(curl --connect-timeout 3 --fail -L -o "${local_filedir}/${local_filename}" --retry 2 -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randomint}.212 Safari/537.36")

# if is large file show progress, else be silent
local exitcode=""
large_files=("bz2" "gz" "zip" "jar" "xz")
if grep -qE "(^|\s)${local_filename##*.}(\s|$)" <<< "${large_files[@]}"; then
echo -e "downloading file [ ${local_filename} ]"
fn_sleep_time
"${curlcmd[@]}" --progress-bar "${fileurl}" 2>&1
exitcode="$?"
echo -en "downloading file [ ${local_filename} ]"
else
echo -en "fetching ${fileurl_name} [ ${local_filename} ]\c"
"${curlcmd[@]}" --silent --show-error "${fileurl}" 2>&1
exitcode="$?"
fi

# Download will fail if downloads a html file.
if [ -f "${local_filedir}/${local_filename}" ]; then
if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
rm -f "${local_filedir:?}/${local_filename:?}"
if head -n 1 "${local_filedir}/${local_filename}" | grep -q "DOCTYPE"; then
rm "${local_filedir:?}/${local_filename:?}"
local exitcode=2
fi
fi

# On first try will error. On second try will fail.
if [ "${exitcode}" != 0 ]; then
if [ ${counter} -ge 2 ]; then
echo -e "FAIL"
echo -e " ... FAIL"
if [ -f "${lgsmlog}" ]; then
fn_script_log_fail "Downloading ${local_filename}"
fn_script_log_fail "Downloading ${local_filename}..."
fn_script_log_fail "${fileurl}"
fi
core_exit.sh
else
echo -e "ERROR"
echo -e " ... ERROR"
if [ -f "${lgsmlog}" ]; then
fn_script_log_error "Downloading ${local_filename}"
fn_script_log_error "Downloading ${local_filename}..."
fn_script_log_error "${fileurl}"
fi
fi
else
echo -en "OK"
echo -en " ... OK"
sleep 0.3
echo -en "\033[2K\\r"
if [ -f "${lgsmlog}" ]; then
fn_script_log_pass "Downloading ${local_filename}"
fn_script_log_pass "Downloading ${local_filename}..."
fi

# Make file executable if chmodx is set.
Expand Down

0 comments on commit 2700fa6

Please sign in to comment.