blob: 3fceec87549ee24701c13673b106a00dddc2b927 (
plain) (
blame)
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
|
set_go() {
export GOPATH="${GOPATH:-$HOME/go}"
export PATH="$GOPATH/bin:$PATH"
_gobin="/usr/local/go/bin"
if [ -e "$_gobin" ] ; then
export PATH="$_gobin:$PATH"
fi
}
set_editor() {
if [ -z "$EDITORS" ] ; then
export EDITORS="ed vi vim"
fi
export EDITOR="$(which $EDITORS 2>/dev/null | tail -n1)"
export VISUAL="$EDITOR"
# Set an alias for our editor of choice
alias vi="$EDITOR"
alias vim="$EDITOR"
alias edit="$EDITOR"
alias e="$EDITOR"
}
set_pager() {
export PAGER="$(which cat more less 2>/dev/null | tail -n1)"
}
set_lang() {
export CHARSET="$1";
export LANG="$1";
}
# Usage debugstarttls $ipaddr:$port
debugstarttls() {
openssl s_client -starttls smtp -crlf -connect "$1" "$2"
}
randmacgen() {
if [ "$(uname)" = "FreeBSD" ] ; then
LC_COLLATE=c
fi
tr -c -d '0123456789abcdef' < /dev/urandom \
| head -c 12 \
| sed 's!^M$!!;s!\-!!g;s!\.!!g;s!\(..\)!\1:!g;s!:$!!'
echo ""
}
# First argument is the interface on which to scan
ipv6_local_hosts() {
if ! [ -z $1 ] ; then
interface="$1"
ping6 -c 3 ff02::2%$interface \
| grep 'bytes from' \
| awk '{print $4}' \
| sort \
| uniq \
| sed -e's/:$//'
else
echo "You need to specify an interface"
fi
}
set_nocaps() {
setxkbmap -layout "us,de"
setxkbmap -option ctrl:nocaps
setxkbmap -option shift:breaks_caps
setxkbmap -option numpad:microsoft
setxkbmap -option grp:alt_space_toggle
}
# Usage: dir_oct:file_oct path
setperms() {
_perm="$1"; shift
dir_perms=$(echo "$_perm" | awk -F: '{print $1}')
file_perms=$(echo "$_perm" | awk -F: '{print $2}')
find "$@" -type f -print0 | xargs -0 chmod "$file_perms"
find "$@" -type d -print0 | xargs -0 chmod "$dir_perms"
}
set_title() {
printf $'\033]0;'"%s"$'\007' "$1"
}
set_my_title() {
_load="Load Avg: $(_sys_load)"
_free_mem="M Free: $(_sys_memory)"
_uptime="Uptime: $(_sys_uptime)"
set_title "$(id -un)[$(hostname)] -- $_load $_free_mem $_uptime"
}
_sys_memory() {
! [ -e $(which vmstat) ] && return
if [ `uname` = "Linux" ] ; then
vmstat | tail -n1 | awk '{print $4/1024}' | sed -e's/\..*$//g'
elif [ `uname` = "FreeBSD" ] ; then
vmstat | tail -n1 | awk '{print $5/1024}' | sed -e's/\..*$//g'
elif [ `uname` = "OpenBSD" ] ; then
vmstat | sed -n '$p' | awk '{print $4}' | sed 's/M$//'
fi
}
_sys_load() {
# Works on BSD too, neat.
uptime | sed -re's/^.*load averages?: ([0-9]+\.[0-9]+).*$/\1/g'
}
_sys_uptime() {
# Took awhile to figure out, but this works on BSD as well
uptime | sed -re's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g'
}
timestamp() {
date +%m.%d.%y_%H.%M.%S
}
checkSSHAgent() {
ssh_agent_conf="$HOME/.ssh/agent"
if [ -e "$ssh_agent_conf" ] ; then
. "$ssh_agent_conf"
fi
if ! ps -eo pid | grep -q "$SSH_AGENT_PID" \
|| ! [ -e "$ssh_agent_conf" ] \
|| [ -z "$SSH_AGENT_PID" ] ; \
then
ssh-agent -s | grep -v echo > "$ssh_agent_conf"
. "$ssh_agent_conf"
fi
}
|