Update factorio download script to accept optional edition argument.

Possible values:
- alpha (default): The base game
- headless: For server use
- demo: The Factorio Demo
- expansion: Factorio: Space Age expansion
This commit is contained in:
Erwin Boskma 2024-11-12 15:00:14 +01:00
parent 22111b5dc7
commit aad8139fdc
Signed by: erwin
SSH key fingerprint: SHA256:/Wk1WZdLg+vQHs3in9qq7PsIp8SMzwGSk/RLZ5zPuZk
2 changed files with 30 additions and 4 deletions

View file

@ -0,0 +1,15 @@
# shellcheck shell=bash
edition=alpha
if [[ $# -ge 1 ]]; then
edition="${1}"
fi
releases_file=$(mktemp --suffix=.json)
xhs -o "${releases_file}" factorio.com/api/latest-releases
version=$(jaq -r '.stable.alpha' "${releases_file}")
token=$(cat "${FACTORIO_TOKEN_FILE:?}")
nix-prefetch-url --name "factorio_${edition}_x64-${version}.tar.xz" \
"https://factorio.com/get-download/${version}/${edition}/linux64?username=eboskma&token=${token}"

View file

@ -11,10 +11,21 @@ let
homeCfg = config.home-manager.users.erwin;
bt = config.eboskma.bluetooth;
downloadFactorio = pkgs.writeShellScriptBin "download-factorio" ''
version=$(${pkgs.xh}/bin/xhs factorio.com/api/latest-releases | ${pkgs.jaq}/bin/jaq -r '.stable.alpha')
${pkgs.nix}/bin/nix-prefetch-url --name factorio_alpha_x64-''${version}.tar.xz https://factorio.com/get-download/''${version}/alpha/linux64\?username=eboskma\&token=$(cat ${config.sops.secrets.factorio-token.path})
'';
downloadFactorio = pkgs.writeShellApplication {
name = "download-factorio";
text = builtins.readFile ./download-factorio.sh;
runtimeInputs = with pkgs; [
jaq
nix
xh
];
runtimeEnv = {
FACTORIO_TOKEN_FILE = config.sops.secrets.factorio-token.path;
};
derivationArgs = {
version = "0.0.1";
};
};
in
{
config = mkIf cfg.home {