FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli-mfa/src/bash.sh at main · rogusdev/aws-cli-mfa · GitHub
rogusdev
/
aws-cli-mfa
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
1
Code
Issues
2
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli-mfa
/
src
/
bash.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (51 loc) · 2.04 KB
Breadcrumbs
aws-cli-mfa
/
src
/
bash.sh
Copy path
File metadata and controls
71 lines (51 loc) · 2.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!
/usr/bin/env bash
#
you MUST source this file to get the exports in your shell!
#
https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced/28776166#28776166
([[
-n
$ZSH_EVAL_CONTEXT
&&
$ZSH_EVAL_CONTEXT
=~
:file$ ]]
||
[[
-n
$KSH_VERSION
&&
$(
cd
"
$(
dirname --
"
$0
"
)
"
&&
printf
'
%s
'
"
${PWD
%/
}
/
"
)
$(
basename --
"
$0
"
)
!=
"
${.sh.file}
"
]]
||
[[
-n
$BASH_VERSION
]]
&&
(return 0
2>
/dev/null))
&&
SOURCED=1
||
SOURCED=0
#
https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
if
!
command
-v python3
>
/dev/null
2>&1
;
then
echo
"
python3 could not be found!
"
[[
$SOURCED
-eq
1 ]]
&&
return
0
||
exit
0
fi
if
!
command
-v aws
>
/dev/null
2>&1
;
then
echo
"
aws could not be found!
"
[[
$SOURCED
-eq
1 ]]
&&
return
0
||
exit
0
fi
if
!
command
-v jq
>
/dev/null
2>&1
;
then
echo
"
jq could not be found!
"
[[
$SOURCED
-eq
1 ]]
&&
return
0
||
exit
0
fi
PYCODE=
$(
cat
<<
EOF
#INSERT_PYTHON_CODE_HERE
EOF
)
RESPONSE=
$(
COLUMNS=999 /usr/bin/env python3 -c
"
$PYCODE
"
$@
)
if
[[
"
$RESPONSE
"
==
usage
*
]]
;
then
echo
-E
"
$RESPONSE
"
[[
$SOURCED
-eq
1 ]]
&&
return
0
||
exit
0
fi
if
!
echo
-E
"
$RESPONSE
"
|
jq -e
.
>
/dev/null
2>&1
;
then
echo
"
JSON parsing failed:
"
echo
-E
"
$RESPONSE
"
[[
$SOURCED
-eq
1 ]]
&&
return
1
||
exit
1
fi
STS_CMD=
$(
echo -E
"
$RESPONSE
"
|
jq -r .sts_cmd
)
OUTPUT=
$(
echo -E
"
$RESPONSE
"
|
jq -r .output
)
[[
!
-z
"
$STS_CMD
"
]]
&&
echo
"
$STS_CMD
"
[[
!
-z
"
$OUTPUT
"
&&
"
null
"
!=
"
$OUTPUT
"
]]
&&
echo
"
$OUTPUT
"
#
https://unix.stackexchange.com/questions/88850/precedence-of-the-shell-logical-operators
[[
"
null
"
==
"
$(
echo -E
"
$RESPONSE
"
|
jq -r
'
.envvars
'
)
"
]]
&&
{ [[
$SOURCED
-eq
1 ]]
&&
return
0
||
exit
0
;
}
KEYS=(
$(
echo -E
"
$RESPONSE
"
|
jq -r
'
.envvars | keys[]
'
)
)
[[
${
#
KEYS[@]}
-ge
0 ]]
&&
[[
$SOURCED
-ne
1 ]]
&&
echo
"
You must source this file to get the exports in your shell
"
&&
exit
1
for
key
in
"
${KEYS[@]}
"
;
do
value=
$(
echo -E
"
$RESPONSE
"
|
jq -r
"
.envvars.
$key
"
)
export
$key
=
$value
echo
"
Set env var:
$key
"
done
Back
|
FazBrowse Home
|
New Git URL