-
Notifications
You must be signed in to change notification settings - Fork 0
/
.functions
185 lines (158 loc) · 3.77 KB
/
.functions
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
# collection of shell functions found in dot_files, wikis, etc
# around the world. Some are written by me, of course.
# Trivial conversion of a hex number to decimal
function hex2dec()
{
[ -z "$1" ] && echo "No hex number given" && return
if [[ ${1:0:2} != "0x" ]]; then
echo "Please prefix string with 0x"
return
fi
re='^[0-9a-fA-Fx]+$'
if ! [[ $1 =~ $re ]]; then
echo "Hex only contains 0-9a-fA-F and 0x as prefix"
return
fi
printf "%d\n" $1
}
# Trivial conversion of a decimal number to hex
function dec2hex()
{
[ -z "$1" ] && echo "No decimal number given" && return
re='^[0-9]+$'
if ! [[ $1 =~ $re ]]; then
echo "Decimal only contains 0-9"
return
fi
printf "0x%x\n" $1
}
# Generates a RSA 2048 bit keypair with DUMMY password
function kgenkey()
{
[ -z "$1" ] && echo "No key alias given" && return
keytool -genkeypair -keyalg RSA -keysize 2048 -alias "$1" \
-dname "CN=Unknown,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown" \
-storepass "test123" -keypass "test123" -keystore keystore.jks
}
# Generate a CSR from the keystore generated w/ the cmd above
function kgencsr()
{
[ -z "$1" ] && echo "No key alias given" && return
keytool -certreq -alias "$1" -keystore keystore.jks -file "${1}.csr" \
-storepass "test123" -keypass "test123"
}
function kimportcert()
{
[ -z "$1" ] && echo "No key alias given" && return
[ -z "$2" ] && echo "No cert file given" && return
keytool -import -alias "$1" -file "$2" -keystore keystore.jks \
-storepass "test123" -keypass "test123" -trustcacerts
}
function updatecvs()
{
local _cvsdir=/home/matthias/cvs
rsync -az --delete rsync://ftp.hostserver.de/cvsync/src $_cvsdir/cvs || return 1
cd $_cvsdir/src && cvs -q up -P
}
function cvspsdiff()
{
[ -z "$1" ] && return
cvsps -q -s "$1" -g | cdiff
}
function sshopen()
{
local AGPATH="$HOME"/.ssh/$(hostname).agent
rm -f $AGPATH
command ssh-agent -t 345600 | grep -v echo > $AGPATH
source $AGPATH
# Find all public keys...
for i in `find $HOME/.ssh/ -maxdepth 1 -name "*.pub"`; do
# ... and strip the .pub suffix
_key=`echo $i | sed -e 's/\.pub//'`
command ssh-add $_key
done
}
function psg()
{
ps aux | grep "$@"
}
function ssh()
{
source_ssh_agent
/usr/bin/ssh "$@"
}
function scp()
{
source_ssh_agent
/usr/bin/scp "$@"
}
function sshfs()
{
source_ssh_agent
/usr/bin/sshfs "$@"
}
function source_ssh_agent()
{
local AGPATH="$HOME"/.ssh/$(hostname).agent
[[ -f $AGPATH ]] && source $AGPATH
}
function mkcd()
{
[[ $1 ]] || return 0
[[ -d $1 ]] || mkdir -vp "$1"
[[ -d $1 ]] && builtin cd "$1"
}
function cget()
{
curl -OL --compressed "$@"
}
# Show infos about my external IP address
function showmyipaddress
{
echo "My external IPv4 : $(curl -s -4 icanhazip.com)"
echo "My external IPv6 : $(curl -s -6 icanhazip.com)"
echo "My external PTR : $(curl -s icanhazptr.com)"
}
# Show info about hostname or IP address
function ipif()
{
if grep -P "(([1-9]\d{0,2})\.){3}(?2)" <<< "$1"
then
curl ipinfo.io/"$1"
else
local ipadd=$(host "$1") &&
local ipawk=$(awk '{ print $4 }' <<< "$ipadd")
curl ipinfo.io/"$ipawk"
fi
echo
}
function calc()
{
echo "scale=3;$@" | bc -l
}
function cds()
{
cd "$1" && ls -la
}
function netmnt()
{
ndcli show ip $(dig +short $1) | grep "^pool:" | cut -d':' -f2 | xargs ndcli show pool
}
function whonet()
{
ndcli show ip $1 | grep "^pool:" | cut -d':' -f2 | xargs ndcli show pool
}
# http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
}
function unmark {
rm -i "$MARKPATH/$1"
}
function marks {
ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
}