-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·146 lines (116 loc) · 3.95 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
#! /bin/sh
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# Disclaimer of Warranty. Unless required by applicable law or
# agreed to in writing, Licensor provides the Work (and each
# Contributor provides its Contributions) on an AS IS BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied, including, without limitation, any warranties or conditions
# of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
# PARTICULAR PURPOSE. You are solely responsible for determining the
# appropriateness of using or redistributing the Work and assume any
# risks associated with Your exercise of permissions under this License.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
# This script clones romcheg's Vim settings and creates all
# necessary symbolic links.
set -eu
# Defaults
# ========
REPO_ADDRESS=${REPO_ADDRESS:-"https://github.com/romcheg/vim-settings.git"}
VIM_DIRECTORY=${VIM_DIRECTORY:-~/.vim}
VIMRC=${VIMRC:-~/.vimrc}
BACKUP_LOCATION=${BACKUP_LOCATION:-~/vim.old}
GIT_EXECUTABLE=${GIT_EXECUTABLE:-'git'}
VIM_EXECUTABLE=${VIM_EXECUTABLE:-'vim'}
# Functions
# =========
# Checks whether the specified app is available by running
# it with --version and checking the exit code. Breaks the
# script exection, if not available.
#
# $1: App executable to run.
assert_available() {
$1 --version 2>&1 >/dev/null
local not_available=$?
if [ "$not_available" -ne "0" ]; then
echo "Please install " $1 " and make sure it is available."
exit 1
fi
}
# Clones the settings from the repository and creates a symlink.
# Assumes that the environment is clean.
install() {
echo "Obtaining the settings..."
$GIT_EXECUTABLE clone $REPO_ADDRESS $VIM_DIRECTORY
if [ $? -ne 0 ]; then
echo "Failed to obtain the settings. Please try again later."
echo "If you got the error multiple times, please contact the author."
exit 2
fi
echo "Creating symlinks..."
ln -s $VIM_DIRECTORY/vimrc $VIMRC
}
# Backs up previous settings.
backup() {
echo "Creating a back up..."
backup_dir=$(mktemp -d $BACKUP_LOCATION.XXX)
if [ -f "$VIMRC" ] || [ -d "$VIMRC" ]; then
cp $VIMRC $backup_dir/
fi
if [ -f "$VIM_DIRECTORY" ] || [ -d "$VIM_DIRECTORY" ]; then
cp -r $VIM_DIRECTORY $backup_dir/
fi
}
# Cleans up a previuos configuration.
cleanup() {
echo "Cleaning up the previous installation..."
rm -rf $VIM_DIRECTORY
rm -rf $VIMRC
}
# Logic
# =====
assert_available $VIM_EXECUTABLE
assert_available $GIT_EXECUTABLE
backup_dir=""
# Detect a previous installation.
if [ -d "$VIM_DIRECTORY" ] || [ -f "$VIMRC" ]; then
echo "A previous configuration found."
echo "You can either stop right now or choose to relpace it with the new one."
echo "If you choose to continue, the old configuration will be backed up and replaced with the new one."
read -p "Would you like to continue (y/N)? " choice < /dev/tty
case "$choice" in
y|Y )
backup
cleanup
;;
n|N )
echo "Exiting. Thank you!"
exit 3
;;
* )
echo "Assuming that as No. Thank you!"
exit 3
;;
esac
fi
# Installation is performed here.
install
echo ""
echo "=========================================================="
echo "Vim settings was installed!"
if [ -n "$backup_dir" ]; then
echo "Old configuration files were saved to "$backup_dir
fi
echo "Now you can run Vim without arguments and let it configure its plugins."
echo "Thank you for using my settings!"
echo "=========================================================="
exit 0