factorio: Fix the fetch script (#17741)

authored by Svein Ove Aas and committed by Robin Gloster cbe8832c 226cba76

+18 -7
+2 -2
pkgs/games/factorio/fetch.nix
··· 1 - { stdenv, curl, cacert 2 # Begin download parameters 3 , username ? "" 4 , password ? "" ··· 18 stdenv.mkDerivation { 19 name = "factorio.tar.gz"; 20 21 - buildInputs = [ curl ]; 22 23 inherit url loginUrl username password cacert; 24
··· 1 + { stdenv, curl, xidel, cacert 2 # Begin download parameters 3 , username ? "" 4 , password ? "" ··· 18 stdenv.mkDerivation { 19 name = "factorio.tar.gz"; 20 21 + buildInputs = [ curl xidel ]; 22 23 inherit url loginUrl username password cacert; 24
+16 -5
pkgs/games/factorio/fetch.sh
··· 9 --max-redirs 20 \ 10 --retry 3 \ 11 --cacert $cacert/etc/ssl/certs/ca-bundle.crt \ 12 $curlOpts \ 13 $NIX_CURL_FLAGS" 14 15 # We don't want the password to be on any program's argv, as it may be 16 # visible in /proc. Writing it to file with echo should be safe, since 17 # it's a shell builtin. 18 - echo "password=$password" > password 19 # Might as well hide the username as well. 20 - echo "username-or-email=$username" > username 21 22 # Log in. We don't especially care about the result, but let's check if login failed. 23 - $curl -c cookies -d @username -d @password $loginUrl -D headers > /dev/null 24 25 - if grep -q 'Location: /' headers; then 26 # Now download. We need --insecure for this, but the sha256 should cover us. 27 - $curl -b cookies --insecure --location $url > $out 28 else 29 echo 'Login failed' 30 echo 'Please set username and password with config.nix,' 31 echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.'
··· 9 --max-redirs 20 \ 10 --retry 3 \ 11 --cacert $cacert/etc/ssl/certs/ca-bundle.crt \ 12 + -b cookies \ 13 + -c cookies \ 14 $curlOpts \ 15 $NIX_CURL_FLAGS" 16 17 # We don't want the password to be on any program's argv, as it may be 18 # visible in /proc. Writing it to file with echo should be safe, since 19 # it's a shell builtin. 20 + echo -n "$password" > password 21 # Might as well hide the username as well. 22 + echo -n "$username" > username 23 + 24 + # Get a CSRF token. 25 + csrf=$($curl $loginUrl | xidel - -e '//input[@id="csrf_token"]/@value') 26 27 # Log in. We don't especially care about the result, but let's check if login failed. 28 + $curl --data-urlencode csrf_token="$csrf" \ 29 + --data-urlencode username_or_email@username \ 30 + --data-urlencode password@password \ 31 + -d action=Login \ 32 + $loginUrl -D headers > /dev/null 33 34 + if grep -q 'Location: https://' headers; then 35 # Now download. We need --insecure for this, but the sha256 should cover us. 36 + $curl --insecure --location $url > $out 37 + set +x 38 else 39 + set +x 40 echo 'Login failed' 41 echo 'Please set username and password with config.nix,' 42 echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.'