-
Notifications
You must be signed in to change notification settings - Fork 5
/
dotfiles-restore.sh
155 lines (129 loc) · 5.06 KB
/
dotfiles-restore.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
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
#!/bin/sh
# Warning: This will work for coffebar only!
# Run as regular user, not root!
# Before proceeding you need to restore SSH and GPG keys.
# SSH config must point to the GitHub's private key.
# Function to ask for user confirmation
confirm() {
PROMPT="$1"
while true; do
echo "$PROMPT [y/n]"
read -r response
case $response in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
*) echo "$PROMPT [y/n]" ;;
esac
done
}
REPO="$HOME/dotfiles"
if [ -d "$REPO" ]; then
echo "Dotfiles repo already exists."
confirm "Do you want to proceed?" || exit
else
# enable colors for pacman
sudo sed -i 's/#Color/Color/' /etc/pacman.conf
# install git and openssh to clone repo via git ssh
# base-devel is for yay setup
sudo pacman --needed --noconfirm -Sy git openssh base-devel
# make sure that key permissions are correct
chmod 600 ~/key/ssh/*
# clone repo
git clone --bare git@github.com:coffebar/dotfiles.git dotfiles || exit 1
# configure work tree path
git --git-dir="$REPO" --work-tree="$HOME" config --local core.worktree "$HOME"
# checkout files into $HOME
git --git-dir="$REPO" --work-tree="$HOME" checkout -f
# enable GPG sign for dotfiles repo (commit signature verification)
~/.local/bin/github-enable-gpg
# set custom gitingore path
git --git-dir="$REPO" --work-tree="$HOME" config --local core.excludesFile "$HOME/dotfiles.gitignore"
fi
# install yay if not installed
if ! command -v yay; then
# install yay
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si --noconfirm && cd .. && rm -rf yay
yay -Y --gendb
fi
pkglist_file1="$HOME/pkglist-intel.txt"
pkglist_file2="$HOME/pkglist-nvidia.txt"
pkglist_file3="$HOME/pkglist-nvidia-xorg.txt"
echo "Available package lists:"
echo "1) $pkglist_file1"
echo "2) $pkglist_file2"
echo "3) $pkglist_file3"
echo "Please select a package list (1-3):"
# Read user input
read selection
# Determine the selected file
case "$selection" in
1) PKG_FILE="$pkglist_file1" ;;
2) PKG_FILE="$pkglist_file2" ;;
3) PKG_FILE="$pkglist_file3" ;;
*) echo "Invalid selection. Exiting." >&2; exit 1 ;;
esac
confirm "Do you want to install packages from $PKG_FILE?" || exit
# install packages
# Note: --noconfirm can't be used, because you need to resolve conflicts
# use /tmp/yay as build directory
mkdir -p /tmp/yay
# repeat command until it succeeds
until yay -S --builddir /tmp/yay --needed --cleanmenu=false --diffmenu=false --editmenu=false --removemake=false - < "$PKG_FILE"; do
echo "Failed to install packages."
confirm "Do you want to retry?" || exit
yay -Syu
done
echo "Packages installed successfully."
# copy input device configs for xorg
if [ -d /etc/X11/xorg.conf.d ]; then
sudo cp ~/00-keyboard.conf /etc/X11/xorg.conf.d/
sudo cp ~/30-touchpad.conf /etc/X11/xorg.conf.d/
fi
# add firewall rule
sudo ufw default deny incoming
sudo ufw allow syncthing
sudo ufw enable
# enable services
sudo systemctl enable --now cronie bluetooth docker tlp ufw systemd-timesyncd.service
echo "Installing ohmyzsh..."
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/main/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
git clone https://github.com/tom-doerr/zsh_codex.git ~/.oh-my-zsh/custom/plugins/zsh_codex
echo "Decrypting AI credentials..."
gpg --decrypt --output ~/.config/github-copilot/hosts.json ~/.config/github-copilot/hosts.json.gpg
# copy ksnip config
cp -f ~/.config/ksnip/ksnip.example.conf ~/.config/ksnip/ksnip.conf
# setup pacman hook to update pkglist file automatically
pacman-setup-hooks "$PKG_FILE"
# setup keepassxc password
echo "Configuring secret-tool for KeePassXC"
echo "Please enter KeePassXC database.kdbx password:"
secret-tool store --label='KeePassXC' 'keepass' 'default'
# gtk theme options
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
gsettings set org.gtk.Settings.FileChooser startup-mode cwd
gsettings set org.gtk.gtk4.Settings.FileChooser startup-mode cwd
# gtk cursor and icon themes
gsettings set org.gnome.desktop.interface cursor-theme BreezeX-RosePine-Linux
gsettings set org.gnome.desktop.interface icon-theme 'bloom-classic'
gsettings set org.gnome.desktop.interface cursor-size 32
echo "Setting up neovim..."
# add node_modules to path
export PATH="$PATH:$HOME/.local/share/pnpm:$HOME/.node_modules/bin"
sh -c "$(wget -O- https://raw.githubusercontent.com/coffebar/dotfiles/main/fetch-nvim-conf.sh)"
# install global packages via pnpm
PNPM_HOME=~/.local/share/pnpm pnpm install -g uglify-js
# setup cronjob
crontab -l | { cat; echo "*/5 * * * * .local/bin/batterynotify"; } | crontab -
# restore license for intelephense
test -f ~/dev/Scripts/intelephense-licence.sh && sh ~/dev/Scripts/intelephense-licence.sh
# set charge threshold to 80% to prolong battery life
echo "Setting charge threshold..."
sudo tlp setcharge 60 80 BAT0
# upgrade firmware
echo "Firmware upgrade..."
sudo fwupdmgr refresh
sudo fwupdmgr update
echo "Done. Consider re-login or reboot to apply all changes."