This repository was archived by the owner on Jul 12, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathbootstrap.sh
More file actions
203 lines (173 loc) · 7.75 KB
/
Copy pathbootstrap.sh
File metadata and controls
203 lines (173 loc) · 7.75 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# =============================================================================
# Omarchy Mac Bootstrap Installer
# =============================================================================
# This script is intended to be run as root on a fresh Arch/Asahi install.
# It creates a user (wheel), installs core dependencies (sudo, git, base-devel),
# installs yay, clones the repo into the new user's home, and then runs install.sh.
# =============================================================================
set -euo pipefail
# When invoked from `wget ... | bash`, stdin may be the pipe (EOF).
# Prefer reading from the controlling terminal.
TTY_IN=""
if [[ -r /dev/tty ]]; then
TTY_IN="/dev/tty"
fi
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
BOLD='\033[1m'
print_banner() {
echo -e "${CYAN}"
cat << 'EOF'
▄▄▄
▄█████▄ ▄███████████▄ ▄███████ ▄███████ ▄███████ ▄█ █▄ ▄█ █▄
████ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
████ ███ ███ ███ ███ ███ ███ ███ ███ ███ █▀ ███ ███ ███ ███
████ ███ ███ ███ ███ ▄███▄▄▄███ ▄███▄▄▄██▀ ███ ▄███▄▄▄███▄ ███▄▄▄███
████ ███ ███ ███ ███ ▀███▀▀▀███ ▀███▀▀▀▀ ███ ▀▀███▀▀▀███ ▀▀▀▀▀▀███
████ ███ ███ ███ ███ ███ ███ ██████████ ███ █▄ ███ ███ ▄██ ███
████ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
▀█████▀ ▀█ ███ █▀ ███ █▀ ███ ███ ███████▀ ███ █▀ ▀█████▀
███ █▀
MAC BOOTSTRAP INSTALLER
EOF
echo -e "${NC}"
}
print_step() { echo -e "\n${BLUE}${BOLD}==>${NC}${BOLD} $1${NC}"; }
print_success() { echo -e "${GREEN}✓${NC} $1"; }
print_warning() { echo -e "${YELLOW}⚠${NC} $1"; }
print_error() { echo -e "${RED}✗${NC} $1"; }
print_info() { echo -e "${CYAN}ℹ${NC} $1"; }
on_error() {
local exit_code=$?
local line_no="${BASH_LINENO[0]:-${LINENO}}"
print_error "Bootstrap failed (exit ${exit_code}) at line ${line_no}."
print_info "Command: ${BASH_COMMAND}"
exit "${exit_code}"
}
trap on_error ERR
require_root() {
if [[ ${EUID:-$(id -u)} -ne 0 ]]; then
print_error "This script must be run as root."
exit 1
fi
}
valid_username() {
[[ "$1" =~ ^[a-z_][a-z0-9_-]*$ ]]
}
prompt_username() {
local input
while true; do
if [[ -n "${OMARCHY_USER_NAME:-}" ]]; then
input="$OMARCHY_USER_NAME"
else
if [[ -n "$TTY_IN" ]]; then
if ! read -r -p "Choose a username to create: " input <"$TTY_IN"; then
print_error "Unable to read username (no interactive input)."
print_info "Run with OMARCHY_USER_NAME=yourname to continue non-interactively."
exit 1
fi
else
print_error "No TTY available for interactive input."
print_info "Run with OMARCHY_USER_NAME=yourname to continue non-interactively."
exit 1
fi
fi
if valid_username "$input"; then
echo "$input"
return 0
fi
print_warning "Invalid username. Use lowercase letters/numbers/_/- and start with a letter or _."
unset OMARCHY_USER_NAME
done
}
ensure_deps() {
print_step "Updating system and installing dependencies"
if ! pacman -Syu --noconfirm --needed sudo git base-devel; then
print_warning "Package installation failed; continuing anyway. Some later steps may fail."
fi
}
ensure_wheel_sudo() {
print_step "Configuring sudo for wheel group"
cat >/etc/sudoers.d/00-wheel <<'EOF'
%wheel ALL=(ALL:ALL) ALL
EOF
chmod 440 /etc/sudoers.d/00-wheel
}
ensure_user() {
local username="$1"
if id "$username" &>/dev/null; then
print_info "User '$username' already exists; reusing."
else
print_step "Creating user '$username'"
useradd -m -G wheel -s /bin/bash "$username"
print_success "User created"
fi
local home_dir
home_dir="$(getent passwd "$username" | cut -d: -f6)"
if [[ -n "$home_dir" ]] && [[ -d "$home_dir" ]]; then
local home_owner
home_owner="$(stat -c %U "$home_dir" 2>/dev/null || true)"
if [[ -n "$home_owner" ]] && [[ "$home_owner" != "$username" ]]; then
print_warning "Home directory ownership is '$home_owner' (expected '$username'); fixing."
chown -R "$username:$username" "$home_dir"
fi
fi
print_step "Setting password for '$username'"
print_info "You will be prompted to enter the password twice."
# passwd reads from the controlling terminal; if none exists, this will fail.
if ! passwd "$username"; then
print_error "Failed to set password (is this running in a real TTY?)."
exit 1
fi
}
install_yay() {
local username="$1"
print_step "Installing yay (AUR helper)"
if command -v findmnt &>/dev/null; then
local tmp_opts
tmp_opts="$(findmnt -no OPTIONS /tmp 2>/dev/null || true)"
if [[ "$tmp_opts" == *noexec* ]]; then
print_info "/tmp is mounted with noexec; building yay under the user's cache directory."
fi
fi
if su - "$username" -c "bash -lc 'set -e; build_root=\"\${XDG_CACHE_HOME:-\${HOME}/.cache}/omarchy-build\"; mkdir -p \"\$build_root\"; cd \"\$build_root\"; rm -rf yay; git clone https://aur.archlinux.org/yay.git yay; cd yay; makepkg -si --noconfirm --needed'"; then
print_success "yay installed"
else
print_warning "Failed to install yay; continuing without AUR helper."
fi
}
clone_repo_to_user() {
local username="$1"
local repo="${OMARCHY_REPO:-malik-na/omarchy-mac}"
local ref="${OMARCHY_REF:-main}"
print_step "Cloning Omarchy Mac into user's home"
su - "$username" -c "bash -lc 'set -e; mkdir -p ~/.local/share; rm -rf ~/.local/share/omarchy; git clone https://codeberg.org/${repo}.git ~/.local/share/omarchy; cd ~/.local/share/omarchy; if [[ \"${ref}\" != \"main\" ]]; then git fetch origin \"${ref}\" && git checkout \"${ref}\"; fi'"
print_success "Repository cloned"
}
run_installer() {
local username="$1"
print_step "Running Omarchy installer as $username"
print_info "You may be prompted for the user's sudo password during installation."
su - "$username" -c "bash -lc 'cd ~/.local/share/omarchy && bash install.sh'"
}
main() {
print_banner
require_root
local username
username="$(prompt_username)"
ensure_deps
ensure_wheel_sudo
ensure_user "$username"
install_yay "$username"
clone_repo_to_user "$username"
run_installer "$username"
print_success "Bootstrap complete"
print_info "If you hit mirror issues, run: bash fix-mirrors.sh"
}
main "$@"