108 lines
2.5 KiB
Bash
Executable File
108 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Bash Functions sourced by .bashrc / .sshrc
|
|
#
|
|
|
|
# Get SSL Certificate information
|
|
# Based on https://serverfault.com/questions/661978/displaying-a-remote-ssl-certificate-details-using-cli-tools
|
|
function getCertInfo() {
|
|
local myServer=${1:?a Servername is required}
|
|
local myPort=${2:-443}
|
|
|
|
echo | openssl s_client -showcerts -servername "$myServer" -connect "$myServer":"$myPort" 2>/dev/null | openssl x509 -inform pem -noout -text
|
|
}
|
|
|
|
#
|
|
# Some functions (some by c't magazine)
|
|
#
|
|
|
|
# change directory and list
|
|
cdl() {
|
|
if cd "$@"; then
|
|
ls
|
|
fi
|
|
}
|
|
|
|
backup() {
|
|
# local @files = "$@"
|
|
for f in "$@"
|
|
do
|
|
if [ -d "$f" ]; then
|
|
cp -p -r "$f" "$f".backup-"$(date +%Y-%m-%d_%H_%M_%S)"
|
|
else
|
|
cp -p "$f" "$f".backup-"$(date +%Y-%m-%d_%H_%M_%S)"
|
|
fi
|
|
done
|
|
}
|
|
|
|
extract() {
|
|
case $1 in
|
|
*.tar.bz2) tar xvjf "$1";;
|
|
*.tar.gz|*.tgz) tar xvfz "$1";;
|
|
*.zip) unzip "$1";;
|
|
*) echo "Not supported: $1";;
|
|
esac
|
|
}
|
|
|
|
# Misc functions
|
|
|
|
# convert epoch timestamp to human readable date
|
|
epoch2date() {
|
|
local string="${1:-0}"
|
|
date -d "@$string"
|
|
}
|
|
|
|
# inspired by
|
|
# https://unix.stackexchange.com/questions/59501/convert-file-path-to-uri-in-bash
|
|
# https://www.unix.com/shell-programming-and-scripting/159863-how-store-files-names-directory-array.html
|
|
file2uri() {
|
|
local root=${1:-.}
|
|
local filter=${2:-*}
|
|
|
|
if ! python3 --version &> /dev/null
|
|
then
|
|
echo "python not available!"
|
|
return 2
|
|
fi
|
|
|
|
echo "get files for $root"
|
|
#for f in "$root/*"; do
|
|
# echo "checking $f"
|
|
# if [ -f $f ]; then
|
|
# echo "is a file: $f"
|
|
# python -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f"
|
|
# fi
|
|
#done
|
|
|
|
# arr_uris=(`ls $root/*.ma4`)
|
|
|
|
arr=()
|
|
for f in $root/*.m4a; do
|
|
echo "f: $f"
|
|
echo python3 -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f"
|
|
uri=$(python3 -c "import sys, pathlib; print(pathlib.Path(input()).resolve().as_uri())" <<< "$f")
|
|
arr[${#arr[@]}]="$uri"
|
|
done
|
|
for a in "${arr[@]}"; do
|
|
echo "$a"
|
|
done
|
|
}
|
|
|
|
enqueueFiles() {
|
|
local root="${1:-.}"
|
|
|
|
if ! rhythmbox-client --version &> /dev/null
|
|
then
|
|
echo "No rhythmbox-client available!"
|
|
return 3
|
|
fi
|
|
|
|
file2uri "$root"
|
|
# echo "Array is ${arr[*]}"
|
|
for a in "${arr[@]}"; do
|
|
echo rhythmbox-client --no-start --enqueue $a
|
|
done
|
|
}
|
|
|
|
PATH=$PATH:$HOME/bin
|