2016-01-22 23:54:49 +00:00
|
|
|
source $stdenv/setup
|
|
|
|
|
|
|
|
# Curl flags to increase reliability a bit.
|
|
|
|
#
|
|
|
|
# Can't use fetchurl, for several reasons. One is that we definitely
|
|
|
|
# don't want --insecure for the login, though we need it for the
|
|
|
|
# download as their download cert isn't in the standard linux bundle.
|
|
|
|
curl="curl \
|
|
|
|
--max-redirs 20 \
|
|
|
|
--retry 3 \
|
2016-04-21 14:09:53 +00:00
|
|
|
--cacert $cacert/etc/ssl/certs/ca-bundle.crt \
|
2016-08-14 22:47:00 +00:00
|
|
|
-b cookies \
|
|
|
|
-c cookies \
|
2016-01-22 23:54:49 +00:00
|
|
|
$curlOpts \
|
|
|
|
$NIX_CURL_FLAGS"
|
|
|
|
|
|
|
|
# We don't want the password to be on any program's argv, as it may be
|
|
|
|
# visible in /proc. Writing it to file with echo should be safe, since
|
|
|
|
# it's a shell builtin.
|
2016-08-14 22:47:00 +00:00
|
|
|
echo -n "$password" > password
|
2016-01-22 23:54:49 +00:00
|
|
|
# Might as well hide the username as well.
|
2016-08-14 22:47:00 +00:00
|
|
|
echo -n "$username" > username
|
|
|
|
|
|
|
|
# Get a CSRF token.
|
|
|
|
csrf=$($curl $loginUrl | xidel - -e '//input[@id="csrf_token"]/@value')
|
2016-01-22 23:54:49 +00:00
|
|
|
|
|
|
|
# Log in. We don't especially care about the result, but let's check if login failed.
|
2016-08-14 22:47:00 +00:00
|
|
|
$curl --data-urlencode csrf_token="$csrf" \
|
|
|
|
--data-urlencode username_or_email@username \
|
|
|
|
--data-urlencode password@password \
|
|
|
|
-d action=Login \
|
|
|
|
$loginUrl -D headers > /dev/null
|
2016-01-22 23:54:49 +00:00
|
|
|
|
2016-08-14 22:47:00 +00:00
|
|
|
if grep -q 'Location: https://' headers; then
|
2016-01-22 23:54:49 +00:00
|
|
|
# Now download. We need --insecure for this, but the sha256 should cover us.
|
2017-07-16 13:09:57 +00:00
|
|
|
$curl --insecure --location --fail $url > $out || { echo "Login succeeded, but subsequent fetch failed."; exit 1; }
|
2016-08-14 22:47:00 +00:00
|
|
|
set +x
|
2016-01-22 23:54:49 +00:00
|
|
|
else
|
2016-08-14 22:47:00 +00:00
|
|
|
set +x
|
2016-01-22 23:54:49 +00:00
|
|
|
echo 'Login failed'
|
|
|
|
echo 'Please set username and password with config.nix,'
|
|
|
|
echo 'or /etc/nix/nixpkgs-config.nix if on NixOS.'
|
|
|
|
echo
|
|
|
|
echo 'Example:'
|
|
|
|
echo '{'
|
|
|
|
echo ' packageOverrides = pkgs: rec {'
|
|
|
|
echo ' factorio = pkgs.factorio.override {'
|
|
|
|
echo ' username = "<username or email address>";'
|
|
|
|
echo ' password = "<password>";'
|
|
|
|
echo ' };'
|
|
|
|
echo ' };'
|
|
|
|
echo '}'
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|