forked from coinbase/assume-role
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-assume-role
executable file
·43 lines (35 loc) · 984 Bytes
/
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
#!/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/madogiwa/assume-role/master/install-assume-role | bash
set -euo pipefail
location=/usr/local/bin/assume-role
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 ! 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/madogiwa/assume-role/master/assume-role --output $location