-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
202 lines (173 loc) · 4.39 KB
/
setup.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
#
# Functions;
#
function show_usage() {
echo "Usage: $(basename $0) [-dh]"
exit 1
}
function get_os_type() {
local host_os
if [[ -z $1 ]]; then
host_os="$(uname)"
else
host_os="$1"
fi
local environment
if echo "${host_os}" | grep -i ^mingw.* >/dev/null; then
environment="windows"
elif [[ "${host_os}" == "Linux" ]]; then
environment="linux"
elif [[ "${host_os}" == "Darwin" ]]; then
environment="macos"
else
environment="unknown"
fi
echo "${environment}"
}
function get_hostname() {
local platform_os="$1"
local name
if [[ "${DEBUG_MODE}" == "true" ]]; then
if [[ ${platform_os} == "windows" ]]; then
name="WinPC_00"
elif [[ ${platform_os} == "macos" ]]; then
name="Watashi-no-Mac"
elif [[ ${platform_os} == "linux" ]]; then
name="Ubuntu-PC"
else
name="unknown"
fi
else
if [[ ${platform_os} == "windows" ]]; then
name="$(hostname)"
elif [[ ${platform_os} == "macos" ]]; then
name="$(hostname)"
elif [[ ${platform_os} == "linux" ]]; then
name="" # Currently do nothing
else
name="unknown"
fi
fi
echo "${name}"
}
function get_platform_env() {
local arg=$1
local os=$(get_os_type ${arg})
local name="$(get_hostname ${os})"
echo ${os} "${name}"
}
#
# main()
#
while getopts d:h OPT; do
case ${OPT} in
d)
DEBUG_MODE="true"
DEBUG_HOST_OS="${OPTARG}"
;;
h)
show_usage
;;
\?)
show_usage
;;
esac
done
shift $((OPTIND - 1))
echo "### Setup dotfiles ###"
echo -n "### Check Environment... "
if [[ "${DEBUG_MODE}" == "true" ]]; then
ENVIRONMENT=( $(get_platform_env ${DEBUG_HOST_OS}) )
else
ENVIRONMENT=( $(get_platform_env) )
fi
echo "OS=${ENVIRONMENT[0]} HOSTNAME=${ENVIRONMENT[1]} ###"
if [[ "${ENVIRONMENT[0]}" != "windows" ]] \
&& [[ "${ENVIRONMENT[0]}" != "macos" ]] \
&& [[ "${ENVIRONMENT[0]}" != "linux" ]]
then
echo "Unexpected environment: ${ENVIRONMENT[0]}"
echo "Abort."
exit 1
fi
echo "### Export ENVIRONMENT vars ###"
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\techo \"DOTFILES_ENV_OS=${ENVIRONMENT[0]}\" >> ~/dotfiles/env/environment_vars"
echo -e "\techo \"DOTFILES_ENV_HOSTNAME=${ENVIRONMENT[1]}\" >> ~/dotfiles/env/environment_vars"
else
mkdir -p ~/dotfiles/env/
if [[ -f ~/dotfiles/env/environment_vars ]]; then
rm -f ~/dotfiles/env/environment_vars
fi
echo "DOTFILES_ENV_OS=${ENVIRONMENT[0]}" >> ~/dotfiles/env/environment_vars
echo "DOTFILES_ENV_HOSTNAME=${ENVIRONMENT[1]}" >> ~/dotfiles/env/environment_vars
fi
echo "### Make symlinks..."
# tig
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv dotfiles/tig/tigrc ~/.tigrc"
else
ln -sfv dotfiles/tig/tigrc ~/.tigrc
fi
# bash
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv dotfiles/bash/bash_profile ~/.bash_profile"
echo -e "\tln -sfv dotfiles/bash/bashrc ~/.bashrc"
else
ln -sfv dotfiles/bash/bash_profile ~/.bash_profile
ln -sfv dotfiles/bash/bashrc ~/.bashrc
fi
# vim
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv dotfiles/vim/vimrc ~/.vimrc"
echo -e "\tln -sfv dotfiles/vim/gvimrc ~/.gvimrc"
else
ln -sfv dotfiles/vim/vimrc ~/.vimrc
ln -sfv dotfiles/vim/gvimrc ~/.gvimrc
fi
mkdir -p ~/.config
# gitconfig
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv ~/dotfiles/git ~/.config/git"
else
ln -sfv ~/dotfiles/git ~/.config/git
fi
# ranger
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv ~/dotfiles/ranger/config ~/.config/ranger"
else
ln -sfv ~/dotfiles/ranger/config ~/.config/ranger
fi
# broot
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e"echo \t\"DOTFILES_ENV_CONFIG_BROOT_ENABLE=y\" >> ~/dotfiles/env/environment_vars"
echo -e "\tln -sfv ~/dotfiles/broot ~/.config/broot"
else
if [[ -e "/usr/local/bin/broot" ]]; then
echo "DOTFILES_ENV_CONFIG_BROOT_ENABLE=y" >> ~/dotfiles/env/environment_vars
ln -sfv ~/dotfiles/broot ~/.config/broot
fi
fi
# wezterm
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv ~/dotfiles/wezterm ~/.config/wezterm"
else
ln -sfv ~/dotfiles/wezterm ~/.config/wezterm
fi
# gh
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tmkdir -p ~/.config/gh"
echo -e "\tln -sfv ~/dotfiles/gh/config.yml ~/.config/gh/config.yml"
else
mkdir -p ~/.config/gh
ln -sfv ~/dotfiles/gh/config.yml ~/.config/gh/config.yml
fi
# editorconfig
if [[ "${DEBUG_MODE}" == "true" ]]; then
echo -e "\tln -sfv ~/dotfiles/editorconfig/editorconfig ~/.editorconfig"
else
ln -sfv ~/dotfiles/editorconfig/editorconfig ~/.editorconfig
fi
echo "### Done. ###"
exit 0