-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiler
executable file
·96 lines (75 loc) · 2.19 KB
/
dotfiler
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
#!/usr/bin/env bash
set -euo pipefail
# Config defaults
install_dir="${HOME}/.files"
src_dir=$(mktemp -d)
repo_url='https://github.com/cadeef/.files.git'
main() {
load_config
local option=${1:-ask}
if [[ ${option} == "--force" || ${option} == "-f" ]]; then
install
else
echo -n "This may overwrite existing files in your home directory. Are you sure? [y|n]: "
read -r -n 1 REPLY
echo
if [[ ${REPLY} =~ ^[Yy]$ ]]; then
install
fi
fi
unset option
}
get_source() {
git clone "${df_repo_url}" "${df_src_dir}"
}
install() {
get_source
run_scripts 'pre'
cd "${df_src_dir}" || (
echo "FATAL: Could not change to ${df_src_dir}"
exit 5
)
for dir in {bin,state,bash.d}; do
path="$df_install_dir/$dir"
[[ -d ${path} ]] || mkdir -v -p "${path}"
[[ -d "./${dir}" ]] && rsync -ah --no-perms "./${dir}/" "${path}/"
done
rsync -ah --no-perms ./dots/ "${HOME}/"
chmod +x ./dotfiler
cp -f ./dotfiler "${df_install_dir}/bin"
config_file="${df_install_dir}/config"
if [[ ! -f ${config_file} ]]; then
cat << EOF > "${install_dir}/config"
df_install_dir=${df_install_dir}
df_repo_url=${df_repo_url}
EOF
echo "Config file (${config_file}) didn't exist, you probably want to set df_git_user and df_git_email"
fi
run_scripts 'post'
echo -e '\nINSTALL COMPLETE\n\n'
# Don't bother following to .bash_profile, it gets checked elsewhere
# shellcheck disable=SC1090
source "${HOME}/.bash_profile"
}
load_config() {
# shellcheck disable=SC1090
[[ -r "${install_dir}/config" ]] && source "${install_dir}/config"
df_install_dir=${df_install_dir:-${install_dir}}
df_src_dir=${df_src_dir:-${src_dir}}
df_repo_url=${df_repo_url:-${repo_url}}
}
run_scripts() {
local prefix=${1:-none}
if [[ ${prefix} =~ ^pre|post$ ]]; then
for script in "${df_src_dir}/scripts/${prefix}"_*.sh; do
if [[ -r ${script} ]]; then
echo "Running ${script}"
bash "${script}"
fi
done
else
echo "run_scripts only accepts pre or post"
exit 1
fi
}
main "$@"