This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acm
executable file
·110 lines (101 loc) · 2.5 KB
/
acm
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
#! /bin/zsh -f
# ACM: The AWS Context Manager - Changes up your account IDs and credentials for your command line tools when switching AWS accounts.
# Process commands:
function printUsage {
cat<<EOF
acm: Sets, creates and deletes AWS contexts.
Usage: acm <command>
Command is one of the following:
<none> - Prints the context you are currently in
create <context> - creates a new context
switch <context> - switches to a context
delete <context> - deletes a context
list - Lists all contexts
disable - Disables ACM
enable - Enables ACM
verbose - Prints your context before running any EC2 commands
quiet - Stop being verbose
See http://github.com/drocamor/aws-context-manager for more info
EOF
}
# Startup:
# Check for ~/.acm directory, create it if neccessary
if [[ ! -d ~/.acm ]]; then
mkdir -p ~/.acm/contexts
if [[ $? -ne 0 ]]; then
echo Could not create ~/.acm/contexts. Exiting...
exit 1
fi
fi
case "$1" in
disable)
touch ~/.acm/disabled
echo Disabling AWS context Manager
;;
enable)
rm ~/.acm/disabled
echo Enabling AWS context Manager
;;
verbose)
touch ~/.acm/verbose
echo Making AWS context Manager be verbose
;;
quiet)
rm ~/.acm/verbose
echo Making AWS context Manager quiet
;;
create)
if [[ -e ~/.acm/contexts/$2 ]]; then
echo Context ~/.acm/contexts/$2 appears to already exist.
echo You must delete this file to create a new context with the same name, or edit it directly to change it.
else
cat > ~/.acm/contexts/$2 <<EOF
# AWS context $2
export EC2_PRIVATE_KEY=
export EC2_CERT=
export AWS_USER_ID=
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
EOF
echo Context skeleton created. You must edit ~/.acm/contexts/$2 to add the proper values for your context.
fi
;;
switch)
if [[ -e ~/.acm/contexts/$2 ]]; then
ln -sf ~/.acm/contexts/$2 ~/.acm/configured_context
if [[ $? -ne 0 ]]; then
echo Error creating link to ~/.acm/contexts/$2
fi
else
echo Context $2 does not seem to exist.
fi
;;
delete)
if [[ -e ~/.acm/contexts/$2 ]]; then
rm ~/.acm/contexts/$2
if [[ $? -ne 0 ]]; then
echo Error removing ~/.acm/contexts/$2
fi
else
echo Context $2 does not seem to exist.
fi
;;
list)
echo AWS contexts:
ls -1 ~/.acm/contexts
;;
describe)
cat ~/.acm/contexts/$2
;;
'')
if [[ -h ~/.acm/configured_context ]]; then
MY_CONTEXT=`readlink ~/.acm/configured_context`
echo AWS context is `basename $MY_CONTEXT`
else
echo No AWS context selected
fi
;;
*)
printUsage
;;
esac