forked from MunifTanjim/scripts.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-gopass
executable file
·56 lines (45 loc) · 1.06 KB
/
setup-gopass
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
#!/usr/bin/env bash
set -euo pipefail
command_exists() {
type "${1}" >/dev/null 2>&1
}
ensure_tool() {
local -r tool="${1}"
if ! command_exists "${tool}"; then
echo "missing required tool: ${tool}"
exit 1
fi
}
setup_for_darwin() {
ensure_tool brew
brew install gopass
}
setup_for_debian() {
ensure_tool curl
ensure_tool dpkg
ensure_tool jq
ensure_tool wget
local -r repo="gopasspw/gopass"
local -r url_pattern="linux_amd64.deb"
local -r url=$(curl -s "https://api.github.com/repos/${repo}/releases/latest" | jq -r --arg pattern "${url_pattern}" '.assets | map(.browser_download_url) | map(select(. | test($pattern)))[0]')
local -r filename=$(basename "${url}")
echo "Downloading..."
curl --progress-bar --continue-at - --output "/tmp/${filename}" -L "${url}"
echo
echo "Installing..."
sudo dpkg --install "/tmp/${filename}"
echo
echo "Done!"
}
case $OSTYPE in
darwin*)
setup_for_darwin;;
linux*)
if command_exists dpkg; then
setup_for_debian
fi
;;
*)
echo "Unknown OS!"
exit 1;;
esac