-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_once_setup_wsl2.sh.tmpl
60 lines (49 loc) · 2.39 KB
/
run_once_setup_wsl2.sh.tmpl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
{{ if .is_wsl2 -}}
sudo apt update && sudo apt install -y \
gnustep-gui-runtime \
;
# TODO: https://github.com/microsoft/WSL/issues/8943
# depends on kernel version, call exe on wsl2 filesystem is soooooooo slowly, so put on windows filesystem.
# clean: remove .exe from wsl2 fs if exists ...
# setup_wsl2_downloads.json hash: {{ include "files/setup_wsl2_downloads.json" | sha256sum }}
cat {{ joinPath .chezmoi.sourceDir "files/setup_wsl2_downloads.json" | quote }} |
jq -c -r '.downloads[] | .exe // .url | split("/") | last' |
xargs -I{} $SHELL -c 'exe_path=$(command -v {} 2>/dev/null) && [[ ! ${exe_path} =~ ^/mnt/.* ]] && echo "${exe_path} on wsl2. removing..." && sudo rm ${exe_path} || true'
# neovim with vscode + wsl2
# note: vscode-neovim won't load bashrc or profile, so put exe globally.
install_dir=$(wslpath $(wslvar USERPROFILE))/AppData/Local/bin
sudo mkdir -p $install_dir
cd $install_dir
# setup_wsl2_downloads.json hash: {{ include "files/setup_wsl2_downloads.json" | sha256sum }}
cat {{ joinPath .chezmoi.sourceDir "files/setup_wsl2_downloads.json" | quote }} |
jq -c '.downloads[]' |
while read -r download; do
url=$(echo "${download}" | jq -r '.url')
file=$(basename $url)
checksum=$(echo "${download}" | jq -r '.sha1sum')
exe=$(echo "${download}" | jq -r '.exe // .url | split("/") | last')
if [ "${exe#*.}" != "exe" ]; then
echo "exe: ${exe} must end with .exe. fill exe attribute on json element." >&2
exit 1
fi
exists_checksum=$(test -f $exe && echo $(sha1sum $exe | cut -d ' ' -f 1 | tr -d ' ') || echo "")
if [ "${checksum}" != "${exists_checksum}" ]; then
echo "download: ${url}"
curl -fsSLO $url
extension="${file#*.}"
case "${extension}" in
"zip")
unzip -p $file $exe | tee $exe >/dev/null
;;
*) ;;
esac
exists_checksum=$(sha1sum $exe | cut -d ' ' -f 1 | tr -d ' ')
[[ "${checksum}" != "${exists_checksum}" ]] &&
echo "checksum verfication failed for ${exe}" >&2 && exit 1
fi
chmod a+x $exe
command -v $exe &>/dev/null || echo "WARN: couldn't find [${exe}]. To resolve this, add [${install_dir}] to your user's PATH environment variable in Windows." >&2
done
cd - &>/dev/null
{{- end -}}