This repository was archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.sh
executable file
·176 lines (160 loc) · 4.96 KB
/
setup.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
# set -eux
base_url="https://raw.githubusercontent.com/lime-desu/dootsfile/main"
source_colors() {
local tmp_file
tmp_file="$(mktemp)"
curl -fsSL "${base_url}"/config/zsh/functions/colors.zsh >"$tmp_file"
source "$tmp_file" && define_colors
unset tmp_file
}
DOOTS="$HOME/Git/Local/dootsfile"
CONFIG="$HOME/.config"
BINS="$HOME/.local/bin"
SCRIPTS="$BINS/scripts"
THEMES="$HOME/.local/share/themes"
ICONS="$HOME/.local/share/icons"
DEPENDENCIES=(alacritty bat broot btop cava chafa chsh curl delta dust exa fd foot fuck fzf git jq kitty lsd mpv neofetch nvim rg stow starship tar tldr tmux unzip wget wl-copy zsh)
check_dependencies() {
missing_deps=()
for dependency in "${DEPENDENCIES[@]}"; do
if ! command -v "$dependency" >/dev/null; then
missing_deps+=("$dependency")
fi
done
if [ ${#missing_deps[@]} -gt 0 ]; then
echo -e "${BLD}${BLU}Installing the following packages: ${RST}"
for dependency in "${missing_deps[@]}"; do
echo "- ${YLW}$dependency${RST}"
done
echo -e "${BLD}${RED}Note:${RST} Certain packages aren't available on some package manager"
return 1
fi
return 0
}
setup_flatpak() { sudo flatpak remote-modify --enable flathub && sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo; }
install_packages() {
if command -v "$package_manager" &>/dev/null; then
case "$package_manager" in
dnf | apt | flatpak) sudo "$package_manager" install -y "${packages[@]}" ;;
pacman | xbps-install) sudo "$package_manager" -Sy "${packages[@]}" ;;
*) echo "${BLD}${RED}Error:${RST} Unsupported package manager." ;;
esac
fi
}
# essential packages (setup script dependencies, modern unix and base-devel package (for building and compiling))
declare -A PACKAGE_LISTS=(
["pacman"]="${base_url}/scripts/install/packages/arch.txt"
["apt"]="${base_url}/scripts/install/packages/debian.txt"
["dnf"]="${base_url}/scripts/install/packages/fedora.txt"
["xbps-install"]="${base_url}/scripts/install/packages/void.txt"
["flatpak"]="${base_url}/scripts/install/packages/flatpak.txt"
["pkg"]="${base_url}/scripts/install/packages/termux.txt"
)
install_essential_packages() {
if [ -n "$TERMUX_VERSION" ]; then
readarray -t packages < <(curl -fsSL "${PACKAGE_LISTS[pkg]}")
pkg upgrade && pkg install -y "${packages[@]}" && pip install thefuck
else
for package_manager in "${!PACKAGE_LISTS[@]}"; do
readarray -t packages < <(curl -fsSL "${PACKAGE_LISTS[$package_manager]}")
install_packages "$package_manager" "${packages[@]}"
done
fi
}
create() {
local dir="$1"
local dir_name
dir_name="$(basename "$dir")"
if [[ ! -d "$dir" ]]; then
echo -e "Creating directory for ${BLD}${BLU}'$dir_name'${RST}..."
mkdir -p "$dir" && sleep 2
fi
}
backup() {
local file="$1"
local backup_file=${2:-$file.doots}
if [[ -e "$file" ]] && [[ ! -e "$backup_file" ]]; then
echo "Backing up ${BLD}${BLU}$file${RST} to ${BLD}${CYN}$backup_file${RST}..."
cp -r "$file" "$backup_file" && sleep 2
fi
}
create_dircopy_and_backup() {
dirs=("$CONFIG" "$BINS" "$SCRIPTS" "$THEMES" "$ICONS")
for dir in "${dirs[@]}"; do
backup "$dir"
create "$dir"
done
}
stow_this() {
local dootsfile="$1" target_dir="$2"
stow "$dootsfile" --dir "$DOOTS" --verbose --restow --target "$target_dir" --adopt
sleep 2
}
symlink() {
local dootsfile="$1" target_dir="$2"
echo -e "Symlinking ${BLD}${BLU}$dootsfile${RST} to ${BLD}${CYN}$target_dir${RST}..."
ln -sf "$dootsfile" "$target_dir" && sleep 2
}
setup() {
stow_this config "${CONFIG}"
stow_this bin "${BINS}"
stow_this scripts "${SCRIPTS}"
stow_this themes "${THEMES}"
stow_this icons "${ICONS}"
}
main() {
if [ ! -d "$DOOTS" ]; then
source_colors
! check_dependencies && install_essential_packages
echo -e "${BLD}${BLU}Fetching ${CYN}Doots${RST}${BLU}${BLD} from the source...${RST}"
create "$DOOTS" && cd "$_" || return
git clone --recurse-submodules --shallow-submodules https://github.com/lime-desu/dootsfile.git "$(pwd)"
create_dircopy_and_backup
# stow/symlink to proper directory
setup && git reset --hard &>/dev/null && bat cache --build
# execute install scripts
source ./scripts/install/gnome.sh
source ./scripts/install/zsh.sh
source ./scripts/install/dl-from-github.sh
source ./scripts/install/firefox.sh
source ./scripts/install/termux.sh
echo -e "${BLD}${BLU}All done.${RST}\n\n"
# recommended tools
source ./scripts/tool.sh
fi
}
[ "$(pwd)" = "${DOOTS}" ] && setup
main
# For custom installation comment out `stow_this config` from above, and
# uncomment this line of array below then remove some you don't want to include
# Note: Using stow will not work, so symlinking it instead
# TODO: make this interactive, and split into multiple file?
# doots=(
# alacritty
# atuin
# bat
# broot
# btop
# cava
# foot
# fzf
# git
# gtk-3.0
# gtk-4.0
# hypr
# kitty
# librewolf
# lsd
# neofetch
# nvim
# ripgrep
# tealdeer
# tmux
# zsh
# )
#
# for dot in "${doots[@]}"; do
# cd "$DOOTS/config"
# symlink "$(pwd)/$dot" "${CONFIG}"
# done