Skip to content

Commit

Permalink
Switch autoscripts to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
vanosg committed Jan 18, 2024
1 parent 9fc0ae9 commit 8751ce5
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions scripts/autoscripts.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ proc send_http {url type} {
catch {set req [http::geturl $url -binary 1 -channel $fs]} error
close $fs
} else {
catch {set req [http::geturl $url -timeout 10000]} error
catch {set req [http::geturl $url -headers [dict create "User-Agent" "Mozilla/5.0"] -timeout 10000]} error
}
set status [http::status $req]
if {$status != "ok"} {
Expand Down Expand Up @@ -334,14 +334,18 @@ proc egg_set {idx script setting value} {
# For future eggheads- 100 is the maximum WP supports without doing pagination
proc egg_remote {idx} {
global cmdtxt
global eggdir
putdcc $idx "* Retrieving script list, please wait..."
set jsondata [send_http "https://www.eggheads.org/wp-json/wp/v2/media?mime_type=application\/x-gzip&orderby=slug&per_page=100&order=asc" 0]
send_http "https://raw.githubusercontent.com/eggheads/autoscripts/master/manifest" 1
set fp [open $eggdir/manifest r]
set jsondata [read $fp]
close $fp
set datadict [json::json2dict $jsondata]
putdcc $idx "Scripts available for download:"
putdcc $idx "-------------------------------"
foreach scriptentry $datadict {
regsub -all {<[^>]+>} [dict get $scriptentry caption rendered] "" scriptcap
putdcc $idx "* [format "%-16s %s" [dict get $scriptentry slug] [string trim $scriptcap "\n"]]"
# regsub -all {<[^>]+>} [dict get $scriptentry caption rendered] "" scriptcap
putdcc $idx "* [format "%-16s %s" [dict get $scriptentry name] [dict get $scriptentry description]]"
}
putdcc $idx "\n"
putdcc $idx "* Type 'fetch <scriptname>' to download a script"
Expand Down Expand Up @@ -369,15 +373,14 @@ proc egg_update {idx tgtscript} {
set found 0

readjsonfile
set jsondata [send_http "https://www.eggheads.org/wp-json/wp/v2/media?mime_type=application\/x-gzip&orderby=slug&per_page=100&order=asc" 0]
set jsondata [send_http "https://www.eggheads.org/wp-content/uploads/2023/05/asman.json" 0]
set jsondata [send_http "https://raw.githubusercontent.com/eggheads/autoscripts/master/manifest" 0]
set datadict [json::json2dict $jsondata]
foreach localscript $jsondict {
foreach remotescript $datadict {
if {[string equal -nocase [dict get $remotescript name] [dict get $localscript name]]} {
if { ([dict get $remotescript minor] > [dict get $localscript version_minor] &&
[dict get $remotescript major] >= [dict get $localscript version_major]) ||
([dict get $remotescript major] > [dict get $localscript version_major]) } {
if { ([dict get $remotescript version_minor] > [dict get $localscript version_minor] &&
[dict get $remotescript version_major] >= [dict get $localscript version_major]) ||
([dict get $remotescript version_major] > [dict get $localscript version_major]) } {
## If we're looking for a specific script, suppress other found messages
if {[string equal -nocase $tgtscript ""]} {
putdcc $idx "* [dict get $localscript name] has an update available."
Expand Down Expand Up @@ -452,24 +455,28 @@ proc egg_fetch {idx script} {
putidx $idx "$cmdtxt"
return
}
### CHECK IF IT IS ON SITE FIRST
putdcc $idx "* Downloading, please wait..."
set jsondata [send_http "https://www.eggheads.org/wp-json/wp/v2/media?mime_type=application\/x-gzip" 0]
set jsondata [send_http "https://api.github.com/repos/eggheads/autoscripts/contents/packages" 0]
set datadict [json::json2dict $jsondata]
foreach scriptentry $datadict {
if {[string match $script [dict get $scriptentry slug]]} {
send_http [dict get $scriptentry source_url] 1
file mkdir $eggdir/[dict get $scriptentry slug]
exec tar -zxf $eggdir/[dict get $scriptentry slug].tgz -C $eggdir/[dict get $scriptentry slug]
file delete $eggdir/[dict get $scriptentry slug].tgz
putdcc $idx "* [dict get $scriptentry slug] downloaded."
putdcc $idx "* Use 'config [dict get $scriptentry slug]' to configure and then 'load [dict get $scriptentry slug]' to load."
putidx $idx "$cmdtxt"
readjsonfile
if {[string match ${script}.tgz [dict get $scriptentry name]]} {
send_http "[dict get $scriptentry download_url]" 1
putdcc $idx "* [dict get $scriptentry name] downloaded."
exec tar -zxf $eggdir/[dict get $scriptentry name] -C $eggdir
if {[file exists $eggdir/$script]} {
file delete $eggdir/[dict get $scriptentry name]
putdcc $idx "* [dict get $scriptentry name] extracted."
putdcc $idx "* Use 'config $script' to configure and then 'load $script' to load."
putidx $idx "$cmdtxt"
readjsonfile
} else {
putdcc $idx "* ERROR: [dict get $scriptentry name] not found. Cannot continue."
}
}
}
}


proc egg_clean {idx script} {
global cmdtxt
global eggdir
Expand Down

0 comments on commit 8751ce5

Please sign in to comment.