~krathalan/miscellaneous-scripts

4865e2ebed1f86f50ba87c13cad49480d68e07b4 — Hunter Peavey 5 years ago 0582bd1 wow_async
Update update_wow_addons to update addons asynchronously
1 files changed, 36 insertions(+), 11 deletions(-)

M update_wow_addons
M update_wow_addons => update_wow_addons +36 -11
@@ 71,6 71,23 @@ readonly PATH_TO_WOW_ADDONS="${PATH_TO_WOW}/drive_c/Program Files (x86)/World of
# -----------------------------------------

#######################################
# Downloads the specified addon.
# Globals:
#   RED, NC
#   SCRIPT_NAME
# Arguments:
#   $1: addon to download
# Returns:
#   none
#######################################
download_addon()
{
  local -r downloadURL="$(get_download_url "${addon}")"

  wget -q --directory-prefix="${TMP_DIR_DOWNLOAD}" "${CURSE_URL}${downloadURL}"
}

#######################################
# Prints passed error message before premature exit.
# Prints everything to >&2 (STDERR).
# Globals:


@@ 115,28 132,38 @@ if [[ "$(whoami)" = "root" ]]; then
  exit_script_on_failure "This script should NOT be run as root (or sudo)!"
fi

# Print addons
printf "Downloading addons from https://www.curseforge.com/:"

for addon in "${ADDONS[@]}"; do
  printf " %s" "${addon}"
done

if [[ "${INCLUDE_ELVUI}" == "true" ]]; then
  printf "\n\nAlso downloading ElvUI from https://www.tukui.org/"
fi

printf "\n"

# Step 1
printf "\n%s==> Downloading addons to temporary folder…%s\n" "${GREEN}" "${NC}"

downloadURL=""
for addon in "${ADDONS[@]}"; do
  printf "Downloading %s" "${addon}"
  downloadURL="$(get_download_url "${addon}")"

  wget -q --show-progress --directory-prefix="${TMP_DIR_DOWNLOAD}" "${CURSE_URL}${downloadURL}"
  download_addon "addon" &
done

if [[ "${INCLUDE_ELVUI}" == "true" ]]; then
  printf "Downloading ElvUI"
wait

if [[ "${INCLUDE_ELVUI}" == "true" ]]; then
  # Extract download URL for latest version
  pageHTML="$(wget -qO- --show-progress "${ELVUI_URL}/download.php?ui=elvui")"
  pageHTML="$(wget -qO- "${ELVUI_URL}/download.php?ui=elvui")"
  pageHTML=$(grep -i "zip" <<< "${pageHTML}" | awk '{printf $2}')
  pageHTML=${pageHTML//\"}
  pageHTML=${pageHTML//href=}

  # Download ElvUI
  wget -q --show-progress --directory-prefix="${TMP_DIR_DOWNLOAD}" "${ELVUI_URL}${pageHTML}"
  wget -q --directory-prefix="${TMP_DIR_DOWNLOAD}" "${ELVUI_URL}${pageHTML}"
fi

wait


@@ 145,9 172,7 @@ wait
printf "Done.\n\n%s==> Safely unzipping to temporary folder…%s\n" "${GREEN}" "${NC}"

for addonFile in "${TMP_DIR_DOWNLOAD}"/*; do
  printf "Unzipping %s…\n" "$(basename "${addonFile}")"

  unzip "${addonFile}" -d "${TMP_DIR_EXTRACT}" > /dev/null 
  unzip "${addonFile}" -d "${TMP_DIR_EXTRACT}" > /dev/null &
done

wait