-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·60 lines (48 loc) · 1.62 KB
/
bootstrap.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
#!/bin/bash
set -euo pipefail
user=mike
remote='https://github.com/mikeroll/dotfiles.git'
localdir="${HOME}/dotfiles"
hostname="$1"
if [[ "$USER" == 'root' ]]; then
# Set the hostname
echo "${hostname}" >| /etc/hostname
# Install the essentials
pacman -Sy --noconfirm zsh git sudo
# Create me a user
if ! grep -q "$user" /etc/group; then
groupadd "$user"
fi
if ! grep -q "$user" /etc/passwd; then
useradd -m -g "$user" -s "$(command -v zsh)" "$user"
echo "Set password for user $user"
passwd "$user"
fi
echo "$user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/"$user"
# Set zsh "entrypoint"
echo 'export ZDOTDIR=${XDG_CONFIG_HOME:-$HOME/.config}/zsh' > /etc/zsh/zshenv
# Set zsh as default shell
chsh -s /usr/bin/zsh "$user"
# Continue as myself
exec sudo -u "$user" bash "$0" "$@"
elif [[ "$USER" == "$user" ]]; then
# Clone dotfiles
if ! ([[ -d "${localdir}" ]] && cd "${localdir}" && git rev-parse --is-inside-work-tree >/dev/null); then
git clone "${remote}" "${localdir}"
fi
# Install yay
if ! command -v yay >/dev/null; then
curl -sSL https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=yay-bin > yay.PKGBUILD
makepkg -si --noconfirm -p yay.PKGBUILD
rm -f yay.PKGBUILD
fi
# Install dotfiles
for dir in .config .local/share/applications .icons bin; do
[[ -d ~/"$dir" ]] || ln -sfn "${localdir}/$dir" ~/"$dir"
done
# Apply aconfmgr state
if ! command -v aconfmgr; then
yay -Sy --noconfirm aconfmgr-git
fi
aconfmgr apply --paranoid
fi