-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
129 lines (109 loc) · 3.34 KB
/
bootstrap
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
#!/usr/bin/env bash
set -e
log() {
echo -e "$1"
}
export HISTIGNORE='*sudo -S*'
# Print colored header
log "Bootstrapping your system"
# Detecting the operating system
OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]')
if [[ "$OSTYPE" == "linux"* ]]; then
DIST=$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release)
fi
log "OSTYPE : ${OSTYPE}"
log "DIST : ${DIST}"
# Function to handle errors
handle_error() {
log "An error occurred. Please check the log for details."
exit 1
}
trap handle_error ERR
# Validate Sudo Acces
log "\nPlease enter your sudo password (for installing base packages):"
read -s -p "Password: " SUDO_PASSWORD
echo -e '\n'
echo "${SUDO_PASSWORD}" | sudo -S -v &>/dev/null || {
log "Error: Invalid sudo password or no sudo privileges."
exit 1
}
run_as() {
echo "${SUDO_PASSWORD}" | sudo -S "${@}"
}
install_yay() {
if ! command -v yay &>/dev/null; then
run_as pacman -S --needed --noconfirm git base-devel
git clone https://aur.archlinux.org/yay.git /tmp/yay
cd /tmp/yay
makepkg -si --noconfirm
rm -rf /tmp/yay
cd - || return
fi
}
install_python_deps() {
log "Installing Python3 Dependencies"
pip_pkgs="pip ansible jmespath pynvim"
python3 -m pip install --upgrade --no-cache-dir --break-system-packages --no-warn-script-location $pip_pkgs
}
configure_docker() {
run_as setfacl -m u:$USER:rw /var/run/docker.sock
}
install_os_deps() {
case "$OSTYPE" in
darwin*)
install_homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
;;
linux*)
install_yay
pkgs="bat bottom docker eza fd fzf git-delta github-cli go lazydocker lazygit neovim nodejs npm preload powertop procs ripgrep starship uv zoxide virt-manager qemu-desktop libvirt dnsmasq stow zip unzip zsh python-pip firefox foot thunderbird pfetch-rs tlp tlp-rdw wl-clipboard axel restic"
yay -Sy --noconfirm --needed --quiet $pkgs
pkgs_to_remove="gnome-contacts gnome-maps gnome-music vim epiphany gnome-tour htop"
yay -R --noconfirm $pkgs_to_remove || true
yay -S --noconfirm --clean
;;
*)
log "Unsupported OS"
exit 1
;;
esac
}
clone_dotfiles() {
DOTFILES_DIR="${HOME}/.dotfiles"
if [[ ! -d "$DOTFILES_DIR" ]]; then
log "Cloning psadi/.dotfiles"
git clone https://github.com/psadi/dotfiles.git "$DOTFILES_DIR"
else
log "psadi/.dotfiles already exists, pulling latest changes"
cd "$DOTFILES_DIR" && git pull && cd - || return
fi
}
configure_user() {
run_as chsh -s /usr/bin/zsh "$USER"
}
configure_systemd_services() {
for service in libvirtd docker preload; do
run_as systemctl enable --now "$service"
done
}
install_zap() {
zsh -c 'if ! (( $+functions[zap] )); then
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh) --branch release-v1 && rm -r ~/.zshrc
fi'
}
finalize() {
rm -rf .profile .bash* || true
mkdir -p "${HOME}/.config"
stow -d .dotfiles -t "${HOME}" .
zsh -c 'source ~/.zshrc && zap update all'
systemctl --user enable --now foot-server.service
}
# Main execution flow
install_os_deps
install_python_deps
install_zap
configure_systemd_services
configure_user
configure_docker
clone_dotfiles
finalize