-
Notifications
You must be signed in to change notification settings - Fork 1
/
ebstall.sh
executable file
·159 lines (133 loc) · 3.87 KB
/
ebstall.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
#!/usr/bin/env bash
#
# Auto-updater && self-invoker
#
set -e # Work even if somebody does "sh thisscript.sh".
# Colors
red='\e[0;31m'
green='\e[0;32m'
yellow='\e[0;33m'
reset='\e[0m'
echoRed() { echo -e "${red}$1${reset}"; }
echoGreen() { echo -e "${green}$1${reset}"; }
echoYellow() { echo -e "${yellow}$1${reset}"; }
# Basename + usage + argument processing
BASENAME=$(basename $0)
USAGE="Usage: $BASENAME [OPTIONS]
A self-updating wrapper script for the EBSTALL. When run, updates
to both this script and EBSTALL will be downloaded and installed.
Help for ebstall itself cannot be provided until it is installed.
--debug attempt experimental installation
-h, --help print this help
-n, --non-interactive, run without asking for user input
--allow-update, run without asking on update permission
--no-self-upgrade do not download updates
--os-packages-only install OS dependencies and exit
-v, --verbose provide more output
All arguments are accepted and forwarded to the EBAWS client when run."
# Override of the prompting for update, we dont need it now
ASSUME_YES=1
for arg in "$@" ; do
case "$arg" in
--debug)
DEBUG=1;;
--os-packages-only)
OS_PACKAGES_ONLY=1;;
--no-self-upgrade)
# Do not upgrade this script (also prevents client upgrades, because each
# copy of the script pins a hash of the python client)
NO_SELF_UPGRADE=1;;
--already-updated)
ALREADY_UPDATED=1;;
--help)
HELP=1;;
--non-interactive)
ASSUME_YES=1;;
--allow-update)
ALLOW_UPDATE=1;;
--verbose)
VERBOSE=1;;
-[!-]*)
while getopts ":hnv" short_arg $arg; do
case "$short_arg" in
h)
HELP=1;;
n)
ASSUME_YES=1;;
v)
VERBOSE=1;;
esac
done;;
esac
done
confirm ()
{
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
RET=0
case "$response" in
[yY][eE][sS]|[yY])
return 0
;;
*)
return 1
;;
esac
}
# Running under root?
if test "`id -u`" -ne "0" ; then
echo "$USAGE"
echo ""
echoRed "Error: This script needs to be run under root."
echo "Try running with sudo -E -H $0"
exit 1
fi
if [ "$HELP" == 1 ]; then
echo "$USAGE"
fi
UPDATE_ALLOWED=0
if [ "$ALLOW_UPDATE" == 1 -o "$ASSUME_YES" == 1 ]; then
UPDATE_ALLOWED=1
fi
# Can we upgrade? Ask the user
if [ "$ASSUME_YES" != 1 -a "$ALLOW_UPDATE" != 1 ]; then
echo "EnigmaBridge Installer would like to update itself so you have the newest version"
if confirm "Do you allow it to do update with pip? [y/N]"; then
UPDATE_ALLOWED=1
else
UPDATE_ALLOWED=0
fi
fi
# Upgrade step
if [ "$NO_SELF_UPGRADE" != 1 -a "$UPDATE_ALLOWED" == 1 ]; then
if [ "$ALREADY_UPDATED" != 1 ]; then
echo "Checking for updates..."
fi
set +e
# Update machine / installer
if [ "$ALREADY_UPDATED" != 1 ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/EnigmaBridge/ebstall-update/ami-01/update.sh)"
$0 "$@" --already-updated
exit 1
fi
# Update pip trouble maker
pip install --upgrade appdirs 2>/dev/null >/dev/null
# Update with pip
PIP_OUT=`pip install --no-cache-dir --upgrade ebstall 2>&1`
PIP_STATUS=$?
set -e
# Report error. (Otherwise, be quiet.)
if [ "$PIP_STATUS" != 0 ]; then
echo "Had a problem while installing Python packages:"
echo "$PIP_OUT"
echo ""
echo "Running the previous version"
fi
fi
# Invoke the python client directly
SCRIPT=ebstall-cli
if [ -f "/usr/local/bin/${SCRIPT}" ]; then
/usr/local/bin/${SCRIPT} "$@"
else
`which ${SCRIPT}` "$@"
fi