summaryrefslogtreecommitdiff
path: root/customized/fetch.sh
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-09-13 04:13:51 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-09-13 04:13:51 +0200
commite95dba2a4b35a8550a2d5320f00c90a11a126c0a (patch)
tree843027f7643b191076ac1394f288715c9e31bbfc /customized/fetch.sh
parentb88de6a31fd97816342382080be6db3f503435f1 (diff)
downloadnixos-e95dba2a4b35a8550a2d5320f00c90a11a126c0a.tar
nixos-e95dba2a4b35a8550a2d5320f00c90a11a126c0a.tar.gz
nixos-e95dba2a4b35a8550a2d5320f00c90a11a126c0a.tar.bz2
nixos-e95dba2a4b35a8550a2d5320f00c90a11a126c0a.tar.xz
nixos-e95dba2a4b35a8550a2d5320f00c90a11a126c0a.zip
customized factorio fetch
Diffstat (limited to 'customized/fetch.sh')
-rw-r--r--customized/fetch.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/customized/fetch.sh b/customized/fetch.sh
new file mode 100644
index 00000000..30d9c9fd
--- /dev/null
+++ b/customized/fetch.sh
@@ -0,0 +1,55 @@
1source $stdenv/setup
2
3# Curl flags to increase reliability a bit.
4#
5# Can't use fetchurl, for several reasons. One is that we definitely
6# don't want --insecure for the login, though we need it for the
7# download as their download cert isn't in the standard linux bundle.
8curl="curl \
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.
20echo -n "$password" > password
21# Might as well hide the username as well.
22echo -n "$username" > username
23
24# Get a CSRF token.
25csrf=$($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
34if 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.'
43 echo
44 echo 'Example:'
45 echo '{'
46 echo ' packageOverrides = pkgs: rec {'
47 echo ' factorio = pkgs.factorio.override {'
48 echo ' username = "<username or email address>";'
49 echo ' password = "<password>";'
50 echo ' };'
51 echo ' };'
52 echo '}'
53
54 exit 1
55fi