Skip to content

Commit 8c645e3

Browse files
committed
selfupdate is broken #174
1 parent f7a42e1 commit 8c645e3

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

‎makesure.awk‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -720,18 +720,32 @@ function currentTimeMillis( res) {
720720
return +res
721721
}
722722

723-
function selfUpdate( url, tmp, err, newVer) {
724-
url = "https://raw.githubusercontent.com/xonixx/makesure/main/makesure?token=" rand()
723+
function selfUpdate( tmp, err, newVer,line,sha) {
725724
tmp = executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
726-
err = dl(url, tmp)
727-
if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp
725+
# first get the last commit hash
726+
err = dl("https://api.github.com/repos/xonixx/makesure/commits?per_page=1", tmp)
728727
if (!err) {
729-
newVer = executeGetLine(tmp " -v")
730-
if (Version != newVer) {
731-
if (!ok("cp " tmp " " quoteArg(Prog)))
732-
err = "can't overwrite " Prog
733-
else print "updated " Version " -> " newVer
734-
} else print "you have latest version " Version " installed"
728+
while (getline line < tmp) {
729+
if (line ~ /"sha":/) {
730+
if (match(line = substr(line, index(line, "\"sha\":") + 6), /"[a-z0-9]+"/))
731+
sha = substr(line, RSTART + 1, RLENGTH - 2)
732+
if (!sha) err = "unable to get the latest commit"
733+
break
734+
}
735+
}
736+
if (!err) {
737+
# now download the latest executable
738+
err = dl("https://raw.githubusercontent.com/xonixx/makesure/" sha "/makesure", tmp)
739+
if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp
740+
if (!err) {
741+
newVer = executeGetLine(tmp " -v")
742+
if (Version != newVer) {
743+
if (!ok("cp " tmp " " quoteArg(Prog)))
744+
err = "can't overwrite " Prog
745+
else print "updated " Version " -> " newVer
746+
} else print "you have latest version " Version " installed"
747+
}
748+
}
735749
}
736750
rm(tmp)
737751
if (err) die(err)

0 commit comments

Comments
 (0)