factorio-init icon indicating copy to clipboard operation
factorio-init copied to clipboard

Fix for Bisa/factorio-init#194: Use factorio api for latest-releases

Open Legrems opened this issue 2 years ago • 7 comments

Legrems avatar Apr 09 '22 23:04 Legrems

use grep + awk or just awk even and do not require the user to install more software just to handle json

there's 2 methods that do not require the user to install new software nor do they require a large change to the check core.

Method 1: grep + awk

curl -LIs https://www.factorio.com/get-download/stable/headless/linux64 | grep Location | awk -F "?" '{print $1}' | awk -F "/" '{print $NF}' | awk -F "" '{print $4}' | awk -F ".tar" '{print $1}'_

Returns something like this as of today : 1.1.57

to get the file name you can do this curl -LIs https://www.factorio.com/get-download/stable/headless/linux64 | grep Location | awk -F "?" '{print $1}' | awk -F "/" '{print $NF}'

which returns this factorio_headless_x64_1.1.57.tar.xz

Method 2: awk on new API site

to get experimental curl -s https://factorio.com/api/latest-releases | awk -F ":" '{print $5 $9}' | awk -F """ '{print $2}'

outputs 1.1.57

to get stable curl -s https://factorio.com/api/latest-releases | awk -F ":" '{print $5 $9}' | awk -F """ '{print $6}'

outputs 1.1.57

both methods are simpler and do not force the user to install/rely on more external software

for Method 2 this is the sample raw output that awk works on {"experimental":{"alpha":"1.1.57","demo":"1.1.57","headless":"1.1.57"},"stable":{"alpha":"1.1.57","demo":"1.1.57","headless":"1.1.57"}} what its doing is breaking down the response first by : parts and then by a " and then returning the numbered column

the benefit is that any system capable of running a factorio server should also have awk/grep installed by default as they are core POSIX functions

The awk method is not robust to any changes made to the latest releases API.

The advantage of jq (which is by the way super light and you should consider using this for parsing json) is that you rely on key from the json instead of arbitrary number of ":".

Any server capable of running factorio is also capable of having jq installed, since it has no runtime dependencies.

Legrems avatar Apr 21 '22 13:04 Legrems

the advantage of awk is still 1 less software to install. There is no need to keep installing more and more packages to do something the os is already capable of doing by default. Less complexity is always better than more.

tmzasz avatar Apr 21 '22 16:04 tmzasz

I don't understand that "fear" to install such a small lib on a system knowing that we install Factorio and everything that goes with it. Using this makes the code more readable and more resistant to changes that the dev. may do in the API.

llann avatar Apr 28 '22 18:04 llann

its not a "fear" its a principle, why install more and more software to do tasks that the currently installed software can already handle just fine.

It would be like installing a distributed calculation program to handle 1+1 which the os's calculator can already do ( extreme example but valid example )

tmzasz avatar Apr 28 '22 19:04 tmzasz

theres also the issue of slowly creeping into Dependency hell for nothing

tmzasz avatar Apr 28 '22 19:04 tmzasz

"Creeing into dependency hell for nothing" Ok, then don't install factorio-init (which by the way don't work atm, so nice dependancy) to "just" install a server because it's still one more dependances than just downloading and launching the game.

Legrems avatar May 06 '22 10:05 Legrems

Just before definetly closing this, i'm curious to know your opinion on this @Bisa.

Thank's in advance !

Legrems avatar May 06 '22 15:05 Legrems

Thnx for the suggested fix @Legrems - I did however opt to use already existing tools, at some point in the future I may look at using the api, but much like @tmzasz I try to stick to as few "extras" as I can (when I remember to and when I do not whirr off into some random "this is so cool" spree ;) )

Bisa avatar Aug 21 '22 20:08 Bisa