/hdtracks-downloader

https://github.com/ronalde/hdtracks-downloader · #! · 254 lines · 206 code · 48 blank · 0 comment · 0 complexity · 468848a289db0ba0a07217410a981eb9 MD5 · raw file

  1. #!/usr/bin/env bash
  2. ## script to check for the latest version of the hdtracks downloader
  3. ## for windows installation program and optionally downloads and
  4. ## installs it using wine.
  5. ## Copyright (C) 2014 Ronald van Engelen <ronalde+github@lacocina.nl>
  6. ## This program is free software: you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation, either version 3 of the License, or
  9. ## (at your option) any later version.
  10. ##
  11. ## This program is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ##
  19. ## The script, helpers and documentation are published at
  20. ## https://github.com/ronalde/hdtracks-downloader
  21. ##
  22. ## Also see `README'
  23. # earlier versions found on websites:
  24. # 19.0.116
  25. # 19.0.056
  26. # 19.0.060
  27. # 19.0.046
  28. # 18.0.159
  29. # 18.0.125
  30. # 18.0.111 (February 13, 2013)
  31. # 18.0.084 (December 05, 2012)
  32. # 18.0.076 (11/19/2012)
  33. # 18.0.072 (11/12/2012)
  34. # 18.0.068 (11/2/2012)
  35. # 18.0.067 (11/1/2012)
  36. ## user variables
  37. ## uncomment to only check for the latest version (and download nothing)
  38. #INSTALL=True
  39. ## uncomment and fill in to test a particluar version without looking
  40. ## for newer ones.
  41. #FIXED_VERSION="18.0.084"
  42. ## tried with and without native dll
  43. # 19.0.046
  44. # 18.0.159
  45. # 18.0.125
  46. # 18.0.111
  47. # 18.0.084
  48. ## use the following native dlls
  49. NATIVE_DLLS=("crypt32")
  50. # NATIVE_DLLS=("crypt32" "secur32" "winhttp" "wininet")
  51. ## check this many versions
  52. HOW_MANY_VERSIONS=${HOW_MANY_VERSIONS:-100}
  53. ## since last run (20140518)
  54. LATEST_KNOWNVERSION="${LATEST_KNOWNVERSION:-190116}"
  55. ## where to put the wine hdtracks installation
  56. HDTRACKS_DIR="${HDTRACKS_DIR:-.hdtracks}"
  57. ## indicate whether the program works in Linux
  58. IS_BROKEN=True
  59. export WINEPREFIX="${HOME}/${HDTRACKS_DIR}"
  60. ### do not alter from here
  61. JRIVER_BASEURL="http://files.jriver.com.s3.amazonaws.com/partners/hdtracks"
  62. HDTRACKS_EXE_NAME="HDtracks Downloader"
  63. ## strip . from fixed version of set
  64. [[ ! -z ${FIXED_VERSION} ]] && FIXED_VERSION="${FIXED_VERSION//./}"
  65. ONLYCHECK=True
  66. [[ ! -z ${INSTALL} || ! -z ${FIXED_VERSION} ]] && unset ONLYCHECK
  67. infourl="http://lacocina.nl/hdtracks-downloader-on-linux"
  68. if [[ ${IS_BROKEN} && -z "${FIXED_VERSION}" ]]; then
  69. printf "\nNOTICE: hdtracks downloader does not currently work in linux.
  70. See %s for more information.
  71. Use the following to try it anyway:
  72. INSTALL=True bash ${0}\n\n" "${infourl}"
  73. fi
  74. ## check for required commands and packages
  75. CMD_WINE=$(which wine || missing_packages+=("wine"))
  76. CMD_WGET=$(which wget || missing_packages+=("wget"))
  77. CMD_WINETRICKS=$(which winetricks || CMD_SVN=$(which svn || missing_packages+=("svn")))
  78. if [[ ! -z ${missing_packages} ]]; then
  79. printf "not ok, please install using:\nsudo apt-get install "
  80. IFS=' ' printf "%s " "${missing_packages[@]}"
  81. printf "\n"
  82. exit 1
  83. else
  84. printf "done.\n"
  85. fi
  86. ## check for existing wine installation
  87. if [[ -d "${WINEPREFIX}" && -z ${ONLYCHECK} ]]; then
  88. printf "directory \`%s' already exists, please (re)move it and try again.\n" \
  89. "${WINEPREFIX}" exit 1
  90. else
  91. if [[ -z ${ONLYCHECK} ]]; then
  92. printf "start installing hdtracks downloader to \`%s'.\n" "${WINEPREFIX}"
  93. ## install neccessary packages
  94. #if [[ -z ${ONLYCHECK} ]]; then
  95. declare -a missing_packages
  96. printf " - checking for neccessary packages ... "
  97. else
  98. printf "will check latest version of hdtracks downloader.\n"
  99. fi
  100. fi
  101. ## check for newer version if FIXED_VERSION isn't set.
  102. if [[ -z "${FIXED_VERSION}" ]]; then
  103. printf " - checking the hdtracks help page for their advertised version ... "
  104. ## check if that assumption is right
  105. hdtracks_baseurl="http://www.hdtracks.com"
  106. hdtracks_helppage=$(${CMD_WGET} -q -O - ${hdtracks_baseurl}/help)
  107. if [[ "$?" = "0" ]]; then
  108. filter='([a-z0-9]*/[a-z0-9]*/[a-z0-9]*/[a-z0-9]*)/([A-Za-z0-9]*\.exe)"'
  109. if [[ "${hdtracks_helppage}" =~ ${filter} ]]; then
  110. ## name of the download, like `HDtracksDownloader190060.exe`
  111. hdtracksinstaller="${BASH_REMATCH[2]}"
  112. ## extract numerical version
  113. if [[ "${hdtracksinstaller}" =~ [A-Za-z]*([0-9]*).exe ]]; then
  114. hdtracks_version="${BASH_REMATCH[1]}"
  115. printf "\`%s'" "${hdtracks_version}"
  116. fi
  117. fi
  118. if [[ ${LATEST_KNOWNVERSION} -le ${hdtracks_version} ]]; then
  119. let check_version=${hdtracks_version}
  120. printf "\n > is newer than last known version.\n"
  121. else
  122. let versionnumbers_short=$(( ${LATEST_KNOWNVERSION} - ${hdtracks_version} ))
  123. let check_version=${LATEST_KNOWNVERSION}
  124. printf "\n > is lagging %s version numbers behind latest known version.\n" "${versionnumbers_short}"
  125. fi
  126. else
  127. printf "(couldn't extract version from \`%s').\n" "${hdtracks_baseurl}/help"
  128. fi
  129. ## assume this is the latest version
  130. let highest_version=${check_version}
  131. ## start with latest version + 1
  132. let check_version=$(( ${check_version} + 1 ))
  133. ## end with latest version + HOW_MANY_VERSIONS
  134. let max_version=$(( ${check_version} + ${HOW_MANY_VERSIONS} ))
  135. printf " - checking the jriver download site for newer versions ...\n "
  136. while ((check_version < ${max_version})); do
  137. printf "."
  138. ${CMD_WGET} -q --spider ${JRIVER_BASEURL}/HDtracksDownloader${check_version}.exe
  139. if [[ "$?" = "0" ]]; then
  140. printf "\n > found version: \`%s'\n " "${check_version}"
  141. let highest_version=${check_version}
  142. fi
  143. let check_version++
  144. done
  145. jriver_url="${JRIVER_BASEURL}/HDtracksDownloader${highest_version}.exe"
  146. printf "\n * done, most recent version is "
  147. if [[ ${LATEST_KNOWNVERSION} -le ${highestversion} ]]; then
  148. printf "\`%s'.\n" "${highest_version}"
  149. else
  150. printf "\`%s'.\n" "${highest_version}"
  151. fi
  152. else
  153. ## version is fixed
  154. jriver_url="${JRIVER_BASEURL}/HDtracksDownloader${FIXED_VERSION}.exe"
  155. printf " - checking user requested fixed version \`%s' ... " "${FIXED_VERSION}"
  156. ${CMD_WGET} -q --spider "${jriver_url}"
  157. if [[ "$?" = "0" ]]; then
  158. printf "is available.\n"
  159. else
  160. printf "is unavailable.\nbailing out ...\n"
  161. exit 1
  162. fi
  163. fi
  164. if [[ -z ${ONLYCHECK} ]]; then
  165. HDTRACKS_CDRIVE="${WINEPREFIX}/drive_c"
  166. HDTRACKS_LNK="${HDTRACKS_CDRIVE}/users/Public/Start Menu/Programs/${HDTRACKS_EXE_NAME}/${HDTRACKS_EXE_NAME}.lnk"
  167. HDTRACKS_EXE_PATH="${HDTRACKS_CDRIVE}/Program Files/${HDTRACKS_EXE_NAME}/${HDTRACKS_EXE_NAME}.exe"
  168. ## put all downloads in /tmp
  169. printf " - creating directory for downloads "
  170. tmp_path="$(mktemp -d)" && \
  171. printf "in \`%s' ... done.\n" "${tmp_path}"
  172. WINETRICKS_LOG="${tmp_path}/winetricks.log"
  173. WINE_LOG="${tmp_path}/wine.log"
  174. SVN_LOG="${tmp_path}/svn.log"
  175. hdtracks_installer="${tmp_path}/hdtracksinstaller.exe"
  176. printf " - downloading installer from the jriver downloadsite to \`%s' ..." "${hdtracks_installer}"
  177. ${CMD_WGET} -q "${jriver_url}" -O "${hdtracks_installer}" && \
  178. printf "done.\n"
  179. LOGS=("")
  180. if [[ -z "${CMD_WINETRICKS}" ]]; then
  181. ## winetricks not installed; check it out using subversion
  182. winetricks_svnurl="http://winetricks.googlecode.com/svn/trunk/"
  183. winetricks_target="${tmp_path}/winetricks"
  184. CMD_WINETRICKS="${winetricks_target}/src/winetricks"
  185. printf " - checking out upstream winetricks using svn ..."
  186. ${CMD_SVN} checkout "${winetricks_svnurl}" "${winetricks_target}" &> ${SVN_LOG} && \
  187. printf "done.\n"
  188. LOGS+=("subversion (checkout for upstream winetricks): ${SVN_LOG}")
  189. fi
  190. export WINEARCH='win32'
  191. if [[ ${#NATIVE_DLLS} -gt 0 ]]; then
  192. printf " - installing native dlls %s with winetricks ..." "${NATIVE_DLLS[@]}"
  193. ${CMD_WINETRICKS} -q "${NATIVE_DLLS[@]}" &> ${WINETRICKS_LOG} && printf "done.\n"
  194. #printf " - installing secur32 with upstream winetricks ..."
  195. #${CMD_WINETRICKS} -q secur32 &> ${WINETRICKS_LOG} && printf "done.\n
  196. LOGS+=("winetricks (crypt32 installation) : ${WINETRICKS_LOG}")
  197. fi
  198. printf " - running wine in \`%s' to run the installer \`%s' ..." "${WINEPREFIX}" "${hdtracks_installer}"
  199. ${CMD_WINE} "${hdtracks_installer}" &> ${WINE_LOG} && \
  200. printf "all done!"
  201. LOGS+=("wine (windows installer) : ${WINE_LOG}")
  202. printf "The following logs are available:\n"
  203. printf " - %s\n" "${LOGS[@]}"
  204. printf "\nuse the following command to run the hdtracks downloader:\n
  205. WINEPREFIX=\"%s\" WINEARCH=\"win32\" wine \"%s\"\n" "${WINEPREFIX}" "${HDTRACKS_EXE_PATH}"
  206. fi