-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·121 lines (107 loc) · 3.41 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·121 lines (107 loc) · 3.41 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
#!/usr/bin/env bash
set -euo pipefail
# Tools needed by the dotfiles:
# stow, node, pnpm, nvim, fzf, jq
# bat, fd, lazygit, tmux, glow (used by alias.sh / scripts)
BOLD='\033[1m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RESET='\033[0m'
ok() { printf " ${GREEN}✓${RESET} %s\n" "$1"; }
skip() { printf " ${YELLOW}o${RESET} %-12s ${YELLOW}%s${RESET}\n" "$1" "$2"; }
fail() { printf " ${RED}✗${RESET} %-12s ${RED}%s${RESET}\n" "$1" "$2"; }
pkg_install_pacman() { sudo pacman -S --needed --noconfirm -- "$@"; }
pkg_install_apt() { sudo apt-get update -qq; sudo apt-get install -y -- "$@"; }
install_none() { return 1; }
detect_os() {
case "$(uname -s)" in
Darwin)
OS=mac
if command -v brew &>/dev/null; then
PKG=brew; PKG_INSTALL="brew install"
else
PKG=none; PKG_INSTALL=install_none
fail "brew" "homebrew not found - install from https://brew.sh first, then re-run"
exit 1
fi
;;
Linux)
OS=linux
if command -v apt-get &>/dev/null; then
PKG=apt; PKG_INSTALL=pkg_install_apt
elif command -v pacman &>/dev/null; then
PKG=pacman; PKG_INSTALL=pkg_install_pacman
else
PKG=none; PKG_INSTALL=install_none
fail "pkg" "no supported package manager (apt/pacman) found"
exit 1
fi
;;
*)
fail "os" "unsupported OS: $(uname -s)"
exit 1
;;
esac
}
have() { command -v "$1" &>/dev/null; }
ensure() {
local tool="$1" check="$2"
if have "$check"; then
ok "$tool"
elif [ "${PKG}" = "none" ]; then
fail "$tool" "install manually"
else
case "$tool" in
pnpm)
if have npm; then
if npm install -g pnpm &>/dev/null; then ok pnpm; else fail pnpm "npm -g install failed"; fi
return
fi
;;
lazygit|glow|opencode)
if [ "${PKG}" = "apt" ]; then
skip "$tool" "not in default debian repos - install from github releases"
return
fi
;;
esac
local pkg="$tool"
case "${PKG}" in
apt)
case "$tool" in
node) pkg=nodejs ;;
nvim) pkg=neovim ;;
fd) pkg=fd-find ;;
esac
;;
esac
if "$PKG_INSTALL" "$pkg" &>/dev/null; then
ok "$tool"
else
fail "$tool" "install failed"
fi
fi
}
main() {
echo "Detected: ${BOLD}$OS ($PKG)${RESET}"
for entry in stow:stow node:node pnpm:pnpm nvim:nvim fzf:fzf jq:jq bat:bat fd:fd tmux:tmux; do
ensure "${entry%%:*}" "${entry##*:}"
done
for tool in lazygit glow opencode; do
if have "$tool"; then
ok "$tool"
else
case "${PKG}-${tool}" in
apt-lazygit|apt-glow|apt-*opencode)
skip "$tool" "not in repo, install from github releases"
;;
*)
"$PKG_INSTALL" "$tool" &>/dev/null && ok "$tool" || fail "$tool" "install failed"
;;
esac
fi
done
}
detect_os
main