-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv
101 lines (94 loc) · 2.2 KB
/
env
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
AWS_DIR=~/.aws
# for JAVA
if ! which java > /dev/null || [ "$JAVA_HOME" = "" ]
then
for x in /usr/local/java /usr/java/default /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/jre /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home /cygdrive/c/java/
do
if [ -d $x ]
then
export JAVA_HOME=$x
export PATH=$JAVA_HOME/bin:$PATH
break
fi
done
fi
# change credential with 'key NAME' command (which will use ~/.aws/keys-NAME/)
function key
{
if [ "$1" = "" ]
then
cd $AWS_DIR
echo "<key list>"
echo keys-*
cd - > /dev/null
echo
echo "type 'key <NEW_KEY_NAME>' to create a new user."
return
fi
keydir=$AWS_DIR/keys-$1
if [ -d $keydir ]
then
source $keydir/env && echo using keys-$1
else
echo $keydir does not exist.
echo -n "input AWSAccessKeyId : "
read accesskey
echo -n "input AWSSecretKey : "
read secretkey
cp -r $AWS_DIR/keys $keydir
cat <<EOF > $keydir/credential
AWSAccessKeyId=$accesskey
AWSSecretKey=$secretkey
EOF
source $keydir/env && echo using keys-$1
fi
}
# change region with 'region REGION_API_NAME'
function region
{
target=$1
if [ "$target" = "" ]
then
if [ "$EC2_REGION" = "" ]
then
echo "currently region is not set (us-east-1 will be used by default)"
else
echo currently region is set to $EC2_REGION
fi
echo "usage: region <region>"
echo available regions are:
ec2-describe-regions | awk '{print "region "$2}'
else
export AWS_REGION=$target
export EC2_REGION=$target
export EC2_URL=https://ec2.$target.amazonaws.com
export ELASTICBEANSTALK_URL=https://elasticbeanstalk.$target.amazonaws.com
echo API endpoint changed to $target
fi
}
# region alias
alias use="region us-east-1"
alias usw="region us-west-1"
alias usw2="region us-west-2"
alias euw="region eu-west-1"
alias aps="region ap-southeast-1"
alias aps2="region ap-southeast-2"
alias apn="region ap-northeast-1"
# permission is important
chmod 600 $AWS_DIR/keys*/{credential*,s3cfg} &> /dev/null
# for AWS tool HOMEs
if [ "$AWSENV" = "" ] # do not add path more than once
then
cd $AWS_DIR
for x in *_HOME
do
export $x=$AWS_DIR/$x
done
cd - > /dev/null
for x in $AWS_DIR/*/bin
do
export PATH=$x:$PATH
done
fi
# to judge multiple load
export AWSENV=LOADED