-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·133 lines (109 loc) · 2.81 KB
/
install.sh
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
#!/bin/bash
set -euo pipefail
export GITHUB_USER="${GITHUB_USER:=$(whoami)}"
export DOTFILES_REPO="https://github.com/$GITHUB_USER/dotfiles"
export DOTFILES_BRANCH="${DOTFILES_BRANCH:=main}"
export YADM_VERSION="3.3.0"
title() {
printf "\033[1;35m≡ %s\033[0m\n" "${@:$#}"
}
info() {
echo
printf "\033[1;37m∷ %s\033[0m\n" "${@:$#}"
}
fail() {
printf "\033[0;31m⁘ %s\n" "${@:$#}" >&2
exit 1
}
ask() {
printf "\033[0;32m⁖ %s\033[0m " "${@:$#}"
old_stty_cfg="$(stty -g)"
stty raw -echo
answer="$(head -c 1)"
# shellcheck disable=SC2086
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y"; then
echo
return 0
else
echo
return 1
fi
}
has_command() {
command -v "$@" >/dev/null 2>&1
}
is_macos() {
[[ "$OSTYPE" == darwin* ]]
}
is_linux() {
[[ "$OSTYPE" == linux* ]]
}
get_distro() {
has_command lsb_release && lsb_release -is 2>/dev/null
}
is_debian() {
has_command apt
}
has_pkg() {
pkg="${1}"
if is_macos; then
(brew list --formula "$pkg" || brew list --cask "$pkg") >/dev/null 2>&1
elif has_command dpkg-query; then
(dpkg-query -W "$pkg" || (has-command brew && brew list --formula "$pkg")) >/dev/null 2>&1
elif has_command pacman; then
pacman -Qi "$pkg" >/dev/null 2>&1
else
fail "Unsupported OS: $(get_distro)"
fi
}
# shellcheck disable=SC2086
add_pkg() {
pkg=${*}
info "Installing $pkg"
if has_command apt; then
sudo apt install -y $pkg
elif has_command brew; then
brew install $pkg
elif has_command pamac; then
pamac install --no-confirm $pkg
elif has_command yay; then
yay -S --noconfirm $pkg
elif has_command pacman; then
sudo pacman -S --noconfirm $pkg
else
fail "Unsupported OS: $(get_distro)"
fi
}
require() {
local pkg="${1:?}"
if ! has_pkg "$pkg"; then
add_pkg "$pkg" || fail "failed to install $pkg"
fi
}
title "Installing $GITHUB_USER's .dotfiles"
if is_linux && [[ -x /home/linuxbrew/.linuxbrew/bin/brew ]]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
if has_command brew; then
info "Updating Homebrew"
brew update && brew upgrade
elif is_macos || is_debian; then
info "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
require yadm ||
sudo -- sh -c "curl -fsSLo /usr/local/bin/yadm 'https://raw.githubusercontent.com/TheLocehiliosan/yadm/${YADM_VERSION}/yadm' && chmod a+x /usr/local/bin/yadm"
require curl
require git
require zsh
info "Initializing the yadm repository"
if [[ -d "$HOME/.local/share/yadm/repo.git" ]]; then
if ask "The yadm repository already exists. Do you want to overwrite it?"; then
yadm checkout .
yadm clone "$DOTFILES_REPO" -b "$DOTFILES_BRANCH" --no-bootstrap -f
fi
else
yadm clone "$DOTFILES_REPO" -b "$DOTFILES_BRANCH" --no-bootstrap
fi
exec yadm bootstrap