-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·162 lines (134 loc) · 4.68 KB
/
bootstrap
File metadata and controls
executable file
·162 lines (134 loc) · 4.68 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
#!/bin/sh
##region Sanity checks and "imports"
[ $ZI_DOTFILES ] && {
. $ZI_DOTFILES/common
} || {
[ -f ./common ] || { >&2 echo "Bootstrap should be ran directly from dotfiles directory ('./bootstrap'), or run './pre-bootstrap' before running bootstrap!"; exit 1; }
. ./common
}
[ $ZI_DOTFILES ] || {
ZI_DOTFILES=$PWD
echo "'./pre-bootstrap' was never ran before. This script will store '$PWD' in \$ZI_DOTFILES as helper variable for automation scripts."
prompt "Run it now? [y/N] " || { >&2 echo "You need to run './pre-bootstrap' before running bootstrap!"; exit 1; }
echo "======include/dotfiles======"
./pre-bootstrap -
echo "============================"
prompt "Set '$PWD' as dotfiles directory? [y/N] " || exit 1
./pre-bootstrap - > $ZI_DOTFILES/.config/zsh/include/dotfiles
}
[ -d $ZI_DOTFILES ] || { >&2 echo "Invalid dotfiles path, please re-run pre-bootstrap!"; exit 1; }
. $ZI_DOTFILES/bootstrap-pkgs
##endregion
##region Function and Variable
is_package_exists() {
[ $(command -v "$1" | wc -l) -gt 0 ] && return 0 || return 1
}
case "$OSTYPE" in
"darwin"* ) DISTRO="apple" ;;
* ) DISTRO="$(cat /etc/*-release | grep ^ID | head -n1 | cut -d '=' -f2 | cut -d '"' -f2)" ;;
esac
SUDO="sudo"
# [ "$SUDO" = "" ] && {
# FALLBACK_SUDO="sudo"
# case $DISTRO in
# "apple" ) SUDO=$FALLBACK_SUDO ;; # There's no good doas implementation for macOS
# * )
# is_package_exists doas && SUDO="doas" || SUDO=$FALLBACK_SUDO
# doas echo "" >/dev/null 2>/dev/null || SUDO=$FALLBACK_SUDO
# ;;
# esac
# }
has_sudo_priv() {
return $SUDO -v 2>/dev/null
}
[ "$PACMAN" = "" ] && {
case $DISTRO in
"arch" ) PACMAN="pacman" ;;
"ubuntu" ) PACMAN="apt" ;;
"apple" ) PACMAN="apple" ;;
esac
}
AUR="${AUR:-paru}"
update_package_db() {
has_sudo_priv || { echo "No sudo privilege, skipping..."; return; }
MSG_FAILED="Failed to update package database, skipping..."
case "$PACMAN" in
"pacman" ) $SUDO $PACMAN -Sy || echo $MSG_FAILED ;;
"apt" ) $SUDO $PACMAN -y update || echo $MSG_FAILED ;;
"apple" ) ;;
* ) echo "Not implemented, skipping..." ;;
esac
}
install_package() {
has_sudo_priv || { echo "No sudo privilege, skipping..."; return; }
[ "$1" = "" ] && { echo "No package candidate is specified, skipping..."; return; }
MSG_FAILED="Failed to install some packages, skipping..."
case "$PACMAN" in
"pacman" ) $SUDO $PACMAN -S --noconfirm "$@" || echo $MSG_FAILED ;;
"apt" ) $SUDO $PACMAN -y install "$@" || echo $MSG_FAILED ;;
"apple" )
echo "Handled by nix. Read '.config/nix/README.md' for more information."
sleep 5
;;
* ) echo "Not implemented, skipping..." ;;
esac
}
install_aur_package() {
has_sudo_priv || { echo "No sudo privilege, skipping..."; return; }
# >> Paranoia checks
[ $DISTRO = "arch" ] || { echo "AUR only available in Arch, skipping..."; return; }
is_package_exists $AUR || { echo "AUR helper '$AUR' is not installed, skipping..."; return; }
[ "$1" = "" ] && { echo "No AUR package candidate is specified, skipping..."; return; }
# <<
case "$AUR" in
"paru" ) $AUR -S --noconfirm --skipreview "$@" ;;
* ) $AUR -S --noconfirm "$@" ;;
esac
}
install_nix() {
is_package_exists nix && { echo "nix is already installed, skipping..."; return; }
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
}
##endregion
echo "Linking x* configs..."
ln -si $ZI_DOTFILES/.config/xinitrc $HOME/.xinitrc
ln -si $ZI_DOTFILES/.config/xprofile $HOME/.xprofile
echo "Updating package database..."
update_package_db
echo "Installing common packages..."
install_package "${packages[@]}"
echo "Installing distro-specific packages..."
case $DISTRO in
"arch" )
install_package "${packages_arch[@]}"
echo "Installing AUR packages..."
install_aur_package "${packages_arch_aur[@]}"
;;
"ubuntu" ) install_package "${packages_ubuntu[@]}" ;;
* ) echo "Not implemented, skipping..." ;;
esac
echo "Installing nix..."
install_nix
echo "Changing default shell to zsh..."
chsh -s $(which zsh)
has_sudo_priv && {
echo "Configuring zsh to use XDG Base Directory..."
$SUDO $ZI_DOTFILES/zsh-xdg-setup
}
echo "Installing zsh config..."
ln -si $ZI_DOTFILES/.config/zsh $HOME/.config/zsh
# is_package_exists doas && {
# echo "Configuring doas..."
# case "$OSTYPE" in
# "darwin"* ) echo "permit persist :staff" > /tmp/doas.conf.tmp ;;
# * ) echo "permit persist :wheel" > /tmp/doas.conf.tmp ;;
# esac
# echo "permit nopass root as root" >> /tmp/doas.conf.tmp
# echo "=======/etc/doas.conf======="
# cat /tmp/doas.conf.tmp
# echo "============================"
# $SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf
# $SUDO ln -si /etc/doas.conf /usr/local/etc/doas.conf
# }
echo "============================"
echo "Bootstrap completed, please restart your shell!"