-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall
More file actions
executable file
·102 lines (89 loc) · 4.23 KB
/
install
File metadata and controls
executable file
·102 lines (89 loc) · 4.23 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env bash
set -e
#This is a fork of npiperelay that supports Assuan, the protocol that gpg-agent speaks
NPRREPO="albertony/npiperelay"
NPRFILE="npiperelay_windows_amd64.exe"
NPRFILEURL="https://github.com/albertony/npiperelay/releases/download/v1.10.0/npiperelay_windows_amd64.exe"
usage() {
echo 'Usage: install [-hgv]'
echo 'Install wsl-gpg-systemd automatically. See README for manual instructions.'
echo ''
echo ' -h, --help this help'
echo ' -g, --gh use GitHub CLI to fetch npiperelay, installing it first if necessary'
echo ' -v, --verbose show verbose output when available'
echo ''
exit $1
}
opts=$(getopt -o 'ghv' --long 'gh,help,verbose' -n install -- "$@")
eval set -- "$opts"
unset opts
for opt; do
case "$opt" in
-g|--gh) usegh="true";;
-h|--help) usage;;
-v|--verbose) verbose="-v";;
*) break;;
esac
done
#This is taken verbatim from the upstream installation instructions:
#https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt
install_gh() {
printf 'This will install GitHub CLI (gh) using apt. You may be asked for a sudo password.\n'
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
}
#remove CR from CRLF and flip \ to /
fixpath() {
tr -d '\015' | tr '\\' '/'
}
enable_w32_ssh() {
gpgagentconf=$(wslpath -u $(gpgconf.exe --list-dirs homedir | fixpath))
grep -q enable-win32-openssh-support $gpgagentconf || printf 'enable-win32-openssh-support\r\n' >> $gpgagentconf
gpg-connect-agent.exe reloadagent /bye
}
#System Paths
#If you edit these, the install will not work.
workdir="$(mktemp -p '' -d install-ssh-pageant-XXXX)"
nprfile_w="${workdir}/$NPRFILE"
gpgwinpath="$(gpgconf.exe --list-dirs agent-extra-socket | fixpath)"
gpgconfwinpath_u="$(type -aP gpgconf.exe | awk '/^\/mnt\// { print; exit }')"
if [ -z "${gpgconfwinpath_u}" ]; then
printf 'Error: could not locate a Windows gpgconf.exe in PATH.\n' >&2
exit 1
fi
unitdir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
#You can edit these if you really want, but they are sensible defaults
#Where to install the npiperelay binary. This MUST be on the Windows filesystem.
nprwinpath="$(powershell.exe -NoProfile -Command \$env:AppData | fixpath)/npiperelay/$NPRFILE"
nprwinpath_u="$(wslpath -u "$nprwinpath")"
#Where to install the symlink to npiperelay so that systemd can easily call it.
#It doesn't HAVE to be on the WSL filesystem, but it's much easier if it is.
localbin="${XDG_BIN_HOME:-$HOME/.local/bin}"
nprlocalpath="${localbin}/$NPRFILE"
printf 'Downloading %s...\n' "$NPRFILE"
if [ $usegh ]; then
hash gh 2>/dev/null || install_gh
gh release download -p $NPRFILE -R $NPRREPO -D "${workdir}"
else
curl -fsSL --output "${nprfile_w}" "$NPRFILEURL"
fi
printf 'Installing...\n'
sed 's%^ExecStart=\%h/.local/bin/npiperelay.exe%ExecStart='"${nprlocalpath}"'%' systemd-units/gpg-agent-ssh@.service > "${workdir}/gpg-agent-ssh@.service"
sed 's%^ExecStart=.*%ExecStart='"${nprlocalpath} -ep -ei -s -a '${gpgwinpath}'%" systemd-units/gpg-agent@.service > "${workdir}/gpg-agent@.service"
cp systemd-units/gpg-agent-ssh.socket systemd-units/gpg-agent.socket "${workdir}/"
install $verbose -D "${nprfile_w}" "${nprwinpath_u}" && rm "${nprfile_w}"
install $verbose -Dm 644 -t "${unitdir}" $workdir/*
install $verbose -Dm 644 systemd-units/gpg-agent-launch.service "${unitdir}/gpg-agent-launch.service"
install $verbose -d "${localbin}"
ln $verbose -nfs "${nprwinpath_u}" "${localbin}"
ln $verbose -nfs "${gpgconfwinpath_u}" "${localbin}/gpgconf-windows.exe"
systemctl --user enable gpg-agent-launch.service > /dev/null
systemctl --user restart gpg-agent-launch.service > /dev/null
rm -r "${workdir}"
printf 'Installation complete!\n'