Compare commits

...

2 Commits

Author SHA1 Message Date
xeruf 9f0aae589a config/shell: improve automation scripts 2023-01-31 18:33:04 +01:00
xeruf 99053ecd32 bin: extend scripts for duplicate detection 2023-01-31 18:13:32 +01:00
6 changed files with 71 additions and 13 deletions

View File

@ -1,10 +1,35 @@
test -n "$PS1" || return 0
alias sc="sudo systemctl"
alias scs="sudo systemctl status"
alias sce="sudo systemctl enable --now"
alias scr="sudo systemctl reload-or-restart"
alias status="sudo systemctl list-units --failed || service --status-all; tmux ls; sudo docker ps || sudo systemctl status docker"
test $(id -u) -eq 0 || sudo=sudo
alias sc="$sudo systemctl"
alias scs="$sudo systemctl status"
alias sce="$sudo systemctl enable --now"
alias sced="$sudo --preserve-env=EDITOR systemctl edit"
alias scr="$sudo systemctl reload-or-restart"
highlight() { echo "$1"; }
status() {
highlight 'System'
free -h
df -h -T --exclude-type=tmpfs --exclude-type=devtmpfs --exclude-type=squashfs --exclude-type=overlay
zfs list -d 0
highlight 'Internet'
#--color=always
ip -brief address | grep --color=none -E '^(wl|en|tun|vmbr)'
ip route
echo -n 'IPv4: ' && timeout 3s ping example.com -A -c 3 -w 3 -q -4
echo -n 'IPv6: ' && timeout 3s ping example.com -A -c 3 -w 3 -q -6
highlight 'Programs'
tmux ls
$sudo systemctl --no-pager list-units --failed || service --status-all
if type docker >/dev/null
then $sudo docker ps || $sudo systemctl status docker
fi
}
alias u='$sudo apt update && sudo apt upgrade'
alias ur='u && $sudo reboot'
# Diff recursively
difr() { diff --color=always --unified=1 --recursive "$@" | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen; }

View File

@ -12,7 +12,7 @@ indent_character: '|'
journals:
default: ~/data/2-box/journal/jrnl.txt
intentions: ~/data/2-box/journal/intentions.txt
nug: ~/data/2-box/journal/nugnug.txt
nug: ~/data/2-box/journal/nug.txt
linewrap: 99
tagsymbols: '@'
template: false

View File

@ -316,10 +316,15 @@ sshl() {
local authcache="/var/tmp/ssh-keys"
mkdir -p "$authcache"
local file="$authcache/$1"
ssh -G "$1" | grep --silent "^user root$" &&
! [[ "$1" =~ "pve.*" ]] &&
! [[ "$1" =~ "encee.*" ]] &&
! [[ "$1" =~ ".*fmh.de" ]] &&
pass=pass
test "$all" &&
pass scp ~/.bash_aliases "$1:" &&
pass ssh "$1" 'grep -q ".bash_aliases" .bashrc || echo "source ~/.bash_aliases" >>.bashrc'
if ssh -G "$1" | grep --silent "^user root$" && ! [[ "$1" =~ "pve*" ]]
$pass scp ~/.bash_aliases "$1:" &&
$pass ssh "$1" 'grep -q ".bash_aliases" .bashrc || echo "source ~/.bash_aliases" >>.bashrc'
if test -n "$pass"
then pass ssh "$@"
else
test ! -e "$file" &&

7
.local/bin/scripts/autolight Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh -e
# Automatically set screen brightness based on time of day.
# OLD: value=$(expr 100 - $(expr 13 - $(date +%H) | tr -d -) \* 5)
# S Function: echo "(c($(date +%H) / 4 - 3) + 1) * 50" | bc -l
value=$(echo "l=(100 - 1.5 * ( 11 - $(date +%H) ) ^ 2); if(l > 0) l else 3" | bc -l)
light -S $value
{ date && echo $value; } >>/var/log/autolight

17
.local/bin/scripts/dupcheck Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
# Check the first file against all other ones given and print duplicates.
# Checks first size then diff.
# TODO diff initial bytes
if ! test $# -lt 2
then echo "Need at least 2 files to compare!" 2>/dev/null
exit 2
fi
target="$1"
shift
for existing
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" &&
test "$(stat --format %s "$target")" -eq "$(stat --format %s "$existing")" &&
diff -q "$target" "$existing" >/dev/null &&
echo "$existing"
#test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" &&
done

View File

@ -1,11 +1,15 @@
#!/bin/sh
# Delete files under current or given path which exist elsewhere as listed in the locate database
# Matches first by name, then by checksum (currently inefficiently via md5)
# Delete files under current or given path
# which exist elsewhere as listed by locate.
# Args: [threshold (MB)] <filepaths...>
# OptDepends: synct (for checking against original filename)
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"'
filepath="{}"
target="$(synct-unarchive "$filepath")"
target="$(synct-unarchive "$filepath" || echo "$filepath")"
highlight "$filepath"
for existing in $(locate -b "$target")
do test "$(realpath "$target")" != "$(realpath "$existing")" -a -f "$existing" && test "$(md5sum "$existing" | cut -d\ -f1)" = "$(md5sum "$filepath" | cut -d\ -f1)" && echo "Found duplicate at $existing" && rm -vi "$filepath" && break
do test -n "$(dupcheck "$target" "$existing") &&
echo "Duplicate found at $existing"
rm -vi "$filepath" && break
done' \;