-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·173 lines (145 loc) · 3.96 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
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
#!/usr/bin/env bash
# vim: ts=4 sw=4 sr sts=4 fdm=marker fmr={{{,}}} ff=unix fenc=utf-8 tw=130
# ts: Actual tab character stops.
# sw: Indentation commands shift by this much.
# sr: Round existing indentation when using shift commands.
# sts: Virtual tab stops while using tab key.
# fdm: Folds are manually defined in file syntax.
# fmr: Folds are denoted by {{{ and }}}.
# ff: Line endings should always be <NL> (line feed #09).
# fenc: Should always be UTF-8; #! must be first bytes, so no BOM.
# tw: Maximum width of a line before it auto-wraps.
# Environment {{{1
#
#
XP_FOLDER="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Functions {{{1
#
#
# install_file {{{2
install_file()
{
TARGET="$2"
INSTALL="$XP_FOLDER/$1"
if [ -z "$3" ]; then
BACKUP="$TARGET.bak"
else
BACKUP="$3"
fi
if [ -h "$TARGET" ]; then
if ! rm -f "$TARGET"; then
echo $'\e[31m'"Could not install '$INSTALL' to '$TARGET': unable to remove old symbolic link."$'\e[m'
return 1
fi
elif [[ -e "$TARGET" && ! -e "$BACKUP" ]]; then
mv "$TARGET" "$BACKUP" || EXIT_CODE=$?
if (( $EXIT_CODE )); then
echo $'\e[31m'"Could not install '$INSTALL' to '$TARGET': unable to back up existing file."$'\e[m'
return $EXIT_CODE
else
echo $'\e[0m'"Moved original '$TARGET' to '$BACKUP'."
fi
fi
ln -s "$INSTALL" "$TARGET" || EXIT_CODE=$?
if ! (( $EXIT_CODE )); then
echo $'\e[32m'"Linked '$TARGET' to '$INSTALL'."$'\e[m'
return 0
fi
echo $'\e[31m'"Could not install '$INSTALL' to '$TARGET': unable to make symbolic link."$'\e[m'
return $EXIT_CODE
}
# install_script {{{2
install_script()
{
ext="$1"
INSTALL="$2"
TARGET="$3"
if [ -z "$4" ]; then
FOLDER="$TARGET.d"
else
FOLDER="$4"
fi
if [ -z "$5" ]; then
BACKUP="$FOLDER/10-default.$ext"
else
BACKUP="$FOLDER/$5"
fi
if [ ! -d "$FOLDER" ]; then
mkdir "$FOLDER" || EXIT_CODE=$?
if ! (( $EXIT_CODE )); then
echo $'\e[0m'"Created '$FOLDER' to hold any pre-existing scripts."
else
echo $'\e[31m'"Could not install '$INSTALL' to '$TARGET': unable to create folder '$FOLDER'."$'\e[0m'
return $EXIT_CODE
fi
fi
install_file "$INSTALL" "$TARGET" "$BACKUP" || EXIT_CODE=$?
[ -e "$BACKUP" ] && chmod +x "$BACKUP"
return $EXIT_CODE
}
# make_folder {{{2
make_folder()
{
[ ! -e "$1" ] && mkdir -p "$1"
}
# Installation Manifest {{{1
#
#
if [ $# -lt 1 ]; then
pushd "$XP_FOLDER" > /dev/null || exit $?
git submodule init
git submodule update
popd > /dev/null
fi
make_folder ~/tmp
make_folder ~/.swp
make_folder ~/.backup
make_folder ~/.undo
make_folder ~/.config/nvim
make_folder ~/.zsh/cache
make_folder ~/.zsh/init
make_folder ~/.zsh/functions
make_folder ~/.local/share/nvim/backup
make_folder ~/.local/share/nvim/swap
make_folder ~/.local/share/nvim/undo
install_script sh shell/bashrc.sh ~/.bashrc ~/.bashrc.d
install_script zsh zsh/zshrc.zsh ~/.zshrc.local ~/.zsh/init
install_file vim/vimrc.vim ~/.vimrc
install_file config/screen.screenrc ~/.screenrc
install_file config/tmux.conf ~/.tmux.conf
install_file nvim/config/init.vim ~/.config/nvim/init.vim
install_file config/minttyrc ~/.minttyrc
for f in zsh/functions/_*; do
install_file "$f" ~/.zsh/functions
done
"$XP_FOLDER/grml.sh"
"$XP_FOLDER/git.sh" && true
if type zsh > /dev/null 2>&1; then
zsh -c 'rehash && rm -f -- ${ZDOTDIR:-${HOME:?No ZDOTDIR or HOME}}/.zcompdump'
fi
case "$OSTYPE" in
darwin*)
if ! grep -qF '/.bashrc' /etc/bashrc; then
if ! grep -qF -e '~/.bashrc' -e '$HOME/.bashrc' /etc/bashrc; then
yn=
echo -n $'\e[31mPatch /etc/bashrc? [y/n]:\e[m ' >&2
read -srn1 yn || true
echo
if [[ "$yn" = 'y' || "$yn" = 'Y' ]]; then
echo "Patching..." >&2
sudo tee -a /etc/bashrc <<< $'\n\n[ -e ~/.bashrc ] && . ~/.bashrc'
else
echo "Skipping patch" >&2
fi
fi
fi
;;
esac
case "$(basename "$SHELL")" in
zsh|bash)
echo $'\e[31mLog in again or run: \e[m. ~/.'"$(basename "$SHELL")"'rc'
;;
*)
echo $'\e[31mLog in again with bash or zsh.\e[m'
;;
esac