Created
January 24, 2019 03:18
-
-
Save yujiorama/c3c37643ac41139380619324e01d1301 to your computer and use it in GitHub Desktop.
lombok.jar や plantuml.jar を更新する bash script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # download_new_file__ | |
| # require date, stat, curl or http | |
| # | |
| download_new_file__() | |
| { | |
| local src=$1 | |
| local dst=$2 | |
| if [[ -e ${dst} ]]; then | |
| ctime_=$( | |
| LANG=C date --utc --date=@"$(stat --format='%Y' ${dst})" +"%a, %d %b %Y %H:%M:%S GMT" | |
| ) | |
| else | |
| ctime_=$( | |
| LANG=C date --utc --date="10 years ago" +"%a, %d %b %Y %H:%M:%S GMT" | |
| ) | |
| fi | |
| if which curl >/dev/null 2>&1; then | |
| modified_=$( | |
| curl -fsSL -I -H "If-Modified-Since: ${ctime_}" -o /dev/null -w %{http_code} ${src} | |
| ) | |
| if [[ "200" = "${modified_}" ]]; then | |
| curl -fsSL --output ${dst} ${src} >/dev/null 2>&1 | |
| fi | |
| elif which http >/dev/null 2>&1; then | |
| http --follow --continue --download --output ${dst} ${src} >/dev/null 2>&1 | |
| fi | |
| ls -l ${dst} | |
| } | |
| # Example | |
| ## lombok.jar | |
| mkdir -p ${HOME}/.lombok | |
| download_new_file__ "https://projectlombok.org/downloads/lombok.jar" "${HOME}/.lombok/lombok.jar" | |
| ## plantuml.jar | |
| mkdir -p ${HOME}/.plantuml | |
| download_new_file__ "http://sourceforge.net/projects/plantuml/files/plantuml.jar/download" "${HOME}/.plantuml/plantuml.jar" | |
| ## pleiades.jar (in pleiades.zip) | |
| mkdir -p ${HOME}/.pleiades | |
| download_new_file__ "http://ftp.jaist.ac.jp/pub/mergedoc/pleiades/build/stable/pleiades.zip" "${HOME}/.pleiades/pleiades.zip" | |
| if [[ -e "${HOME}/.pleiades/pleiades.zip" ]]; then | |
| workdir_=$(mktemp --directory --tmpdir=${HOME}/.pleiades) | |
| unzip -q -d ${workdir_} "${HOME}/.pleiades/pleiades.zip" | |
| if [[ -e "${workdir_}/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar" ]]; then | |
| src_="${workdir_}/plugins/jp.sourceforge.mergedoc.pleiades/pleiades.jar" | |
| dst_="${HOME}/.pleiades/pleiades.jar" | |
| if [[ "${src_}" -nt "${dst_}" ]]; then | |
| cp "${src_}" "${dst_}" | |
| fi | |
| unset src_ dst_ | |
| fi | |
| rm -rf "${workdir_}" | |
| unset workdir_ | |
| ls -l "${HOME}/.pleiades/pleiades.jar" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment