-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
111 lines (97 loc) · 2.19 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
set -e
DOT_DIRECTORY="${HOME}/dotfiles"
DOT_TARBALL="https://github.com/yyamada12/dotfiles/tarball/master"
REMOTE_URL="https://github.com/yyamada12/dotfiles.git"
# check the command exist
has() {
type "$1" > /dev/null 2>&1
}
# help
usage() {
name=`basename $0`
cat <<EOF
Usage:
$name [Argument] [Command]
Commands:
deploy
initialize
Arguments:
-f $(tput setaf 1)** warning **$(tput sgr0) Overwrite dotfiles.
-h Print help (this message)
EOF
exit 1
}
# options -f: overwrite -h: help
while getopts :f:h opt; do
case ${opt} in
f)
OVERWRITE=true
;;
h)
usage
;;
esac
done
shift $((OPTIND - 1))
# download dotfiles
if [ -n "${OVERWRITE}" -o ! -d ${DOT_DIRECTORY} ]; then
echo "Downloading dotfiles..."
rm -rf ${DOT_DIRECTORY}
mkdir ${DOT_DIRECTORY}
if has "git"; then
git clone --recursive "${REMOTE_URL}" "${DOT_DIRECTORY}"
else
curl -fsSLo ${HOME}/dotfiles.tar.gz ${DOT_TARBALL}
tar -zxf ${HOME}/dotfiles.tar.gz --strip-components 1 -C ${DOT_DIRECTORY}
rm -f ${HOME}/dotfiles.tar.gz
fi
echo $(tput setaf 2)Download dotfiles complete!. ✔︎$(tput sgr0)
fi
# Deploy
link_files() {
cd ${DOT_DIRECTORY}
for f in .??*
do
[[ ${f} = ".git" ]] && continue
ln -snfv ${DOT_DIRECTORY}/${f} ${HOME}/${f}
done
echo $(tput setaf 2)Deploy dotfiles complete!. ✔︎$(tput sgr0)
}
# Initialize
initialize() {
# install brew
if has "brew"; then
echo "$(tput setaf 2)Already installed Homebrew ✔︎$(tput sgr0)"
else
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# install with brew
if has "brew"; then
echo "Updating Homebrew..."
brew update && brew upgrade
[[ $? ]] && echo "$(tput setaf 2)Update Homebrew complete. ✔︎$(tput sgr0)"
cd ${DOT_DIRECTORY}
brew bundle
fi
# change shell to zsh
[ ${SHELL} != "/bin/zsh" ] && chsh -s /bin/zsh
echo "$(tput setaf 2)Initialize complete!. ✔︎$(tput sgr0)"
}
# arguments
command=$1
[ $# -gt 0 ] && shift
case $command in
deploy)
link_files
;;
init*)
link_files
initialize
;;
*)
usage
;;
esac
exit 0