/hdtracks-downloader
https://github.com/ronalde/hdtracks-downloader · #! · 254 lines · 206 code · 48 blank · 0 comment · 0 complexity · 468848a289db0ba0a07217410a981eb9 MD5 · raw file
- #!/usr/bin/env bash
- ## script to check for the latest version of the hdtracks downloader
- ## for windows installation program and optionally downloads and
- ## installs it using wine.
- ## Copyright (C) 2014 Ronald van Engelen <ronalde+github@lacocina.nl>
- ## This program is free software: you can redistribute it and/or modify
- ## it under the terms of the GNU General Public License as published by
- ## the Free Software Foundation, either version 3 of the License, or
- ## (at your option) any later version.
- ##
- ## This program is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ##
- ## You should have received a copy of the GNU General Public License
- ## along with this program. If not, see <http://www.gnu.org/licenses/>.
- ##
- ## The script, helpers and documentation are published at
- ## https://github.com/ronalde/hdtracks-downloader
- ##
- ## Also see `README'
- # earlier versions found on websites:
- # 19.0.116
- # 19.0.056
- # 19.0.060
- # 19.0.046
- # 18.0.159
- # 18.0.125
- # 18.0.111 (February 13, 2013)
- # 18.0.084 (December 05, 2012)
- # 18.0.076 (11/19/2012)
- # 18.0.072 (11/12/2012)
- # 18.0.068 (11/2/2012)
- # 18.0.067 (11/1/2012)
- ## user variables
- ## uncomment to only check for the latest version (and download nothing)
- #INSTALL=True
- ## uncomment and fill in to test a particluar version without looking
- ## for newer ones.
- #FIXED_VERSION="18.0.084"
- ## tried with and without native dll
- # 19.0.046
- # 18.0.159
- # 18.0.125
- # 18.0.111
- # 18.0.084
- ## use the following native dlls
- NATIVE_DLLS=("crypt32")
- # NATIVE_DLLS=("crypt32" "secur32" "winhttp" "wininet")
- ## check this many versions
- HOW_MANY_VERSIONS=${HOW_MANY_VERSIONS:-100}
- ## since last run (20140518)
- LATEST_KNOWNVERSION="${LATEST_KNOWNVERSION:-190116}"
- ## where to put the wine hdtracks installation
- HDTRACKS_DIR="${HDTRACKS_DIR:-.hdtracks}"
- ## indicate whether the program works in Linux
- IS_BROKEN=True
- export WINEPREFIX="${HOME}/${HDTRACKS_DIR}"
- ### do not alter from here
- JRIVER_BASEURL="http://files.jriver.com.s3.amazonaws.com/partners/hdtracks"
- HDTRACKS_EXE_NAME="HDtracks Downloader"
- ## strip . from fixed version of set
- [[ ! -z ${FIXED_VERSION} ]] && FIXED_VERSION="${FIXED_VERSION//./}"
- ONLYCHECK=True
- [[ ! -z ${INSTALL} || ! -z ${FIXED_VERSION} ]] && unset ONLYCHECK
- infourl="http://lacocina.nl/hdtracks-downloader-on-linux"
- if [[ ${IS_BROKEN} && -z "${FIXED_VERSION}" ]]; then
- printf "\nNOTICE: hdtracks downloader does not currently work in linux.
- See %s for more information.
- Use the following to try it anyway:
- INSTALL=True bash ${0}\n\n" "${infourl}"
- fi
- ## check for required commands and packages
- CMD_WINE=$(which wine || missing_packages+=("wine"))
- CMD_WGET=$(which wget || missing_packages+=("wget"))
- CMD_WINETRICKS=$(which winetricks || CMD_SVN=$(which svn || missing_packages+=("svn")))
- if [[ ! -z ${missing_packages} ]]; then
- printf "not ok, please install using:\nsudo apt-get install "
- IFS=' ' printf "%s " "${missing_packages[@]}"
- printf "\n"
- exit 1
- else
- printf "done.\n"
- fi
- ## check for existing wine installation
- if [[ -d "${WINEPREFIX}" && -z ${ONLYCHECK} ]]; then
- printf "directory \`%s' already exists, please (re)move it and try again.\n" \
- "${WINEPREFIX}" exit 1
- else
- if [[ -z ${ONLYCHECK} ]]; then
- printf "start installing hdtracks downloader to \`%s'.\n" "${WINEPREFIX}"
-
- ## install neccessary packages
- #if [[ -z ${ONLYCHECK} ]]; then
- declare -a missing_packages
- printf " - checking for neccessary packages ... "
- else
- printf "will check latest version of hdtracks downloader.\n"
- fi
- fi
- ## check for newer version if FIXED_VERSION isn't set.
- if [[ -z "${FIXED_VERSION}" ]]; then
- printf " - checking the hdtracks help page for their advertised version ... "
- ## check if that assumption is right
- hdtracks_baseurl="http://www.hdtracks.com"
- hdtracks_helppage=$(${CMD_WGET} -q -O - ${hdtracks_baseurl}/help)
-
- if [[ "$?" = "0" ]]; then
-
- filter='([a-z0-9]*/[a-z0-9]*/[a-z0-9]*/[a-z0-9]*)/([A-Za-z0-9]*\.exe)"'
-
- if [[ "${hdtracks_helppage}" =~ ${filter} ]]; then
- ## name of the download, like `HDtracksDownloader190060.exe`
- hdtracksinstaller="${BASH_REMATCH[2]}"
-
- ## extract numerical version
- if [[ "${hdtracksinstaller}" =~ [A-Za-z]*([0-9]*).exe ]]; then
- hdtracks_version="${BASH_REMATCH[1]}"
- printf "\`%s'" "${hdtracks_version}"
- fi
- fi
-
- if [[ ${LATEST_KNOWNVERSION} -le ${hdtracks_version} ]]; then
- let check_version=${hdtracks_version}
- printf "\n > is newer than last known version.\n"
- else
- let versionnumbers_short=$(( ${LATEST_KNOWNVERSION} - ${hdtracks_version} ))
- let check_version=${LATEST_KNOWNVERSION}
- printf "\n > is lagging %s version numbers behind latest known version.\n" "${versionnumbers_short}"
- fi
-
- else
- printf "(couldn't extract version from \`%s').\n" "${hdtracks_baseurl}/help"
- fi
-
- ## assume this is the latest version
- let highest_version=${check_version}
-
- ## start with latest version + 1
- let check_version=$(( ${check_version} + 1 ))
- ## end with latest version + HOW_MANY_VERSIONS
- let max_version=$(( ${check_version} + ${HOW_MANY_VERSIONS} ))
-
- printf " - checking the jriver download site for newer versions ...\n "
-
- while ((check_version < ${max_version})); do
- printf "."
- ${CMD_WGET} -q --spider ${JRIVER_BASEURL}/HDtracksDownloader${check_version}.exe
- if [[ "$?" = "0" ]]; then
- printf "\n > found version: \`%s'\n " "${check_version}"
- let highest_version=${check_version}
- fi
- let check_version++
- done
-
- jriver_url="${JRIVER_BASEURL}/HDtracksDownloader${highest_version}.exe"
- printf "\n * done, most recent version is "
- if [[ ${LATEST_KNOWNVERSION} -le ${highestversion} ]]; then
- printf "\`%s'.\n" "${highest_version}"
- else
- printf "\`%s'.\n" "${highest_version}"
- fi
- else
- ## version is fixed
- jriver_url="${JRIVER_BASEURL}/HDtracksDownloader${FIXED_VERSION}.exe"
- printf " - checking user requested fixed version \`%s' ... " "${FIXED_VERSION}"
- ${CMD_WGET} -q --spider "${jriver_url}"
- if [[ "$?" = "0" ]]; then
- printf "is available.\n"
- else
- printf "is unavailable.\nbailing out ...\n"
- exit 1
- fi
- fi
-
- if [[ -z ${ONLYCHECK} ]]; then
- HDTRACKS_CDRIVE="${WINEPREFIX}/drive_c"
- HDTRACKS_LNK="${HDTRACKS_CDRIVE}/users/Public/Start Menu/Programs/${HDTRACKS_EXE_NAME}/${HDTRACKS_EXE_NAME}.lnk"
- HDTRACKS_EXE_PATH="${HDTRACKS_CDRIVE}/Program Files/${HDTRACKS_EXE_NAME}/${HDTRACKS_EXE_NAME}.exe"
- ## put all downloads in /tmp
- printf " - creating directory for downloads "
- tmp_path="$(mktemp -d)" && \
- printf "in \`%s' ... done.\n" "${tmp_path}"
- WINETRICKS_LOG="${tmp_path}/winetricks.log"
- WINE_LOG="${tmp_path}/wine.log"
- SVN_LOG="${tmp_path}/svn.log"
- hdtracks_installer="${tmp_path}/hdtracksinstaller.exe"
- printf " - downloading installer from the jriver downloadsite to \`%s' ..." "${hdtracks_installer}"
-
- ${CMD_WGET} -q "${jriver_url}" -O "${hdtracks_installer}" && \
- printf "done.\n"
- LOGS=("")
-
- if [[ -z "${CMD_WINETRICKS}" ]]; then
- ## winetricks not installed; check it out using subversion
- winetricks_svnurl="http://winetricks.googlecode.com/svn/trunk/"
- winetricks_target="${tmp_path}/winetricks"
- CMD_WINETRICKS="${winetricks_target}/src/winetricks"
- printf " - checking out upstream winetricks using svn ..."
- ${CMD_SVN} checkout "${winetricks_svnurl}" "${winetricks_target}" &> ${SVN_LOG} && \
- printf "done.\n"
- LOGS+=("subversion (checkout for upstream winetricks): ${SVN_LOG}")
- fi
- export WINEARCH='win32'
- if [[ ${#NATIVE_DLLS} -gt 0 ]]; then
- printf " - installing native dlls %s with winetricks ..." "${NATIVE_DLLS[@]}"
- ${CMD_WINETRICKS} -q "${NATIVE_DLLS[@]}" &> ${WINETRICKS_LOG} && printf "done.\n"
- #printf " - installing secur32 with upstream winetricks ..."
- #${CMD_WINETRICKS} -q secur32 &> ${WINETRICKS_LOG} && printf "done.\n
- LOGS+=("winetricks (crypt32 installation) : ${WINETRICKS_LOG}")
- fi
- printf " - running wine in \`%s' to run the installer \`%s' ..." "${WINEPREFIX}" "${hdtracks_installer}"
- ${CMD_WINE} "${hdtracks_installer}" &> ${WINE_LOG} && \
- printf "all done!"
- LOGS+=("wine (windows installer) : ${WINE_LOG}")
- printf "The following logs are available:\n"
- printf " - %s\n" "${LOGS[@]}"
- printf "\nuse the following command to run the hdtracks downloader:\n
- WINEPREFIX=\"%s\" WINEARCH=\"win32\" wine \"%s\"\n" "${WINEPREFIX}" "${HDTRACKS_EXE_PATH}"
- fi