forked from joshoohaah/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.shellfn
More file actions
137 lines (109 loc) · 5.09 KB
/
.shellfn
File metadata and controls
137 lines (109 loc) · 5.09 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#########################################
# Utility Functions
#will setup quick RDP tunnel for windows boxes in SCALR
function rdp(){
echo "Please enter IP address of box to RDP into: "
read ipaddr
echo "You entered: $ipaddr"
port_no="9002"
echo "Localhost port # for RDP: $port_no"
ec2_jumpbox_ip="10.227.165.28"
echo "ec2 jumpbox IP address: $ec2_jumpbox_ip"
ssh -L $port_no:$ipaddr:3389 gecloud@$ec2_jumpbox_ip
}
#will setup quick RDP tunnel for windows boxes in SCALR
function rdp_me(){
ipaddr="10.227.165.167"
port_no="9008"
echo "Attempting connection to $ipaddr box at port: $port_no"
ec2_jumpbox_ip="10.227.165.28"
echo "ec2 jumpbox IP address: $ec2_jumpbox_ip"
ssh -L $port_no:$ipaddr:3389 gecloud@$ec2_jumpbox_ip
}
#gets aws keys
function keyrefresh-aws(){
## customize the following variables
# setting for assumerole api call
name_for_this_session="212050466"
# account that you want access to (will lead to error if you're not authorized)
account_no="164996153968"
# role that you want access to (will lead to error if you're not authorized)
my_approved_role="bu-poweruser"
# how long will this token be valid for (min. 900, max. 3600)
valid_seconds=${seconds:=3600}
#### should not need to edit below this line
# the ARN for the role for which temporary token is to be generated
# format:
# arn_for_the_role="arn:aws:iam::TARGET_ACCOUNT_NO:role/TARGET_ROLE_NAME"
arn_for_the_role="arn:aws:iam::${account_no}:role/${my_approved_role}"
# optional: note the time at which keys were generated
generated_at=$(date -u "+%Y-%m-%dT%H:%M:%S")
# call STS to get temporary creds
temp_creds=$(aws sts assume-role \
--role-arn $arn_for_the_role \
--role-session-name $name_for_this_session \
--duration-seconds $valid_seconds \
--profile default \
--output json)
# extract access and secret keys and session token from response
# store in local shell vars
aws_access_key_id=$(echo $temp_creds \
| jq '.Credentials.AccessKeyId' \
| sed -e 's/\"//g')
aws_secret_access_key=$(echo $temp_creds \
| jq '.Credentials.SecretAccessKey' \
| sed -e 's/\"//g')
aws_session_token=$(echo $temp_creds \
| jq '.Credentials.SessionToken' \
| sed -e 's/\"//g')
expires_at=$(echo $temp_creds \
| jq '.Credentials.Expiration'\
| sed -e 's/\"//g' -e 's/Z//')
echo "generated at: $generated_at" && echo "expiring at: $expires_at"
#Set the 3 temp. keys in credentials/config file for the 'temp' profile
aws configure set AWS_ACCESS_KEY_ID $aws_access_key_id --profile temp
aws configure set AWS_SECRET_ACCESS_KEY $aws_secret_access_key --profile temp
aws configure set AWS_SESSION_TOKEN $aws_session_token --profile temp
#updates environment vars
AWS_ACCESS_KEY_ID=$aws_access_key_id; export AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=$aws_secret_access_key; export AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN=$aws_session_token; export AWS_SESSION_TOKEN
}
#____________________________===================_____________________
#########################################
# Utility Functions
# Create a new git repo with one README commit and CD into it
function gitnr() { mkdir $1; cd $1; git init; touch README; git add README; git commit -mFirst-commit;}
# Do a Matrix movie effect of falling characters
function matrix1() {
echo -e "\e[1;40m" ; clear ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) ;sleep 0.05; done|gawk '{ letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()"; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
}
function matrix2() {
echo -e "\e[1;40m" ; clear ; characters=$( jot -c 94 33 | tr -d '\n' ) ; while :; do echo $LINES $COLUMNS $(( $RANDOM % $COLUMNS)) $(( $RANDOM % 72 )) $characters ;sleep 0.05; done|gawk '{ letters=$5; c=$4; letter=substr(letters,c,1);a[$3]=0;for (x in a) {o=a[x];a[x]=a[x]+1; printf "\033[%s;%sH\033[2;32m%s",o,x,letter; printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,letter;if (a[x] >= $1) { a[x]=0; } }}'
}
# Use Mac OSX Preview to open a man page in a more handsome format
function manp() {
man -t $1 | open -f -a /Applications/Preview.app
}
# Show normally hidden system and dotfile types of files
# in Mac OSX Finder
function showhiddenfiles() {
defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app
}
# Hide (back to defaults) normally hidden system and dotfile types of files
# in Mac OSX Finder
function hidehiddenfiles() {
defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app
}
# kill all instances of a process by name
function skill()
{
sudo kill -9 `ps ax | grep $1 | grep -v grep | awk '{print $1}'`
}
function schef()
{
sudo chef-client
}
function fixperms(){
find . \( -name "*.sh" -or -type d \) -exec chmod 755 {} \; && find . -type f ! -name "*.sh" -exec chmod 644 {} \;
}