Skip to content

Commit

Permalink
selfupdate is broken #174 : switch to releases strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Dec 12, 2024
1 parent 01b1518 commit ab176c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
13 changes: 6 additions & 7 deletions makesure
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,17 @@ function currentTimeMillis(res){
res=executeGetLine("date +%s%3N")
sub(/%?3N/,"000",res)
return +res}
function selfUpdate(tmp,err,newVer,line,sha){
function selfUpdate(tmp,err,newVer,line,ver){
tmp=executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
err=dl("https://api.github.com/repos/xonixx/makesure/commits?per_page=1",tmp)
err=dl("https://github.com/xonixx/makesure/releases",tmp)
if(!err){
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)
if(match(line,/\/xonixx\/makesure\/releases\/tag\/v[0-9.]+/)){
ver=substr(line=substr(line,RSTART,RLENGTH),index(line,"/v")+1)
break}}
if(!sha)err="unable to get the latest commit"
if(!ver)err="unable to get the latest release"
if(!err){
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"sha"/makesure",tmp)
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"ver"/makesure",tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
if(!err){
newVer=executeGetLine(tmp" -v")
Expand Down
15 changes: 7 additions & 8 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -720,22 +720,21 @@ function currentTimeMillis( res) {
return +res
}

function selfUpdate( tmp, err, newVer,line,sha) {
function selfUpdate( tmp, err, newVer,line,ver) {
tmp = executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
# first get the last commit hash
err = dl("https://api.github.com/repos/xonixx/makesure/commits?per_page=1", tmp)
# first get the last release version
err = dl("https://github.com/xonixx/makesure/releases", tmp)
if (!err) {
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)
if (match(line, /\/xonixx\/makesure\/releases\/tag\/v[0-9.]+/)) {
ver = substr(line = substr(line, RSTART, RLENGTH), index(line, "/v") + 1) # v0.9.23
break
}
}
if (!sha) err = "unable to get the latest commit"
if (!ver) err = "unable to get the latest release"
if (!err) {
# now download the latest executable
err = dl("https://raw.githubusercontent.com/xonixx/makesure/" sha "/makesure", tmp)
err = dl("https://raw.githubusercontent.com/xonixx/makesure/" ver "/makesure", tmp)
if (!err && !ok("chmod +x " tmp)) err = "can't chmod +x " tmp
if (!err) {
newVer = executeGetLine(tmp " -v")
Expand Down
13 changes: 6 additions & 7 deletions makesure_candidate
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,17 @@ function currentTimeMillis(res){
res=executeGetLine("date +%s%3N")
sub(/%?3N/,"000",res)
return +res}
function selfUpdate(tmp,err,newVer,line,sha){
function selfUpdate(tmp,err,newVer,line,ver){
tmp=executeGetLine("mktemp /tmp/makesure_new.XXXXXXXXXX")
err=dl("https://api.github.com/repos/xonixx/makesure/commits?per_page=1",tmp)
err=dl("https://github.com/xonixx/makesure/releases",tmp)
if(!err){
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)
if(match(line,/\/xonixx\/makesure\/releases\/tag\/v[0-9.]+/)){
ver=substr(line=substr(line,RSTART,RLENGTH),index(line,"/v")+1)
break}}
if(!sha)err="unable to get the latest commit"
if(!ver)err="unable to get the latest release"
if(!err){
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"sha"/makesure",tmp)
err=dl("https://raw.githubusercontent.com/xonixx/makesure/"ver"/makesure",tmp)
if(!err&&!ok("chmod +x "tmp))err="can'\''t chmod +x "tmp
if(!err){
newVer=executeGetLine(tmp" -v")
Expand Down

0 comments on commit ab176c6

Please sign in to comment.