-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·147 lines (126 loc) · 2.9 KB
/
bootstrap
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
#!/usr/bin/env bash
OS_ID=$(awk -F= ' /^ID=/ { gsub("\"", ""); print $2 } ' /etc/os-release)
ROOT=$(git rev-parse --show-toplevel)
source $ROOT/arch/configure
remove_home_files() {
echo "remove home files"
for file in aliases bash_profile bashrc env functions profile; do
if [[ $backup_files ]]; then
if [ -f "$HOME/.$file" ] && [ ! -L "$HOME/.$file" ]; then
$cmd mv "$HOME/.$file" "$HOME/.$file.bkp"
else
$cmd rm -f "$HOME/.$file"
fi
fi
done
}
remove_config_files() {
echo "remove config files"
for file in mimeapps.list user-dirs.dirs user-dirs.locale; do
if [[ $backup_files ]]; then
if [ -f "$HOME/.$file" ] && [ ! -L "$HOME/.$file" ]; then
$cmd mv "$HOME/.config/$file" "$HOME/.config/$file.bkp"
else
$cmd rm -f "$HOME/.config/$file"
fi
fi
done
}
__get_xmanager_id() {
if [[ $hdpi_config == false ]]; then
echo "xmanager-fhd"
else
echo "xmanager-hdpi"
fi
}
install() {
echo "install configurations"
local dir=$ROOT
local stow_config="--dir=$dir --target=$HOME --dotfiles"
echo "stow configuration: " $stow_config
echo $stow_config >$dir/.stowrc
local xmanager=$(__get_xmanager_id)
$cmd stow -v git/ terminator/ bash/ dunst/ emacs/ gtk-3.0/ gtk-4.0/ nvim/ xdg-dirs/ picom/ rofi/ starship/ tmux/ ${xmanager}/ bin/ zathura/ bspwm/ polybar/ sxhkd/ wallpaper/ networkmanager-dmenu/ clang/ ranger/ bat/ kitty/ fish/ neofetch/
echo "done"
}
uninstall() {
echo "uninstall configurations"
local xmanager=$(__get_xmanager_id)
$cmd stow -v -D git/ terminator/ bash/ dunst/ emacs/ gtk-3.0/ gtk-4.0/ nvim/ xdg-dirs/ picom/ rofi/ starship/ tmux/ bin/ zathura/ bspwm/ polybar/ sxhkd/ wallpaper/ ${xmanager}/ networkmanager-dmenu/ clang/ ranger/ bat/ kitty/ fish/ neofetch/
echo "done"
}
usage() {
echo -e "\nUsage:\n"
echo -e "-c - to install all deps"
echo -e "-i - to install applications (default)"
echo -e "-u - to uninstall all configurations"
echo -e "-b - move files to backup instead remove"
echo -e "-h - to install hidpi config (default)"
echo -e "-f - to install full hd config"
}
dry_run_exec() {
if [[ $dry_run ]]; then
cmd=echo
else
cmd=''
fi
}
handle() {
install_deps=false
install_config=true
hdpi_config=true
backup_files=false
dry_run=false
if [[ $# -eq 0 ]]; then
usage
exit
fi
while [ $# -ge 1 ]; do
case "$1" in
-b | --backup)
backup_files=true
;;
-c | --configure)
install_deps=true
;;
-f | --fhd)
hdpi_config=false
;;
-h | --hdpi)
hdpi_config=true
;;
-i | --install)
install_config=true
;;
-u | --uninstall)
install_config=false
;;
-n| --dry-run)
dry_run_exec
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
shift
done
}
main() {
handle "$@"
if [[ $install_deps == true ]]; then
configure
fi
if [[ $install_config == true ]]; then
remove_home_files
remove_config_files
install
else
uninstall
fi
}
main "$@"