diff --git a/Makesurefile b/Makesurefile index e88c9cd..a787153 100644 --- a/Makesurefile +++ b/Makesurefile @@ -181,7 +181,10 @@ @goal README.md @private @doc 'compiles release version of README.md' - $AWK ' + $AWK -v NEXT_VERSION="$NEXT_VERSION" ' + { + gsub(/raw\.githubusercontent\.com\/xonixx\/makesure\/[^\/]+\//, "raw.githubusercontent.com/xonixx/makesure/v" NEXT_VERSION "/") + } /^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") } /^```$/ { stop=0 } !stop' README.md > README.md.1 diff --git a/README.md b/README.md index c9dced3..15a4c2b 100644 --- a/README.md +++ b/README.md @@ -76,12 +76,12 @@ Usage: makesure [options...] [-f buildfile] [goals...] Since `makesure` is a tiny utility represented by a single file, the recommended installation strategy is to keep it local to a project where it's used (this means in code repository). Not only this eliminates the need for repetitive installation for every dev on a project, but also allows using separate `makesure` version per project and update only as needed. ```sh -wget "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=$(date +%s)" -Omakesure && \ +wget "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/makesure" -Omakesure && \ chmod +x makesure && echo "makesure $(./makesure -v) installed" ``` or ```sh -curl "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=$(date +%s)" -o makesure && \ +curl "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/makesure" -o makesure && \ chmod +x makesure && echo "makesure $(./makesure -v) installed" ``` @@ -659,7 +659,7 @@ Install Bash completion for `./makesure` locally ```sh [[ ! -f ~/.bash_completion ]] && touch ~/.bash_completion grep makesure ~/.bash_completion >/dev/null || echo '. ~/.makesure_completion.bash' >> ~/.bash_completion -curl "https://raw.githubusercontent.com/xonixx/makesure/main/completion.bash?token=$(date +%s)" -o ~/.makesure_completion.bash +curl "https://raw.githubusercontent.com/xonixx/makesure/v0.9.23/completion.bash" -o ~/.makesure_completion.bash echo 'Please reopen the shell to activate completion.' ``` diff --git a/makesure.awk b/makesure.awk index 285e7b5..a6aaa0e 100755 --- a/makesure.awk +++ b/makesure.awk @@ -720,21 +720,35 @@ function currentTimeMillis( res) { return +res } -function selfUpdate( url, tmp, err, newVer) { - url = "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=" rand() +function selfUpdate( tmp, err, newVer,line,sha) { tmp = executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX") - err = dl(url, tmp) - if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp + # first get the last commit hash + err = dl("https://api.github.com/repos/xonixx/makesure/commits?per_page=1", tmp) if (!err) { - newVer = executeGetLine(tmp " -v") - if (Version != newVer) { - if (!ok("cp " tmp " " quoteArg(Prog))) - err = "can't overwrite " Prog - else print "updated " Version " -> " newVer - } else print "you have latest version " Version " installed" + while (getline line < tmp) { + if (line ~ /"sha":/) { + if (match(line = substr(line, index(line, "\"sha\":") + 6), /"[a-z0-9]+"/)) + sha = substr(line, RSTART + 1, RLENGTH - 2) + break + } + } + if (!sha) err = "unable to get the latest commit" + if (!err) { + # now download the latest executable + err = dl("https://raw.githubusercontent.com/xonixx/makesure/" sha "/makesure", tmp) + if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp + if (!err) { + newVer = executeGetLine(tmp " -v") + if (Version != newVer) { + if (!ok("cp " tmp " " quoteArg(Prog))) + err = "can't overwrite " Prog + else print "updated " Version " -> " newVer + } else print "you have latest version " Version " installed" + } + } } rm(tmp) - if (err) die(err) + if (err) die(err "\nPlease use manual update: https://makesure.dev/Installation.html") } function renderDuration(deltaMillis,\ diff --git a/tests/200_update.tush b/tests/200_update.tush index 8f01013..15d0fe7 100644 --- a/tests/200_update.tush +++ b/tests/200_update.tush @@ -13,8 +13,10 @@ $ ./$MAKESURE -f tests/200_update.sh test_wget | awk '{ sub(/[0-9][0-9.]+/,"YYY" | goal 'test_wget' ... | XXX | running wget +| running wget | updated XXX -> YYY | running wget +| running wget | you have latest version YYY installed | YYY @@ -24,7 +26,9 @@ $ ./$MAKESURE -f tests/200_update.sh test_curl | awk '{ sub(/[0-9][0-9.]+/,"YYY" | goal 'test_curl' ... | XXX | running curl +| running curl | updated XXX -> YYY | running curl +| running curl | you have latest version YYY installed | YYY