-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·87 lines (68 loc) · 2.34 KB
/
install.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
#!/usr/bin/env zsh
SHA1N_PROFILE_HOME="${${(%):-%x}:a:h}"
source "$SHA1N_PROFILE_HOME/scripts/lib.zsh"
source "$SHA1N_PROFILE_HOME/include/exports"
dotzshrc="$HOME/.zshrc"
dotfiles_dir="$SHA1N_PROFILE_HOME/dotfiles"
dirs=("$HOME/.local/bin" "$CODE/w")
function validate_shell_rc_file() {
__profile_log_info "Observing $dotzshrc..."
# We are not going to create .zshrc. If it doesn't exist something is probably off
if [[ ! -f "$dotzshrc" ]]; then
__profile_log_warn "the file '$dotzshrc' does not exist. An empty one will be created."
touch "$dotzshrc"
fi
local existing_source=$(grep -e '^source .*/\load.zsh' "$dotzshrc")
if [[ ! -z "$existing_source" ]]; then
__profile_log_warn "the following 'source' command is already in your .zshrc profile: $existing_source"
return 1
fi
}
function install_source_command() {
__profile_log_info "installing profile..."
echo "source '$SHA1N_PROFILE_HOME/load.zsh'" >>"$dotzshrc"
if [[ "$?" == "0" ]]; then
__profile_log_info "installed successfully!"
__profile_log_info "to verify installation start new session or source $dotzshrc"
fi
}
function link_dotfile() {
if [[ -f "$HOME/$1" ]]; then
__profile_log_warn "the file '${HOME}/${1}' already exists. Skipping..."
else
__profile_log_info "linking $1..."
ln -s "$dotfiles_dir/$1" "$HOME/$1"
return "$?"
fi
}
function link_dotfiles() {
__profile_log_info "linking dot files..."
for file in $(find "$dotfiles_dir" -type f | awk -F/ '{print $NF}'); do
link_dotfile "$file" || __pe_log_error "failed to link '$file'!"
done
}
function create_directory() {
if [[ -d "$1" ]]; then
__profile_log_warn "the directory '$1' already exists. Skipping..."
else
__profile_log_info "creating directory $1..."
mkdir -p "$1"
return "$?"
fi
}
function create_directories() {
__profile_log_info "creating directories..."
for dir in "${dirs[@]}"; do
create_directory "$dir" || __pe_log_error "failed to create '$dir'!"
done
}
function update_submodules() {
__profile_log_info "updating submodules..."
git submodule update --init
return "$?"
}
update_submodules && __profile_log_success "submodules updated successfully" || __profile_log_warn "failed to update submodules!"
link_dotfiles
create_directories
validate_shell_rc_file && install_source_command
__profile_log_info "done!"