-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-dotfiles
executable file
·138 lines (107 loc) · 4.22 KB
/
install-dotfiles
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
#!/usr/bin/env bash
## Copyright (C) 2019-2020 Ulises Jeremias Cornejo Fandos
## Licensed under MIT
##
## @script.name [OPTION] ARGUMENTS...
##
## Options:
## -h, --help Help.
## -c, --clear Will remove existing dotfiles.
##
## --os=OS_NAME Operating System. Posible values: common | arch-linux | debian | ...
## where common is supposed to work correctly with any linux distro.
## `common` is set as default value for this flag.
## --wms=COMMA_SEPARATED_WMS Window managers. Posible wms: i3, openbox
## --log-file=LOG_FILE_PATH Logs file path, is /tmp/install_progress_log_$(date +'%m-%d-%y_%H:%M:%S').txt by default.
## --dotfiles-dir=OUTPUT_PATH Dotfiles output dir, is ~/dotfiles by default.
##
ROOT=$(dirname "$0")
source "${ROOT}"/../util/opts/opts.sh || exit
source "${ROOT}"/../util/logs.sh || exit
# override OS with a correct value with the given params
source "${ROOT}"/../util/os.sh || exit
#==========================================
# Default argument values and preprocessing
#==========================================
os=${os:-""}
time_str=$(date +'%m-%d-%y_%H:%M:%S')
log_file=${log_file:-"/tmp/install_progress_log_$time_str.txt"}
dotfiles_dir=${dotfiles_dir:-"${HOME}/dotfiles"}
wms=${wms:-""}
[ ! -f "${log_file}" ] && touch "${log_file}"
if [ ! -d "${dotfiles_dir}" ] || [ -n "${clear}" ]; then
describe "Removing existing dotfiles"
# Delete existing dotfiles and folders
rm -rf "${dotfiles_dir}" >/dev/null 2>&1
# Create dotfiles folder
mkdir "${dotfiles_dir}"
mkdir "${dotfiles_dir}"/config
mkdir "${dotfiles_dir}"/custom-config
log_success "Success" "${config}" "${log_file}"
fi
#==========================================
# Copy bin files and create symlinks
#==========================================
describe "Installing binaries" 0
cp -rf "${ROOT}"/../common/bin "${dotfiles_dir}"
if [ -d "${ROOT}/../${os}/bin" ]; then
cp -rf "${ROOT}"/../"${os}"/bin "${dotfiles_dir}"
fi
if [ ! -d "${HOME}/.local/bin" ]; then
mkdir ~/.local/bin
fi
for bin_path in "${dotfiles_dir}"/bin/*; do
bin=$(basename "${bin_path}")
chmod +x "${bin_path}"
sudo rm -rf ~/.local/bin/"${bin}" >/dev/null 2>&1
ln -sf "${bin_path}" ~/.local/bin/"${bin}"
done
echo
#==========================================
# Copy dotfiles and execute dotfiles
# install strategy
#==========================================
success=0
failed=0
describe "Installing dotfiles" 0
echo
for config_path in "${ROOT}"/../common/config/*; do
config=$(basename "${config_path}")
describe "Installing ${config} dotfiles"
os_config_path=${config_path}
if [ -x "${ROOT}/../${os}/config/${config}/install" ]; then
os_config_path="${ROOT}/../${os}/config/${config}"
fi
cp -rf "${os_config_path}" "${dotfiles_dir}"/config
if bash "${dotfiles_dir}"/config/"${config}"/install; then
log_success "Installed successfully" "${config}" "${log_file}"
((success += 1))
else
log_failed "Installation failed" "${config}" "${log_file}"
((failed += 1))
fi
done
all=$((success + failed))
echo
echo "${GREEN}Success: ${success} ${RED}Failed: ${failed}${RESET} Total: ${all}"
describe "Setting up default and custom configs"
echo
echo
rm -rf "${dotfiles_dir}"/default-config >/dev/null 2>&1
cp -rf "${ROOT}"/../default-config/common "${dotfiles_dir}"/default-config
# create new bin directories
if [ ! -d "${dotfiles_dir}"/custom-config/bin ]; then
cp -rf "${dotfiles_dir}"/default-config/bin "${dotfiles_dir}"/custom-config
fi
# add README for custom config
if [ ! -e "${dotfiles_dir}"/custom-config/README.md ]; then
cp -rf "${dotfiles_dir}"/default-config/README.md "${dotfiles_dir}"/custom-config
fi
for wm in xfce4 $(echo "${wms}" | tr ',' '\n'); do
[ -e "${ROOT}/../default-config/wm/${wm}/install" ] || continue
cp -rf "${ROOT}"/../default-config/wm/"${wm}" "${dotfiles_dir}"/default-config
cp -rf "${ROOT}"/../default-config/wm/"${wm}" "${dotfiles_dir}"/custom-config
chmod +x "${dotfiles_dir}"/default-config/"${wm}"/install
done
chmod +x "${dotfiles_dir}"/default-config/install
"${dotfiles_dir}"/default-config/install