-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·129 lines (102 loc) · 2.2 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
#!/bin/bash -e
fail() {
>&2 cat
exit 1
}
if [ $# -ne 0 ]; then
fail << EOF
Usage: ${0##*/}
Options:
HTTPS=0|1
AUTO_COMPLETION=1|0
CONFIRM=0|1
Installs cppsm command by cloning its repository and appending the necessary
changes to the user's Bash startup script.
EOF
fi
if [ -e "$HOME/.cppsm" ]; then
fail << EOF
ERROR: .cppsm already exists in your \$HOME.
EOF
fi
contains() {
local PATTERN="$1"
local FILE="$2"
[ -e "$FILE" ] && grep -q -e "$PATTERN" "$FILE"
}
for SCRIPT in .bash_profile .bashrc; do
if contains CPPSM "$HOME/$SCRIPT"; then
fail << EOF
ERROR: CPPSM already appears in your $SCRIPT.
EOF
fi
if [ -e "$HOME/$SCRIPT" ]; then
TARGET_SCRIPT="$SCRIPT"
fi
done
if [ -z "$TARGET_SCRIPT" ]; then
fail << EOF
ERROR: Neither .bash_profile nor .bashrc exists.
EOF
fi
COMMANDS="$(cat << EOF
CPPSM="\$HOME/.cppsm"
export PATH="\$CPPSM/bin:\$PATH"
EOF
)"
if [ "$AUTO_COMPLETION" != 0 ]; then
COMMANDS="$(cat << EOF
$COMMANDS
. "\$CPPSM/bash_completion"
EOF
)"
fi
SNIPPET="$(cat << EOF
# CPPSM lines added by the C++ submodule manager 'install' script.
# Uninstall by deleting the CPPSM lines and the \$CPPSM directory.
$COMMANDS
EOF
)"
if [ "$HTTPS" = 1 ] || [ "$TRAVIS" = true ]; then
URL="https://github.com/cppsm/cppsm-cli.git"
else
URL="[email protected]:cppsm/cppsm-cli.git"
fi
# shellcheck disable=2001
cat << EOF
This will install the C++ submodule manager 'cppsm' command by running
git clone --quiet --single-branch $URL "\$HOME/.cppsm"
and appending
$(echo "$SNIPPET" | sed 's#^# #')
to \$HOME/$TARGET_SCRIPT.
EOF
if [ "$CONFIRM" = 1 ]; then
read -p "Continue (y/n)? " -n 1 -r && echo
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
fail <<EOF
Installation cancelled.
EOF
fi
echo
fi
if ! git clone --quiet --single-branch $URL "$HOME/.cppsm"; then
fail << EOF
ERROR: Failed to git clone the cppsm-cli.
EOF
fi
augment-script() {
cat << EOF >> "$HOME/$TARGET_SCRIPT"
$SNIPPET
EOF
}
if ! augment-script; then
fail <<EOF
ERROR: Failed to append to \$HOME/$TARGET_SCRIPT.
EOF
fi
cat <<EOF
C++ submodule manager 'cppsm' command has been installed!
To use the 'cppsm' command you now need to restart the shell or execute the
following commands in this shell:
$COMMANDS
EOF