-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·117 lines (102 loc) · 2.97 KB
/
Copy pathbootstrap
File metadata and controls
executable file
·117 lines (102 loc) · 2.97 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
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
EXPECTED_REPO_ROOT="$HOME/code/laulauland/dotfiles"
OPERATING_SYSTEM=$(uname)
CHANGE_SHELL=0
if [ "$REPO_ROOT" != "$EXPECTED_REPO_ROOT" ]; then
echo "This checkout must be at $EXPECTED_REPO_ROOT (found $REPO_ROOT)."
exit 1
fi
while [ $# -gt 0 ]; do
case "$1" in
--defaults)
# mise bootstrap applies [bootstrap.macos.*] defaults by default now.
shift
;;
--fish-shell)
CHANGE_SHELL=1
shift
;;
*)
break
;;
esac
done
install_homebrew() {
if command -v brew >/dev/null 2>&1; then
eval "$(brew shellenv)"
return
fi
echo "Homebrew install needs sudo once to create system directories."
sudo -v
echo "Installing Homebrew..."
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/opt/homebrew/bin/brew shellenv 2>/dev/null || /usr/local/bin/brew shellenv)"
}
install_mise() {
command -v mise >/dev/null 2>&1 && return
echo "Installing mise..."
brew install mise
}
is_arch() {
[ -r /etc/os-release ] && grep -q '^ID=arch$' /etc/os-release
}
install_arch_base() {
command -v mise >/dev/null 2>&1 && return
if ! command -v pacman >/dev/null 2>&1; then
echo "pacman is required for Arch bootstrap."
exit 1
fi
echo "Installing the Arch bootstrap prerequisite..."
sudo pacman -Syu --needed --noconfirm mise
}
install_global_mise_config() {
local environment=$1
mkdir -p "$HOME/.config/mise"
ln -sf "$REPO_ROOT/shared/.config/mise/config.toml" "$HOME/.config/mise/config.toml"
ln -sf "$REPO_ROOT/shared/.config/mise/config.$environment.toml" "$HOME/.config/mise/config.$environment.toml"
mise trust "$HOME/.config/mise/config.toml"
mise trust "$HOME/.config/mise/config.$environment.toml"
}
set_fish_shell() {
local fish_path
fish_path=$(command -v fish)
[ "$SHELL" = "$fish_path" ] && return
if ! grep -qxF "$fish_path" /etc/shells; then
echo "Adding $fish_path to /etc/shells"
echo "$fish_path" | sudo tee -a /etc/shells >/dev/null
fi
echo "Changing login shell to $fish_path"
chsh -s "$fish_path"
}
case "$OPERATING_SYSTEM" in
Darwin)
install_homebrew
install_mise
install_global_mise_config macos
# This checkout already exists, so let mise converge everything except cloning it.
mise bootstrap --yes -E macos --skip repos "$@"
[ "$CHANGE_SHELL" -eq 0 ] || set_fish_shell
;;
Linux)
if ! is_arch; then
echo "Only Arch Linux is supported by this bootstrap path."
exit 1
fi
if [ "$(id -u)" -eq 0 ]; then
echo "Run this as the target user, not root."
exit 1
fi
install_arch_base
install_global_mise_config arch
# Complete system packages and interactive GitHub/AUR setup first. Starting a
# fresh mise process afterwards ensures tool resolution sees the new gh token.
mise bootstrap --raw --yes -E arch --only packages
mise bootstrap --raw --yes -E arch --skip packages,repos,macos-defaults,macos-launchd-agents "$@"
;;
*)
echo "Your operating system is not supported."
exit 1
;;
esac