forked from arvatoaws-labs/assume-role
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-assume-role
executable file
·52 lines (43 loc) · 1.26 KB
/
install-assume-role
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
#!/bin/bash
# Borrowed from https://github.com/brigade/dock and @sds
# Installs/upgrades assume-role in /usr/local/bin/assume-role, requiring sudo password only
# if necessary.
#
# You can run it anywhere by executing:
#
# curl https://raw.githubusercontent.com/arvatoaws/assume-role/master/install-assume-role | bash
set -euo pipefail
location=/usr/local/bin/assume-role
completer_location=~/zsh_functions
sudo=""
auth-sudo() {
if ! sudo -n >/dev/null 2>&1; then
echo "Enter your sudo password to install assume-role in $location"
sudo -v
sudo="sudo"
fi
}
if [ ! -d $(dirname $location) ]; then
mkdir_cmd="mkdir -p $location"
if ! $mkdir_cmd >/dev/null 2>&1; then
auth-sudo
sudo $mkdir_cmd
fi
fi
if [ ! -d $(dirname $completer_location) ]; then
mkdir_cmd="mkdir -p $completer_location"
if ! $mkdir_cmd >/dev/null 2>&1; then
$mkdir_cmd
fi
fi
if ! touch $location; then
auth-sudo
sudo touch $location
sudo chown $(id -u):$(id -g) $location
fi
if ! chmod +x $location; then
auth-sudo
sudo chmod +x $location
fi
$sudo curl -L https://raw.githubusercontent.com/arvatoaws/assume-role/master/assume-role --output $location
curl -L https://raw.githubusercontent.com/arvatoaws/assume-role/master/_assume-role --output $completer_location