-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·269 lines (230 loc) · 8.58 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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/sh
set -eu
DOTFILES_HOME="$(dirname "$0")"
. "$DOTFILES_HOME/bin/lib/polyfills.sh"
DOTFILES_HOME="$(realpath "$DOTFILES_HOME")"
DOTFILES_ENV="${DOTFILES_ENV:-default}"
DOTFILES_ENV_USER="${DOTFILES_ENV_USER:-$USER}"
DOTFILES_ENV_GROUP="${DOTFILES_ENV_GROUP:-$(id -gn)}"
DST_HOME="$HOME"
DOTFILES_CUSTOM_REPO_URL="${DOTFILES_CUSTOM_REPO_URL:-git@github.com:n1amr/dotfiles.custom}"
interactive='true'
while [ $# != 0 ]; do
case "$1" in
--user-home) DST_HOME="$2"; shift ;;
--dotfiles-path) DOTFILES_HOME="$2"; shift ;;
--env|-e) DOTFILES_ENV="$2"; shift ;;
--user|-u) DOTFILES_ENV_USER="$2"; shift ;;
--group|-g) DOTFILES_ENV_GROUP="$2"; shift ;;
--no-interactive|-f) interactive='false' ;;
--interactive|-i) interactive='true' ;;
*)
echo "Invalid syntax. Unknown argument: '$1'."
exit 1
;;
esac
shift
done
if [ "$interactive" = 'true' ]; then
# Set DOTFILES_ENV
printf "Enter your environment name [%s]: " "$DOTFILES_ENV"
read -r response
if [ ! -z "$response" ]; then
DOTFILES_ENV="$response"
fi
# Set DST_HOME
printf "Enter your home directory [%s]: " "$DST_HOME"
read -r response
if [ ! -z "$response" ]; then
DST_HOME="$(realpath "$response")"
fi
# Set DOTFILES_ENV_USER
printf "Enter your user name [%s]: " "$DOTFILES_ENV_USER"
read -r response
if [ ! -z "$response" ]; then
DOTFILES_ENV_USER="$response"
fi
# Set DOTFILES_ENV_GROUP
printf "Enter your user's primary group name [%s]: " "$DOTFILES_ENV_GROUP"
read -r response
if [ ! -z "$response" ]; then
DOTFILES_ENV_GROUP="$response"
fi
# Set DOTFILES_HOME
printf "Enter dotfiles directory [%s]: " "$DOTFILES_HOME"
read -r response
if [ ! -z "$response" ]; then
DOTFILES_HOME="$(realpath "$response")"
fi
# Set custom repo
printf "Enter dotfiles custom repo url [%s]: " "$DOTFILES_CUSTOM_REPO_URL"
read -r response
if [ ! -z "$response" ]; then
DOTFILES_CUSTOM_REPO_URL="$(realpath "$response")"
fi
fi
bakmv () {
mv -v "$1" "$1.bak.$(date -u +"%Y%m%d%H%M%S")"
}
DOTFILES_CUSTOM_DIR="$DOTFILES_HOME/custom"
set +e
(
if [ ! -e "$DOTFILES_CUSTOM_DIR/.git" ]; then
if [ -e "$DOTFILES_CUSTOM_DIR" ]; then
bakmv "$DOTFILES_CUSTOM_DIR"
fi
echo "dotfiles: Cloning custom repo to dotfiles..."
git clone -v --recursive "$DOTFILES_CUSTOM_REPO_URL" "$DOTFILES_CUSTOM_DIR"
fi
)
set -e
export DOTFILES_ENV
export DOTFILES_HOME
export PATH="$DOTFILES_HOME/bin:$PATH"
if [ "$interactive" = 'true' ]; then
safe_link () { "$DOTFILES_HOME/bin/ln-safe" "$@"; }
else
safe_link () { "$DOTFILES_HOME/bin/ln-safe" -f "$@"; }
fi
DOTFILES_DIR="$DST_HOME/.dotfiles"
if [ ! "$DOTFILES_DIR" -ef "$DOTFILES_HOME" ]; then
if [ -e "$DOTFILES_DIR" ]; then
bakmv "$DOTFILES_DIR"
fi
ln -sfn -v "$DOTFILES_HOME" "$DOTFILES_DIR"
fi
test "$DOTFILES_DIR" -ef "$DOTFILES_HOME"
mkdir -pv "$DOTFILES_CUSTOM_DIR"
mkdir -pv "$DOTFILES_CUSTOM_DIR/bin"
mkdir -pv "$DOTFILES_CUSTOM_DIR/config/dotfiles"
mkdir -pv "$DOTFILES_CUSTOM_DIR/history"
touch "$DOTFILES_CUSTOM_DIR/history/shell_history"
touch "$DOTFILES_CUSTOM_DIR/history/shell_history.bak"
config_files="
driverc
emacs
emacs.d
fonts
gitconfig
gitignore
inputrc
irbrc
profile
sqliterc
tcshrc
tmux.conf
vim
wgetrc
xinitrc
xsessionrc
zshenv
"
for cf in $config_files; do
safe_link "$DST_HOME/.$cf" "$DOTFILES_HOME/config/$cf"
done
for cf in bashrc zshrc; do
safe_link "$DST_HOME/.$cf" "$DOTFILES_HOME/config/shellrc"
done
# Custom config directories
mkdir -pv "$DOTFILES_HOME/custom/config/feh/"
mkdir -pv "$DOTFILES_HOME/custom/config/mutt/"
mkdir -pv "$DOTFILES_HOME/custom/config/ranger/"
mkdir -pv "$DOTFILES_HOME/custom/history/"
safe_link "$DST_HOME/.config/cmus/" "$DOTFILES_HOME/config/cmus/"
safe_link "$DST_HOME/.config/feh/" "$DOTFILES_HOME/custom/config/feh/"
safe_link "$DST_HOME/.config/ranger/" "$DOTFILES_HOME/custom/config/ranger/"
safe_link "$DST_HOME/.mutt/" "$DOTFILES_HOME/config/mutt/"
DOTFILES_ENV="${DOTFILES_ENV:-default}"
DOTFILES_ENV_HOME="$DST_HOME"
export interactive
export DOTFILES_ENV
export DOTFILES_HOME
export DST_HOME
export DOTFILES_ENV_HOME
global_custom_install="$DOTFILES_CUSTOM_DIR/custom_install"
env_custom_install="$(custom-env-resolve 'custom_install')"
if [ -x "$env_custom_install" ]; then
"$env_custom_install"
elif [ -x "$global_custom_install" ]; then
"$global_custom_install"
fi
safe_link "$DST_HOME/.config/Code/User/" "$DOTFILES_HOME/config/vscode/User/"
safe_link "$DST_HOME/.config/feh/keys" "$DOTFILES_HOME/config/feh/keys"
safe_link "$DST_HOME/.config/i3/" "$DOTFILES_HOME/config/i3/"
safe_link "$DST_HOME/.config/nvim/init.vim" "$DOTFILES_HOME/config/nvim.vim"
safe_link "$DST_HOME/.config/ranger/commands.py" "$DOTFILES_HOME/config/ranger/commands.py"
safe_link "$DST_HOME/.config/ranger/rc.conf" "$DOTFILES_HOME/config/ranger/rc.conf"
safe_link "$DST_HOME/.config/ranger/rifle.conf" "$DOTFILES_HOME/config/ranger/rifle.conf"
safe_link "$DST_HOME/.config/ranger/scope.sh" "$DOTFILES_HOME/config/ranger/scope.sh"
safe_link "$DST_HOME/.config/vlc/" "$DOTFILES_HOME/config/vlc/"
safe_link "$DST_HOME/.gitconfig.env" "$(custom-env-resolve 'config/gitconfig.env')"
safe_link "$DST_HOME/.ipython/profile_default/" "$DOTFILES_HOME/config/ipython/profile_default/"
safe_link "$DST_HOME/.irssi/" "$DOTFILES_HOME/config/irssi/"
safe_link "$DST_HOME/.jupyter/custom" "$(custom-env-resolve 'config/jupyter/custom')"
safe_link "$DST_HOME/.jupyter/jupyter_notebook_config.py" "$(custom-env-resolve 'config/jupyter/jupyter_notebook_config.py')"
safe_link "$DST_HOME/.jupyter/nbconfig/notebook.json" "$(custom-env-resolve 'config/jupyter/nbconfig/notebook.json')"
safe_link "$DST_HOME/.marks.tsv" "$(custom-env-resolve 'config/marks.tsv')"
safe_link "$DST_HOME/.shell_history" "$DOTFILES_CUSTOM_DIR/history/shell_history"
safe_link "$DST_HOME/.shell_history.bak" "$DOTFILES_CUSTOM_DIR/history/shell_history.bak"
safe_link "$DST_HOME/.vimrc" "$DOTFILES_HOME/config/vim/vimrc"
generate_global_dotfiles_env () {
local env_file="$1"
touch "$env_file"
echo "Note: Creating new dotfiles.env file at $env_file:"
echo "# ===== Start ====="
(
echo '#!/bin/sh'
echo
echo "export DOTFILES_ENV=\"\${DOTFILES_ENV:-$DOTFILES_ENV}\""
echo "export DOTFILES_ENV_HOME=\"\${DOTFILES_ENV_HOME:-$DOTFILES_ENV_HOME}\""
echo "export DOTFILES_ENV_USER=\"\${DOTFILES_ENV_USER:-$DOTFILES_ENV_USER}\""
echo "export DOTFILES_ENV_GROUP=\"\${DOTFILES_ENV_GROUP:-$DOTFILES_ENV_GROUP}\""
echo "export DOTFILES_HOME=\"\${DOTFILES_HOME:-$DOTFILES_ENV_HOME/.dotfiles}\""
echo
echo "export PATH=\"\$DOTFILES_HOME/custom/bin:\$DOTFILES_HOME/bin:\$PATH\""
echo
echo "export NDENV_ROOT=\"\$DOTFILES_ENV_HOME/.ndenv\""
echo "export PYENV_ROOT=\"\$DOTFILES_ENV_HOME/.pyenv\""
echo "export RBENV_ROOT=\"\$DOTFILES_ENV_HOME/.rbenv\""
echo "export BUILD_PREFIX=\"\$DOTFILES_ENV_HOME/.local\""
) | tee -a "$env_file"
echo "# ===== End ====="
}
GLOBAL_DOTFILES_ENV_FILE="$DOTFILES_CUSTOM_DIR/dotfiles.env"
if [ ! -f "$GLOBAL_DOTFILES_ENV_FILE" ]; then
generate_global_dotfiles_env "$GLOBAL_DOTFILES_ENV_FILE"
fi
if [ "$DOTFILES_ENV" != 'default' ]; then
DOTFILES_ENV_FILE="$DOTFILES_CUSTOM_DIR/env/$DOTFILES_ENV/dotfiles.env"
else
DOTFILES_ENV_FILE="$GLOBAL_DOTFILES_ENV_FILE"
fi
if [ "$DOTFILES_ENV" != 'default' ] && [ ! -f "$DOTFILES_ENV_FILE" ]; then
{
echo "#!/bin/sh"
echo
echo "export DOTFILES_ENV='$DOTFILES_ENV'"
echo "export DOTFILES_ENV_HOME='$DOTFILES_ENV_HOME'"
echo "export DOTFILES_ENV_USER='$DOTFILES_ENV_USER'"
echo "export DOTFILES_ENV_GROUP='$DOTFILES_ENV_GROUP'"
echo "export DOTFILES_HOME='$DOTFILES_HOME'"
echo ". \"\$DOTFILES_HOME/custom/dotfiles.env\""
echo
echo "# Add environent dependent config in this file"
} > "$DOTFILES_ENV_FILE"
fi
safe_link "$DST_HOME/.dotfiles.env" "$DOTFILES_ENV_FILE"
initialize () {
. "$DST_HOME/.dotfiles.env" # test sourcing
"$DOTFILES_HOME/bin/marks" update
# Unused.
if false; then
"$DOTFILES_HOME/thirdparty/fzf/install" --bin
fi
}
HOME="$DST_HOME" initialize
echo "Successfully installed dotfiles at '$DOTFILES_HOME'."
if [ "$interactive" = 'true' ]; then
echo ">> exec ${SHELLNAME:-$SHELL}"
HOME="$DST_HOME" exec "${SHELLNAME:-$SHELL}"
fi