-
Notifications
You must be signed in to change notification settings - Fork 171
/
nix.sh
executable file
·47 lines (37 loc) · 1.62 KB
/
nix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
TUNASYNC_WORKING_DIR="${TUNASYNC_WORKING_DIR:-nix}"
TUNASYNC_UPSTREAM_URL="${TUNASYNC_UPSTREAM_URL:-s3://nix-releases/nix/}"
MIRROR_BASE_URL="${MIRROR_BASE_URL:-https://mirrors.tuna.tsinghua.edu.cn/nix}"
ORIG_BASE_URL_OLD="https://nixos.org/releases/nix"
ORIG_BASE_URL="https://releases.nixos.org/nix"
EXCLUDES=(--exclude "*/*/*" \
--exclude "nix-[01].*" \
--exclude "nix-2.[01][./]*" \
--exclude "*-broken*")
INSTALL_TEMP="$(mktemp -d .tmp.XXXXXX)"
trap 'rm -rf "$INSTALL_TEMP"' EXIT
[[ ! -d "${TUNASYNC_WORKING_DIR}" ]] && mkdir -p "${TUNASYNC_WORKING_DIR}"
cd "${TUNASYNC_WORKING_DIR}"
aws --no-sign-request s3 sync ${TUNASYNC_AWS_OPTIONS} \
"${EXCLUDES[@]}" \
--exclude "*/install" \
--exclude "*/install.asc" \
--exclude "*/install.sha256" \
"${TUNASYNC_UPSTREAM_URL}" .
# Create install script
aws --no-sign-request s3 sync ${TUNASYNC_AWS_OPTIONS} \
--exclude "*" \
--include "*/install" \
"${EXCLUDES[@]}" \
"${TUNASYNC_UPSTREAM_URL}" "${INSTALL_TEMP}"
for version in $(ls "$INSTALL_TEMP"); do
[[ ! -d "${version}" ]] && continue # Shouldn't happen
sed -e "s|${ORIG_BASE_URL}|${MIRROR_BASE_URL}|" -e "s|${ORIG_BASE_URL_OLD}|${MIRROR_BASE_URL}|" \
< "${INSTALL_TEMP}/${version}/install" \
> "${INSTALL_TEMP}/${version}/.install"
mv "${INSTALL_TEMP}/${version}/.install" "${version}/install"
sha256sum "${version}/install" | cut -d' ' -f1 | tr -d '\n' \
> "${INSTALL_TEMP}/${version}/.install.sha256"
mv "${INSTALL_TEMP}/${version}/.install.sha256" "${version}/install.sha256"
done
ln -sfn "$(ls -d nix-* | sort -rV | head -1)" latest