-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·216 lines (184 loc) · 5.27 KB
/
start.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash
# exit when a command fails
set -o errexit
# exit when undeclared variable is used
# set -o nounset
# trace what gets executed
# set -o xtrace
##
# Define utility functions
##
text_indentation=" "
# Usage: log_task <message>
# Description: Custom task log.
function log_task() {
echo " $1"
}
# Usage: log_subtask <message>
# Description: Custom subtask log.
function log_subtask() {
echo "$text_indentation $1"
}
# Usage: log_subtask_success
# Description: Log subtask that is completed.
function log_subtask_success() {
msg=${1:-""}
echo "$text_indentation$text_indentation Completed * $msg"
}
# Usage: log_subtask_info <message>
# Description: Log subtask information message.
function log_subtask_info() {
echo "$text_indentation$text_indentation $1"
}
# Usage: log_subtask_error
# Description: Log subtask that is failed.
function log_subtask_error() {
echo "$text_indentation$text_indentation Failed * $1"
}
# Usage: backup <file_name>
# Description: Check if the file exists and backup it.
# IMPORTANT: Backup only real files, NOT symlinks
function backup() {
local file_name=$1
local path_source=$2
local path_destination
path_destination="$path_source.backup.$(date +%d-%m-%Y--%H-%M-%S)"
log_subtask "Backup file $file_name"
# Does the file already exist?
if [[ -f $path_source ]]; then
# Is it a symlink?
if [[ ! -L $path_source ]]; then
mv "$path_source" "$path_destination"
log_subtask_success "Moved your old $path_source file to $path_destination"
else
log_subtask_info "Delete file ${file_name##*/}, because it exists as a symlink in your home directory."
rm -rf "$path_source"
fi
else
log_subtask_info "Skipping * There is not file named ${file_name##*/} in the directory. $path_source"
fi
}
# Usage: symlink <file_name, path_to_source, path_to_destination>
# Description: Check if the file exists and replace it with a symlink.
function symlink() {
local file_name=$1
local path_source=$2
local path_destination=$3
log_subtask "Symlinking file $file_name"
# Does the file already exist?
if [[ ! -f $path_destination ]]; then
# Is it a symlink?
if [[ ! -L $path_destination ]]; then
log_subtask_success
ln -s "$path_source" "$path_destination"
else
log_subtask_info "Rebuild * The file is a symlink!"
rm -rf "$path_destination"
ln -s "$path_source" "$path_destination"
fi
else
log_subtask_info "Skipping * The file already exists!"
fi
}
##
# Begin script
##
root_dir="$HOME/dotfiles"
echo ""
echo "******************************************************************************************"
echo "# dotfiles"
echo "# IMPORTANT: The script is meant to be used on Fedora Silverblue or Fedora workstation."
echo "******************************************************************************************"
echo ""
echo "Do you want to proceed?"
select choice_start in "Yes" "No"; do
case $choice_start in
Yes ) break;;
No ) exit;;
esac
done
if [[ $choice_start == "Yes" ]]; then
clear
fi
echo "Do you want to modify the files from your home folder?"
select choice_home_files in "Yes" "No"; do
case $choice_home_files in
Yes ) break;;
No ) break;;
esac
done
echo "Do you want to modify GNOME settings?"
select choice_gnome_settings in "Yes" "No"; do
case $choice_gnome_settings in
Yes ) break;;
No ) break;;
esac
done
echo "Do you want to reset some common GNOME settings?"
select choice_gnome_settings_reset in "Yes" "No"; do
case $choice_gnome_settings_reset in
Yes ) break;;
No ) break;;
esac
done
echo "Do you want to configure git?"
select choice_git in "Yes" "No"; do
case $choice_git in
Yes ) break;;
No ) break;;
esac
done
echo "Do you want to setup window manager?"
select choice_wm in "Yes" "No"; do
case $choice_wm in
Yes ) break;;
No ) break;;
esac
done
echo "Do you want to install just?"
select choice_just in "Yes" "No"; do
case $choice_just in
Yes ) break;;
No ) break;;
esac
done
clear
# Loop through all files in /files folder, backup them if they exist in home directory and symlink the new onces.
if [[ $choice_home_files == "Yes" ]]; then
log_task "Backup dot files and replace them with symlinks to the new files."
source "$root_dir"/tasks/_setup_bash.sh
setup-bash "$root_dir"/files/bash
echo ""
fi
if [[ $choice_gnome_settings == "Yes" ]]; then
log_task "Update GNOME settings(dconf)."
source "$root_dir"/tasks/_update_gnome_settings.sh
update_gnome_settings
echo ""
fi
if [[ $choice_gnome_settings_reset == "Yes" ]]; then
log_task "Reset GNOME settings(dconf)."
source "$root_dir"/tasks/_reset_some_gnome_settings.sh
reset_some_gnome_settings
echo ""
fi
if [[ $choice_git == "Yes" ]]; then
log_task "Setup git."
source "$root_dir"/tasks/_setup_git.sh
setup_git
echo ""
fi
if [[ $choice_wm == "Yes" ]]; then
log_task "Setup window manager."
source "$root_dir"/tasks/_window_manager.sh
setup_WM "$root_dir"/files/.config
echo ""
fi
if [[ $choice_just == "Yes" ]]; then
log_task "Installing just."
source "$root_dir"/tasks/_install_just.sh
install_just
echo ""
fi
echo "👌 Awesome, all set."
echo ""