-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·95 lines (80 loc) · 2.31 KB
/
install
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
#!/bin/bash
# OS specific stuff
case $(uname) in
Darwin)
BASH_CONFIG="profile"
INSTALL_DIR="/Users/${USER}"
;;
*)
BASH_CONFIG="bashrc"
INSTALL_DIR="${HOME}"
esac
GIT_URL="https://github.com/tiwilliam/dotfiles.git"
STORAGE_DIR="${INSTALL_DIR}/.dotfiles"
function link_file {
link=true
if [ -f "$2" ] || [ -d "$2" ] || [ -h "$2" ]; then
read -p "$2: File or directory already exists - overwrite? [y/N] "
if [ "${REPLY}" == "y" ]; then
rm -rf "$2"
else
link=false
fi
fi
if [ ${link} == true ]; then
ln -s "$1" "$2"
fi
}
function download_dotfiles {
# Get latest files
if [ -d "${STORAGE_DIR}" ]; then
pushd ${STORAGE_DIR} > /dev/null
git pull -q
git submodule init -q
git submodule update -q
popd > /dev/null
else
git clone ${GIT_URL} ${STORAGE_DIR} -q
pushd ${STORAGE_DIR} > /dev/null
git submodule init -q
git submodule update -q
popd > /dev/null
fi
}
function install_gitconfig {
destination="${INSTALL_DIR}/.gitconfig"
if [ -f "${destination}" ]; then
read -p "Do you want to replace your git config? [y/N] "
else
REPLY="y"
fi
if [ "${REPLY}" == "y" ]; then
echo "What is your git name?"
read -e git_name
echo "What is your git email?"
read -e git_email
sed -e "s/NAME/$git_name/g" -e "s/EMAIL/$git_email/g" "${STORAGE_DIR}/gitconfig" > "${destination}"
fi
}
function install_dotfiles {
for file in $(find ${STORAGE_DIR} -maxdepth 1 -name "*.symlink"); do
basename=$(basename "${file%.*}")
# Support for both Linux and Darwin
[ "${basename}" == "bashrc" ] && basename=${BASH_CONFIG}
link_file "${file}" "${INSTALL_DIR}/.${basename}"
done
}
function install_homebrew {
link_file "${STORAGE_DIR}/Brewfile" "${INSTALL_DIR}/Brewfile"
which brew > /dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew bundle
brew bundle --force cleanup
}
function install_keys {
link_file "${INSTALL_DIR}/Documents/.ssh" "${INSTALL_DIR}/.ssh"
}
download_dotfiles
install_gitconfig
install_dotfiles
install_homebrew
install_keys