-
Notifications
You must be signed in to change notification settings - Fork 43
/
install.sh
executable file
·72 lines (62 loc) · 1.63 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
#!/bin/bash
# Get script directory
pushd "$(dirname "$0")" > /dev/null
DIR_SELF=$(pwd -P)
popd > /dev/null
readonly DIR_HOME="${HOME}"
# Running on MinGW
uname -s | grep -q 'MINGW[^_]\+_NT'
OS_MINGW=$?
dirs=("${DIR_HOME}/.local/bin" "${DIR_HOME}/bin" "/usr/local/bin" "/usr/bin" "/bin")
for i in "${dirs[@]}"
do
if [ -d "${i}" ] && echo "$PATH" | grep -q "${i}"
then
DIR_BIN="${i}"
break;
fi
done
# Use XDG Base Directories if available
# (see http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html)
DIR_CONF_DEST="${XDG_CONFIG_HOME:-$DIR_HOME}/.git-semver"
DIR_DATA="${XDG_DATA_HOME:-$DIR_HOME}/.git-semver"
FILE_SRC="${DIR_SELF}/git-semver.sh"
FILE_DEST="${DIR_BIN}/git-semver"
FILE_CONF_SRC="${DIR_SELF}/config.example"
FILE_CONF_DEST="${DIR_CONF_DEST}/config"
# If MinGW
if [ ${OS_MINGW} -eq 0 ]
then
# Create a stub, tabs are important for the heredoc
cat <<-EOF > "${FILE_DEST}"
#!/bin/bash
FILE_SRC="${FILE_SRC}"
FILE_PREFIX=""
if uname -s | grep -q 'MINGW[^_]\+_NT'
then
"\${FILE_SRC}" \$@
else
if uname -s | grep -q 'CYGWIN_NT'
then
FILE_PREFIX="/cygdrive"
fi
echo -e "Error: This file is a stub designed to run under MinGW, please reinstall \$(basename "\$0") by running:\n\n \${FILE_PREFIX}\$(dirname \${FILE_SRC})/install.sh"
fi
EOF
# Otherwise
else
if [ -L "${FILE_DEST}" ]
then
rm "${FILE_DEST}"
fi
# Symlink
ln -s "${FILE_SRC}" "${FILE_DEST}"
fi
# Make data dir
mkdir -p "${DIR_DATA}"
# Copy configuration
mkdir -p "${DIR_CONF_DEST}"
if [ ! -f "${FILE_CONF_DEST}" ]
then
cp "${FILE_CONF_SRC}" "${FILE_CONF_DEST}"
fi