-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_functions
More file actions
199 lines (167 loc) · 3.79 KB
/
shell_functions
File metadata and controls
199 lines (167 loc) · 3.79 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
# Basic functions
function update-ssh-known-hosts {
echo "Updating ssh known hosts from deployment.eqiad.wmnet"
scp deployment.eqiad.wmnet:/etc/ssh/ssh_known_hosts ~/.ssh/known_hosts-wmf
}
function dumpargs {
python3 -c 'import pprint, sys; pprint.pprint(sys.argv[1:])' "${@}"
}
function logspam-watch {
ssh -t -C mwlog1002.eqiad.wmnet /usr/local/bin/logspam-watch
}
function sshaddall {
ssh-add "$HOME"/.ssh/*id_rsa
}
# Run git with tracing
function gittrace {
GIT_TRACE=1 git "$@"
}
function headpage {
head -n $((LINES - 2))
}
function tailpage {
tail -n $((LINES - 2))
}
function gerrit {
host='gerrit.wikimedia.org'
if [ "$1" == "openstack" ]; then
host='review.openstack.org'
shift
elif [ "$1" == "replica" ]; then
host='gerrit-replica.wikimedia.org'
shift
fi;
# Default: gerrit --help
sshModule='gerrit'
cmd=("${@:---help}")
case "$1" in
( 'queue' | 'queues' )
cmd=(show-queue --by-queue --wide)
;;
( 'cache' | 'caches' )
cmd=(show-caches)
;;
( 'connections' )
cmd=(show-connections --wide)
;;
( 'threads' )
cmd=(show-caches --show-threads)
;;
( 'replication' )
sshModule=replication
shift
cmd=( "$@" )
;;
esac
set -x
# shellcheck disable=SC2029
ssh -p 29418 hashar@$host "$sshModule" "${cmd[@]}"
set +x
}
function telnets {
openssl=$(which openssl)
if [ -z "$openssl" ]; then
echo "ERROR: openssl CLI not found." >&2
return 1
fi
if [ -z "$1" ] || [ ! -z "$3" ]; then
echo "Usage:"
echo " ${FUNCNAME[0]} host [port]"
echo " ${FUNCNAME[0]} host:port"
return 1
fi
if [ -z "$2" ]; then
# telnets host.example.org
# telnets host.example.org:443
"$openssl" s_client -connect "$1"
else
# telnets host.example.org 443
"$openssl" s_client -connect "$1":"$2"
fi
}
function fatalmonitor {
host='mwlog1002.eqiad.wmnet'
if [ "$HOSTNAME" = "$host" ]; then
# In case I ever get ALIX on mwlog
# tip: ALIX is not on WMF prod
fatalmonitor "$@"
else
ssh -t -C mwlog1002.eqiad.wmnet 'fatalmonitor'
fi
}
function 720x480 {
osascript -e "tell application \"Terminal\" to set the bounds of the first window to {100, 50, 820, 530}"
}
function airport {
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport "$@"
}
# Show up a pint of beer on Mac OS X :-D
# BEER MUG (U+1F37A) -- thanks Saper for the reference
function beer {
echo '🍺 ';
}
function cigarette {
echo '🚬';
}
# Similar as beer() but gives out three cookies
function cookies {
echo '🍪 🍪 🍪';
}
# American's loves them..
function donuts {
echo '🍩';
}
function bug {
echo '🐛 <-- bug!';
}
function profit {
echo "💶 💶 💶 "; # banknote with euro sign
}
function jenkins {
local cmd=$1
local changeid=${2:-"I0cbfadb4363df19f3a3ff6819280e5ccbedc50b9"}
shift
echo "Using Change-Id: $changeid"
case "$cmd" in
"validate")
# Create a dummy change for jenkins validation
git commit --allow-empty -m 'Jenkins job validation (DO NOT SUBMIT)' -m "Change-Id: $changeid" \
&& git show \
&& echo "Now send the change! git-review -D"
;;
'help' | *)
echo "Oh no"
;;
esac
}
function php-extension_dir {
php -r 'print ini_get("extension_dir");'
}
function php-profile {
php -d xdebug.profiler_enable=1 "$@"
}
function php-trace {
php -d xdebug.auto_trace=1 "$@"
}
function php-trace-raw {
php -d xdebug.auto_trace=1 -d xdebug.trace_format=1 "$@"
}
function php-vld {
php -d "extension=vld.so" -d vld.active=1 -d vld.execute=0 -f "$1"
}
function ppv {
puppet parser validate "$@"
}
function whichpackage {
file="$(which "${@}")"
dpkg --search "$file"
}
function docker-releng {
set -x
docker run --rm -it --user=root --entrypoint=bash docker-registry.wikimedia.org/releng/"$1"
set +x
}
function bazel-list-targets {
bazel query 'attr(visibility, "//visibility:public", //...)'
}