2020-08-02 15:26:23 +00:00
|
|
|
#!/bin/bash
|
2020-09-16 06:34:43 +00:00
|
|
|
|
2021-05-20 06:08:49 +00:00
|
|
|
function k3sudo(){
|
|
|
|
# create a passwordless sudo rule on target
|
|
|
|
# usage: k3sudo [add, del] <target ip/hostname>
|
|
|
|
if [[ "$1" == "add" ]];then
|
|
|
|
ssh -t $2 "hostname --long; echo \"$USER ALL=(ALL) NOPASSWD: ALL\" | sudo tee /etc/sudoers.d/k3sup"
|
|
|
|
elif [[ "$1" == "del" ]];then
|
|
|
|
ssh $2 sudo rm /etc/sudoers.d/k3sup
|
|
|
|
else
|
|
|
|
echo "Error: usage: k3sudo [add, del] <target ip/hostname>"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-12-08 11:25:42 +00:00
|
|
|
function pc(){
|
|
|
|
# use pass and copy to clipboard
|
2020-12-08 11:27:24 +00:00
|
|
|
pass -c1 "$@"
|
2020-12-08 11:25:42 +00:00
|
|
|
}
|
|
|
|
complete -o filenames -F _pass pc
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-08 05:05:55 +00:00
|
|
|
function watermark(){
|
|
|
|
# Add watermark text to image (ImageMagick depentant)
|
|
|
|
# $1 = source file
|
|
|
|
# $2 = watermark text
|
|
|
|
# $3 = destination file
|
|
|
|
convert -density 150 -fill "rgba(255,0,0,0.25)" -gravity Center -pointsize 80 -draw "rotate -45 text 0,0 \"$2\"" "$1" "$3"
|
|
|
|
}
|
|
|
|
|
2020-09-16 06:34:43 +00:00
|
|
|
function reset_evolution() {
|
|
|
|
# Reset evolution calendar factory
|
|
|
|
# When it hangs connecting to EWS calendar outlooko365
|
|
|
|
EWS_DEBUG=2 /usr/lib/evolution-data-server/evolution-calendar-factory -w
|
|
|
|
}
|
|
|
|
|
2020-08-01 12:53:37 +00:00
|
|
|
function salt() {
|
2020-08-02 15:26:23 +00:00
|
|
|
if [[ "$1" == "state.apply" ]]; then
|
|
|
|
sudo salt-call --local --file-root "$HOME/salt/states" --pillar-root "$HOME/salt/pillars" "$@" pillar="{username: $USER}"
|
|
|
|
else
|
|
|
|
sudo salt-call --local --file-root "$HOME/salt/states" --pillar-root "$HOME/salt/pillars" "$@"
|
|
|
|
fi
|
2020-03-30 06:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function pw(){
|
2020-07-10 08:23:39 +00:00
|
|
|
FILE="$1"
|
2020-03-30 06:56:05 +00:00
|
|
|
|
2020-07-10 08:23:39 +00:00
|
|
|
[[ -z "$PWHOME" ]] && printf "\$PWHOME not set\n" && return
|
2020-03-30 06:56:05 +00:00
|
|
|
|
2020-07-10 08:23:39 +00:00
|
|
|
[[ -z "$FILE" ]] && FILE="web.gpg"
|
2020-03-30 06:56:05 +00:00
|
|
|
|
2020-07-10 08:23:39 +00:00
|
|
|
if [[ ! "${FILE: -4}" == ".gpg" ]];then
|
|
|
|
FILE="${FILE}.gpg"
|
|
|
|
fi
|
|
|
|
cd "$PWHOME"
|
|
|
|
vi "$FILE"
|
2020-03-30 06:56:05 +00:00
|
|
|
|
2020-07-10 08:23:39 +00:00
|
|
|
cd "$OLDPWD"
|
2020-03-30 06:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_pw_completion()
|
|
|
|
{
|
2020-07-10 08:23:39 +00:00
|
|
|
local cur prev suggestions
|
|
|
|
[[ -z "$PWHOME" ]] && return
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
cd "$PWHOME"
|
|
|
|
suggestions="$(ls *.gpg)"
|
|
|
|
cd "$OLDPWD"
|
|
|
|
if [[ "$prev" != "pw" ]];then
|
|
|
|
COMPREPLY=()
|
|
|
|
else
|
|
|
|
COMPREPLY=( $(compgen -W "${suggestions}" -- ${cur}) )
|
|
|
|
fi
|
2020-03-30 06:56:05 +00:00
|
|
|
}
|
|
|
|
complete -F _pw_completion pw
|
|
|
|
|
|
|
|
function doh()
|
|
|
|
{
|
2020-07-10 08:23:39 +00:00
|
|
|
local options
|
|
|
|
options=(start stop restart status)
|
|
|
|
if [[ ! " ${options[@]} " =~ " ${1} " ]]; then
|
|
|
|
echo "wrong option, valid: ${options[@]}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [[ "$1" == "status" ]]; then
|
|
|
|
systemctl status local-doh-proxy
|
|
|
|
else
|
|
|
|
sudo systemctl "$1" local-doh-proxy
|
|
|
|
fi
|
2020-03-30 06:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function copy_k8s_token(){
|
2020-07-10 08:23:39 +00:00
|
|
|
grep "id-token" ~/.kube/config | awk '{print $2}' | xclip -sel clip
|
2020-03-30 06:56:05 +00:00
|
|
|
}
|
2020-03-30 08:26:30 +00:00
|
|
|
|
2020-04-23 06:06:49 +00:00
|
|
|
function ip_to_hex(){
|
|
|
|
IFS=. read oct1 oct2 oct3 oct4 <<< "$1"
|
|
|
|
printf '0x%02x%02x%02x%02x\n' $oct1 $oct2 $oct3 $oct4
|
|
|
|
}
|
2020-05-09 09:17:42 +00:00
|
|
|
|
|
|
|
function salt-call(){
|
|
|
|
sudo salt-call --local "$@"
|
|
|
|
}
|
2020-07-10 08:23:39 +00:00
|
|
|
|
|
|
|
|
2020-07-10 10:53:42 +00:00
|
|
|
function ww(){
|
2020-07-10 08:23:39 +00:00
|
|
|
local selected_wiki
|
|
|
|
selected_wiki="$1"
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
SUSE|suse|S|s|2)
|
2020-07-13 11:45:26 +00:00
|
|
|
vim -c "normal 2 ww"
|
2020-07-10 08:23:39 +00:00
|
|
|
;;
|
2020-07-13 11:45:26 +00:00
|
|
|
Private|private|p|3)
|
|
|
|
vim -c "normal 3 ww"
|
2020-07-10 08:23:39 +00:00
|
|
|
;;
|
|
|
|
*)
|
2020-07-13 11:45:26 +00:00
|
|
|
vim -c "normal 1 ww"
|
2020-07-10 08:23:39 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2020-09-09 09:21:55 +00:00
|
|
|
|
|
|
|
function ssh(){
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
case "$arg" in
|
|
|
|
-A)
|
|
|
|
read -t 5 -n 1 -s -r -p "Consider to use -o ProxyJump instead! Press 'y' to continue with -A" answer
|
|
|
|
printf "\n"
|
|
|
|
if [[ "${answer,,}" != "y" ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
/usr/bin/ssh "$@"
|
|
|
|
}
|
|
|
|
|