]> git.cameronkatri.com Git - apple_cmds.git/commitdiff
download.sh: Make way better
authorCameron Katri <me@cameronkatri.com>
Thu, 20 May 2021 20:16:39 +0000 (16:16 -0400)
committerCameron Katri <me@cameronkatri.com>
Thu, 20 May 2021 20:16:39 +0000 (16:16 -0400)
download.sh

index 3c3d0cca15b55c6cca564ed3c9ac2a24e36991a2..54b86a83a7febee09e1023010524e308513a0de0 100755 (executable)
@@ -1,5 +1,14 @@
 #!/bin/sh
-TEMP=$(mktemp -d)
-wget -q -P${TEMP} https://opensource.apple.com/tarballs/${1}/${1}-${2}.tar.gz
-tar xf ${TEMP}/${1}-${2}.tar.gz -C ${1} --strip-components=1
-echo "${2}" > ${1}/.apple_version
+version="$(basename $(curl -s https://opensource.apple.com/tarballs/${1}/ | \
+       pup 'table tbody tr td a:not([href="./../"]) text{}' -c | \
+       sort -V | tail -n 1) .tar.gz | \
+       rev | cut -d- -f 1 | rev)"
+if [ "$( echo -e "${version}\n$(cat ${1}/.apple_version)" | sort -V | tail -n 1)" = "$(cat ${1}/.apple_version)" ]; then
+       echo "${1} - $(cat ${1}/.apple_version)"
+else
+       echo "${1} - $(cat ${1}/.apple_version) -> ${version}"
+       TEMP=$(mktemp -d)
+       wget -q -P${TEMP} https://opensource.apple.com/tarballs/${1}/${1}-${version}.tar.gz
+       tar xf ${TEMP}/${1}-${2}.tar.gz -C ${1} --strip-components=1
+       echo "${version}" > ${1}/.apple_version
+fi