-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpme.sh
executable file
·89 lines (78 loc) · 2.12 KB
/
helpme.sh
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
#!/bin/bash
QH_APP_TAG=quickhost
PROFILE=quickhost-root
function listem() {
function _listall() {
#aws --profile "$PROFILE" --region "us-east-1" ec2 describe-instances \
aws ec2 describe-instances \
--filters "Name=tag-key,Values=${QH_APP_TAG}" \
--query 'Reservations[].Instances[].{ID:InstanceId,STATE:State.Name}' \
--output text
return
}
function _listrunning() {
aws ec2 describe-instances \
--filters 'Name=instance-state-name,Values=running' "Name=tag-key,Values=${QH_APP_TAG}" \
--query 'Reservations[].Instances[].InstanceId' \
--output text
return
}
case "$1" in
-r|--running) _listrunning ;;
-h|--help) echo "listem get all instances tagged with '${QH_APP_TAG}'
[-r|--running] show only running instances (for debugging)
[-h|--help] show this dialog and exit
";;
*) _listall ;;
esac
}
function blog () {
local blogfile
blogfile="${PWD}/blog/blog-$(date -I).md"
function _template(){
[ -f "$blogfile" ] && vim "$blogfile" && exit
cat <<EOF > "$blogfile"
# $(date '+%A, %D')
EOF
vim "$blogfile"
}
case "$1" in
-h|--help) echo "
blog write a blog post for today
-h|--help show this dialog and exit
";;
*) _template;;
esac
}
function sgids(){
aws ec2 describe-security-groups \
--filters "Name=tag-key,Values=${QH_APP_TAG}" \
--query 'SecurityGroups[].{NAME:GroupName,ID:GroupId}'
}
function test_stuff(){
for provider in {aws,null}; do
for action in {make,destroy,update,init,describe}; do
main.py "$provider" "$action" -h
done
done
main.py -h
}
function keys() {
echo TODO
}
case "$1" in
list) shift; listem "$@";;
sgs) shift; sgids "$@";;
keys) shift; keys "$@";;
blog) shift; blog "$@";;
test-help) test_stuff;;
*) echo '
usage:
list list instances
sgs list security groups
keys list ec2 (ssh) keys
blog write a blog post for today
test-help print help for all of the plugin options
help show this dialog and exit
';;
esac