-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·142 lines (126 loc) · 4.46 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·142 lines (126 loc) · 4.46 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
# Install (or update) pulse from the latest GitHub release.
# curl -fsSL https://raw.githubusercontent.com/tanmoysrt/pulse/master/install.sh | sh
set -eu
REPO="tanmoysrt/pulse"
BIN="pulse"
fail() { echo "pulse: $1" >&2; exit 1; }
as_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
return
fi
command -v sudo >/dev/null 2>&1 || fail "need sudo to install required tools"
sudo "$@"
}
install_linux_tools() {
missing_tmux=0
missing_sqlite=0
command -v tmux >/dev/null 2>&1 || missing_tmux=1
command -v sqlite3 >/dev/null 2>&1 || missing_sqlite=1
[ "$missing_tmux" -eq 0 ] && [ "$missing_sqlite" -eq 0 ] && return
if command -v apt-get >/dev/null 2>&1; then
packages=""
[ "$missing_tmux" -eq 0 ] || packages="$packages tmux"
[ "$missing_sqlite" -eq 0 ] || packages="$packages sqlite3"
as_root apt-get update
as_root apt-get install -y $packages
elif command -v apk >/dev/null 2>&1; then
packages=""
[ "$missing_tmux" -eq 0 ] || packages="$packages tmux"
[ "$missing_sqlite" -eq 0 ] || packages="$packages sqlite"
as_root apk add $packages
elif command -v dnf >/dev/null 2>&1; then
packages=""
[ "$missing_tmux" -eq 0 ] || packages="$packages tmux"
[ "$missing_sqlite" -eq 0 ] || packages="$packages sqlite"
as_root dnf install -y $packages
elif command -v yum >/dev/null 2>&1; then
packages=""
[ "$missing_tmux" -eq 0 ] || packages="$packages tmux"
[ "$missing_sqlite" -eq 0 ] || packages="$packages sqlite"
as_root yum install -y $packages
elif command -v pacman >/dev/null 2>&1; then
packages=""
[ "$missing_tmux" -eq 0 ] || packages="$packages tmux"
[ "$missing_sqlite" -eq 0 ] || packages="$packages sqlite"
as_root pacman -Sy --noconfirm $packages
else
fail "unsupported Linux package manager; install tmux and sqlite3, then run this again"
fi
}
install_macos_tools() {
packages=""
command -v tmux >/dev/null 2>&1 || packages="$packages tmux"
command -v sqlite3 >/dev/null 2>&1 || packages="$packages sqlite"
[ -n "$packages" ] || return
command -v brew >/dev/null 2>&1 || fail "Homebrew is required to install tmux and sqlite3 (https://brew.sh)"
brew install $packages
if command -v sqlite3 >/dev/null 2>&1; then
return
fi
brew link --overwrite --force sqlite
}
install_required_tools() {
case "$os" in
linux) install_linux_tools ;;
darwin) install_macos_tools ;;
esac
command -v tmux >/dev/null 2>&1 || fail "tmux installation failed"
command -v sqlite3 >/dev/null 2>&1 || fail "sqlite3 installation failed"
}
os=$(uname -s)
case "$os" in
Linux) os="linux" ;;
Darwin) os="darwin" ;;
*) fail "unsupported OS: $os (linux and macOS only)" ;;
esac
arch=$(uname -m)
case "$arch" in
x86_64|amd64) arch="amd64" ;;
arm64|aarch64) arch="arm64" ;;
*) fail "unsupported architecture: $arch (amd64 and arm64 only)" ;;
esac
# Already installed? Ask before replacing it, and reuse its directory so an
# update lands in the same place. Read from the terminal, since stdin is the
# piped script when run via `curl | sh`.
if existing=$(command -v "$BIN" 2>/dev/null); then
current=$("$BIN" --version 2>/dev/null || echo "unknown")
printf "pulse %s is already installed. Update to the latest release? [y/N] " "$current"
if [ -r /dev/tty ]; then read -r ans </dev/tty; else read -r ans; fi
case "$ans" in
y|Y|yes|YES) ;;
*) echo "pulse: leaving the existing install untouched."; exit 0 ;;
esac
INSTALL_DIR=$(dirname "$existing")
elif [ "$(id -u)" -eq 0 ]; then
INSTALL_DIR="/usr/bin"
else
# A user-writable location so the running daemon can self-update from
# the web UI later without ever needing a sudo password prompt.
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
fi
asset="${BIN}-${os}-${arch}"
url="https://github.com/${REPO}/releases/latest/download/${asset}"
target="${INSTALL_DIR}/${BIN}"
# Elevate only if we can't write to the install dir ourselves.
sudo=""
if [ ! -w "$INSTALL_DIR" ]; then
command -v sudo >/dev/null 2>&1 || fail "need write access to $INSTALL_DIR (run as root or install sudo)"
sudo="sudo"
fi
install_required_tools
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
echo "pulse: downloading ${asset}…"
curl -fSL# "$url" -o "$tmp" || fail "download failed (no release asset for ${os}/${arch}?)"
chmod +x "$tmp"
$sudo mv "$tmp" "$target"
trap - EXIT
echo "pulse: installed to ${target} ($("$target" --version 2>/dev/null || echo "?"))"
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*) echo "pulse: add $INSTALL_DIR to your PATH to run 'pulse' directly" ;;
esac
echo "pulse: run 'pulse' to get started."