···9 --max-redirs 20 \
10 --retry 3 \
11 --cacert $cacert/etc/ssl/certs/ca-bundle.crt \
0012 $curlOpts \
13 $NIX_CURL_FLAGS"
1415# 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
0002122# 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
00002425-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
028else
029 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"
1617# 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')
2627# 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
3334+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
38else
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.'