-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc~
467 lines (370 loc) · 9.15 KB
/
.bashrc~
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# MAB
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ] ; then
. /etc/bashrc
fi
ulimit -s 4096
ulimit -c unlimited
[ -z "$PS1" ] && return
#if ! shopt login_shell >& /dev/null ; then
# return
#fi
# colors
BOLD="\[\033[1m\]"
RED="\[\033[1;31m\]"
OFF="\[\033[m\]"
GREEN="\[\033[0;32m\]"
CYAN="\[\033[0;36m\]"
PURPLE="\[\033[0;35m\]"
RV="\e[7m"
function exitstatus {
EXITSTATUS="$?"
COLOR=${CYAN}
LAST=" \$>"
if [ "$EXITSTATUS" -eq "0" ] ; then
PS1="${EXITSTATUS}:\!:${COLOR}\u@\h:\w${LAST} ${OFF}"
else
PS1="${RED}${EXITSTATUS}:\!:${COLOR}\u@\h:\w${OFF}${RED}${LAST} ${OFF}"
fi
PS2="${BOLD}>${OFF} "
}
function print {
enscript 4 -E -G2r -u'mab' $1
}
function print1 {
enscript 4 -E -G -u'mab' $1
}
function sfp {
if [ -n "${1}" ] ; then
echo -en "\\033[1m"
echo "Setting SF_PREFIX to /var/tmp/BUILD-$1"
echo -en "\\033[m"
export SF_PREFIX=/var/tmp/BUILD-$1
else
echo -en "\\033[1m"
echo "SF_PREFIX is set to ${SF_PREFIX}"
echo -en "\\033[m"
fi
}
function mount-ender {
if ping -c 1 ender.sfeng.sourefire.com >& /dev/null ; then
if ! mount | grep ender.sfeng >& /dev/null ; then
echo -n "Mounting ender on ~/src ... "
sshfs ender.sfeng.sourcefire.com:src ~/src -o uid=500,gid=500
echo " done"
else
echo -n "Unmount ~/src ... "
fusermount -u ~/src
echo " done"
fi
fi
}
function connect-sf {
local PID=$( pgrep openconnect )
if [ -z "${PID}" ] ; then
echo "Connecting to sourcefire vpn...."
sudo openconnect -b -u mbrannig --authgroup=SF-STD -s /etc/vpnc/vpnc-script remote.sourcefire.com
else
if ask "Disconnect from Sourcefire VPN ($PID)" ; then
echo -n "Disconnecting sourcefire vpn..."
sudo kill ${PID}
sudo ifdown eth0
sudo ifup eth0
echo " done"
fi
fi
}
function ask() # See 'killps' for example of use.
{
echo -n "$@" '[y/n] ' ; read ans
case "$ans" in
y*|Y*) return 0 ;;
*) return 1 ;;
esac
}
function ff()
{
find . -type f -iname '*'$*'*' -ls ;
}
function sf_cvs()
{
export CVS_RSH=ssh
export CVSROOT=":ext:cvs.sourcefire.com:/usr/cvsroot"
export CDPATH='.:~/src:~/src/WORK'
}
function xtitle() # Adds some text in the terminal frame.
{
case "$TERM" in
*term | rxvt)
echo -n -e "\033]0;$*\007" ;;
*)
;;
esac
}
function _branch_list()
{
# local list=$(cd ~/src/WORK ; find ${BRANCH_REPOS} -maxdepth 1 -type d ! -name ".bzr" -printf "%f " )
local tmp
local list
for i in ${BRANCH_REPOS} ; do
tmp=$(cd ~/src/WORK/${i} ; find . -maxdepth 1 -type d ! -name ".bzr" -printf "%f\n" | grep -v "^\." | xargs )
list="$list $tmp"
done
echo "${BRANCHES} ${list}"
}
function _branches()
{
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -W "$(_branch_list)" $cur ) )
elif [ $COMP_CWORD -eq 2 ]; then
case "$prev" in
help)
COMPREPLY=( $( compgen -W "$(_branch_list) commands" $cur ) )
;;
esac
fi
}
function _var_functions()
{
echo "foo"
}
function br()
{
local dir=$1
local top=~/src/WORK/
for i in ${BRANCH_REPOS} ; do
if [ -d "${top}/${i}/$1" ] ; then
cd ${top}/${i}/$1
return
fi
done
if [ -d "${top}/$1" ] ; then
cd ${top}/$1
return
fi
echo "No branch directory for $1!"
}
function get_remote_mac()
{
local HOST=$1
arping -c 1 -q ${HOST} 2> /dev/null
if [ $? -ne 0 ] ; then
MAC=
echo "unable to get mac for ${HOST}"
return 1
else
MAC=$( arp ${HOST} | tail -1 | awk -F' ' '{print $3}' )
fi
}
function localboot()
{
local HOST=$1
get_remote_mac ${HOST}
local mac=$(echo "01-${MAC}" | sed -e 's/:/-/g' | tr [A-Z] [a-z] )
rm -vf /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
cp -vf /nfs/netboot/sf-linux-os/install-configs/localboot.cfg /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
chmod -v 777 /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
}
function pxe_mac()
{
local HOST=$1
get_remote_mac ${HOST}
local mac=$(echo ${MAC} | sed -e 's/:/-/g' | tr [A-Z] [a-z] )
echo "01-${mac}"
}
function copy_pxe_config()
{
local HOST=$1
local FILE=$2
local mac=$(pxe_mac $HOST)
rm -vf /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
cp -vf ${FILE} /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
chmod -v 777 /nfs/netboot/sf-linux-os/tftpboot/pxelinux.cfg/${mac}
}
function add_host()
{
if ! grep ${1} ${HOST_LIST_FILE} >& /dev/null ; then
echo "$1" >> ${HOST_LIST_FILE}
fi
}
function reboot_wait()
{
if [ -f ${REPO}/reboot-system.expect ] ; then
${REPO}/reboot-system.expect $1 $2 $3
fi
local port=443
if [ -n "$4" ] ; then
port=$4
fi
wait_for_shutdown $1
wait_for_port $1 $port
send_mail
}
function wait_host()
{
wait_for_port $1 $port
send_mail
}
function wait_for_port()
{
local HOST=$1
local PORT=$2
local keep_going
local output
local banner
keep_going=0
while [ $keep_going -eq 0 ] ; do
output=$(nc -d -w 2 ${HOST} ${PORT})
if [ $? -eq 0 ] ; then
if [ "${PORT}" = "22" ] ; then
if [[ ${output} =~ OpenSSH ]] ; then
keep_going=1
return 0
fi
else
keep_going=1
return 0
fi
fi
sleep 5
done
}
wait_for_shutdown()
{
local HOST=$1
local keep_going
keep_going=0
while [ $keep_going -eq 0 ] ; do
ping -c 1 ${HOST} >& /dev/null
if [ $? -ne 0 ] ; then
keep_going=1
return 0
fi
sleep 5
done
}
send_mail()
{
echo | msmtp -C ${REPO}/msmtprc -f ${USER}@sfeng.sourcefire.com ${USER}@sourcefire.com <<EOF
Subject: Your install of ${HOST} is complete
To: ${USER}@sourcefire.com
From: install@sfeng.sourcefire.com
Your install of ${HOST} in complete.
EOF
}
function copy_tree()
{
local src=$1
local dst=$2
local dir=$( dirname $1)
mkdir -vp $dst/$dir
cp -av $src $dst/$dir
}
EXTRAPTH=
HOST=$(hostname)
SHORTHOST=$(hostname -s)
export REPO=~/repo/mbrannig
if ! bash --version | grep 2.05 >& /dev/null ; then
source ${REPO}/.bashrc-v3-only
fi
PLATFORM=$(uname )
ARCH=$(uname -m)
if host ${HOST} | grep sourcefire >& /dev/null ; then
echo -n "Setting up Sourcefire Environment (${ARCH}): "
export PYTHONPATH=/usr/local/lib/python:/usr/lib/python2.5
export PRINTER=Copier
export REPLYTO=matthew.brannigan@sourcefire.com
EXTRAPATH=/usr/Python-2.6.4/bin
export SF_PREFIX=${SF_PREFIX:=/var/tmp/BUILD}
sf_cvs
HOST_LIST=$(cat ${REPO}/hosts-sf.txt ${REPO}/hosts.txt | xargs)
HOST_LIST_FILE=${REPO}/hosts-sf.txt
echo "SF_PREFIX is set to ${SF_PREFIX}"
else
echo "Setting up Den of Slack Environment (${ARCH}):"
export PRINTER=officejet7310
export REPLYTO=mbrannig@mbrannig.org
HOST_LIST=$(cat ${REPO}/hosts-dos.txt ${REPO}/hosts.txt | xargs ; cat ${REPO}/hosts-sf.txt | sed -e 's/$/.sfeng/g')
HOST_LIST_FILE=${REPO}/hosts-dos.txt
fi
if [ "${PLATFORM}" = "Linux" ] ; then
COLOR_LS="--color"
elif [ "${PLATFORM}" = "Darwin" ] ; then
COLOR_LS="-G"
fi
PROMPT_COMMAND=exitstatus
BRANCH_REPOS="IMS OS BUILD_SCRIPTS"
BRANCHES="MODEL-PACK"
export PATH=~/bin:/opt/local/bin:/opt/local/sbin:/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin::/usr/bin/X11:${EXTRAPATH}
export EDITOR=vi
export VISUAL=vi
export PAGER=less
export LESS="-ern"
export LANGUAGE=C
export LC_ALL=C
export LANG=C
if [ "${USER}" = "mbrannig" ] ; then
xtitle "${SHORTHOST}"
else
xtitle "${USER}@${SHORTHOST}"
fi
set -o emacs
set -o histexpand
set -o ignoreeof
set -o noclobber
shopt -s cdspell
shopt -s extglob
shopt -s cmdhist
shopt -s checkwinsize
shopt -s histappend
alias more=less
alias ls="ls ${COLOR_LS} -hCF"
alias ll="ls ${COLOR_LS} -l"
alias dir="ls ${COLOR_LS} -lF"
alias df="df -h"
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
alias xr="xrdb ${REPO}/emacs.defaults"
alias help="apropos"
alias reup="source ${REPO}/.bashrc"
## completes
complete -W '$(cd /var/tmp ; "ls" -d BUILD-* | sed -e "s/BUILD-//g" )' sfp
#complete -W '$(cd ~/src/WORK ; find IMS OS MODEL-PACK BUILD_SCRIPTS -maxdepth 1 -type d | xargs )' br
complete -F _branches br
complete -A hostname ssh ping localboot
complete -W '${HOST_LIST}' ssh ping rsh localboot
complete -A export printenv
complete -A variable export local readonly
complete -A enabled builtin
complete -A alias alias unalias
complete -A function function
complete -A shopt shopt
complete -A stopped -P '%' bg
complete -A job -P '%' fg jobs disown
complete -A directory mkdir rmdir
complete -A directory -o default cd
complete -F _vars_functions unset
# bzr
function _bzr_commands()
{
bzr help commands | sed -r 's/^([-[:alnum:]]*).*/\1/' | grep '^[[:alnum:]]'
}
function _bzr()
{
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -W "$(_bzr_commands)" $cur ) )
elif [ $COMP_CWORD -eq 2 ]; then
case "$prev" in
help)
COMPREPLY=( $( compgen -W "$(_bzr_commands) commands" $cur ) )
;;
esac
fi
}
complete -F _bzr -o default bzr