-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·81 lines (71 loc) · 1.84 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/env bash
dotfiles_folder=$(pwd)
dotfiles=(
".bashrc.d"
".config/fontconfig"
".config/i3"
".config/nvim"
".env"
".gdbinit"
".local/share/fonts"
".tmux.conf"
)
dependencies=(
alacritty
automake
fzf
g++
gcc
i3
make
neovim
picom
ripgrep
tmux
)
install_dependencies() {
echo "Installing dependencies ..."
local package_manager
if [ -x "$(command -v apt-get)" ]; then
# Ubuntu/Debian
sudo apt-get update
package_manager="apt-get"
elif [ -x "$(command -v dnf)" ]; then
# Fedora
package_manager="dnf"
else
echo "error: Unsupported package manager. Currently supported package managers: apt-get, dnf. Please install the following dependencies manually:"
for dep in "${dependencies[@]}"; do
echo " $dep"
done
fi
sudo "$package_manager" install -y "${dependencies[@]}"
}
# Backup
backup_timestamp=$(date +%Y-%m-%d-%H-%M-%S)
backup_folder="$HOME/dotfiles_backup_${backup_timestamp}"
mkdir -p "$backup_folder"
for f in "${dotfiles[@]}"; do
source_path="${HOME}/${f}"
# If symlink, get actual file instead of copying symlink
if [ -L "$source_path" ]; then
symlink_target=$(readlink -f "$source_path")
if [ -e "$symlink_target" ]; then
echo "Backing up ${symlink_target} to ${backup_folder}/${f}"
cp -r "$symlink_target" "${backup_folder}/"
fi
# If regular file
elif [ -e "$source_path" ]; then
echo "Backing up ~/${f} to ${backup_folder}/${f}"
mv "$source_path" "${backup_folder}/"
fi
done
# Create
for f in "${dotfiles[@]}"; do
echo "Symlinking ~/${f}"
mkdir -p "${HOME}/$(dirname "${f}")"
ln -fsn "${dotfiles_folder}/${f}" "${HOME}/${f}"
done
install_dependencies
source "$HOME/.bashrc"
echo "Done!"