1 # collection of shell functions found in dot_files, wikis, etc
2 # around the world. Some are written by me, of course.
4 # Trivial conversion of a hex number to decimal
7 [ -z "$1" ] && echo "No hex number given" && return
8 if [[ ${1:0:2} != "0x" ]]; then
9 echo "Please prefix string with 0x"
13 if ! [[ $1 =~ $re ]]; then
14 echo "Hex only contains 0-9a-fA-F and 0x as prefix"
20 # Trivial conversion of a decimal number to hex
23 [ -z "$1" ] && echo "No decimal number given" && return
25 if ! [[ $1 =~ $re ]]; then
26 echo "Decimal only contains 0-9"
32 # Generates a RSA 2048 bit keypair with DUMMY password
35 [ -z "$1" ] && echo "No key alias given" && return
36 keytool -genkeypair -keyalg RSA -keysize 2048 -alias "$1" \
37 -dname "CN=Unknown,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown" \
38 -storepass "test123" -keypass "test123" -keystore keystore.jks
41 # Generate a CSR from the keystore generated w/ the cmd above
44 [ -z "$1" ] && echo "No key alias given" && return
45 keytool -certreq -alias "$1" -keystore keystore.jks -file "${1}.csr" \
46 -storepass "test123" -keypass "test123"
49 function kimportcert()
51 [ -z "$1" ] && echo "No key alias given" && return
52 [ -z "$2" ] && echo "No cert file given" && return
53 keytool -import -alias "$1" -file "$2" -keystore keystore.jks \
54 -storepass "test123" -keypass "test123" -trustcacerts
59 local _cvsdir=/home/matthias/cvs
60 rsync -az --delete rsync://ftp.hostserver.de/cvsync/src $_cvsdir/cvs || return 1
61 cd $_cvsdir/src && cvs -q up -P
67 cvsps -q -s "$1" -g | cdiff
72 local AGPATH="$HOME"/.ssh/$(hostname).agent
75 command ssh-agent -t 345600 | grep -v echo > $AGPATH
78 # Find all public keys...
79 for i in `find $HOME/.ssh/ -maxdepth 1 -name "*.pub"`; do
80 # ... and strip the .pub suffix
81 _key=`echo $i | sed -e 's/\.pub//'`
109 function source_ssh_agent()
111 local AGPATH="$HOME"/.ssh/$(hostname).agent
113 [[ -f $AGPATH ]] && source $AGPATH
119 [[ -d $1 ]] || mkdir -vp "$1"
120 [[ -d $1 ]] && builtin cd "$1"
125 curl -OL --compressed "$@"
128 # Show infos about my external IP address
129 function showmyipaddress
131 echo "My external IPv4 : $(curl -s -4 icanhazip.com)"
132 echo "My external IPv6 : $(curl -s -6 icanhazip.com)"
133 echo "My external PTR : $(curl -s icanhazptr.com)"
136 # Show info about hostname or IP address
139 if grep -P "(([1-9]\d{0,2})\.){3}(?2)" <<< "$1"
143 local ipadd=$(host "$1") &&
144 local ipawk=$(awk '{ print $4 }' <<< "$ipadd")
145 curl ipinfo.io/"$ipawk"
152 echo "scale=3;$@" | bc -l
162 ndcli show ip $(dig +short $1) | grep "^pool:" | cut -d':' -f2 | xargs ndcli show pool
167 ndcli show ip $1 | grep "^pool:" | cut -d':' -f2 | xargs ndcli show pool
170 # http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
172 export MARKPATH=$HOME/.marks
174 cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
177 mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
183 ls -l "$MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo