-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-dotfiles.sh
executable file
·60 lines (50 loc) · 1.49 KB
/
setup-dotfiles.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
#!/usr/bin/env bash
CHECKOUT_DIR="${HOME}/src"
CHECKOUT_REPOSITORY="dotfiles"
function link_file() {
ORIG_FILE=$1
TARGET_FILE=$2
# backup exist file
if [[ -f "${TARGET_FILE}" || -h "${TARGET_FILE}" ]]; then
mv -fv "${TARGET_FILE}" "${TARGET_FILE}.bak"
fi
ln -s "${ORIG_FILE}" "${TARGET_FILE}"
}
function setup_clone_dir() {
if [[ ! -d "${CHECKOUT_DIR}" ]]; then
mkdir "${CHECKOUT_DIR}"
fi
# shellcheck disable=SC2164
cd "${CHECKOUT_DIR}"
for REPO in ${CHECKOUT_REPOSITORY}; do
if [[ ! -d "${REPO}" ]]; then
git clone "https://github.com/ssobue/${REPO}.git"
fi
done
}
function setup_mac_setting() {
link_file "${CHECKOUT_DIR}/dotfiles/zshenv.mac" "${HOME}/.zshenv"
link_file "${CHECKOUT_DIR}/dotfiles/zshrc.mac" "${HOME}/.zshrc"
link_file "${CHECKOUT_DIR}/dotfiles/gitconfig" "${HOME}/.gitconfig"
link_file "${CHECKOUT_DIR}/dotfiles/vimrc" "${HOME}/.vimrc"
}
function setup_linux_setting() {
link_file "${CHECKOUT_DIR}/dotfiles/zshenv.linux" "${HOME}/.zshenv"
link_file "${CHECKOUT_DIR}/dotfiles/zshrc.linux" "${HOME}/.zshrc"
link_file "${CHECKOUT_DIR}/dotfiles/gitconfig" "${HOME}/.gitconfig"
link_file "${CHECKOUT_DIR}/dotfiles/vimrc" "${HOME}/.vimrc"
}
# check git command
if [[ ! -x /usr/bin/git && ! -x /usr/local/bin/git ]]; then
exit 1
fi
# choose architecture
if [[ "$(uname)" = "Linux" ]]; then
setup_clone_dir
setup_linux_setting
elif [[ "$(uname)" = "Darwin" ]]; then
setup_clone_dir
setup_mac_setting
else
exit 2
fi