bin: improve scripts

This commit is contained in:
xeruf 2023-05-09 14:02:32 +02:00
parent 5d7deb24d7
commit 027ab59aab
7 changed files with 55 additions and 22 deletions

View File

@ -2,8 +2,8 @@
# Check the first file against all other ones given and print duplicates. # Check the first file against all other ones given and print duplicates.
# Checks first size then diff. # Checks first size then diff.
# TODO diff initial bytes # TODO diff initial bytes
if ! test $# -lt 2 if test $# -lt 2
then echo "Need at least 2 files to compare!" 2>/dev/null then echo "Need at least 2 files to compare!" >&2
exit 2 exit 2
fi fi
target="$1" target="$1"

View File

@ -3,13 +3,22 @@
# which exist elsewhere as listed by locate. # which exist elsewhere as listed by locate.
# Args: [threshold (MB)] <filepaths...> # Args: [threshold (MB)] <filepaths...>
# OptDepends: synct (for checking against original filename) # OptDepends: synct (for checking against original filename)
case $1 in ([0-9]|[0-9][0-9]) threshold=$1; shift;; esac while test $# -gt 0; do
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'"' case "$1" in
filepath="{}" ([0-9]|[0-9][0-9]) threshold=$1;;
target="$(synct-unarchive "$filepath" || echo "$filepath")" (-n) noscan=$1;;
highlight "$filepath" (-v) verbose=$1; set -x;;
for existing in $(locate -b "$target") (*) break;;
do test -n "$(dupcheck "$target" "$existing") && esac
echo "Duplicate found at $existing" shift
rm -vi "$filepath" && break done
test "$noscan" || "Updating Locate Database..." && sudo updatedb
find "$@" -size +${threshold:-50}M -type f -exec sh -c "IFS=$'\n'; verbose='$verbose'"'
target="$(synct-unarchive "{}" || echo "{}")"
highlight "{}"
for existing in $(locate -b "$(basename "$target")")
do test "$verbose" && echo "Checking $existing against {}"
test -n "$(dupcheck "{}" "$existing")" &&
echo "Duplicate found at $existing" &&
rm -vi "{}" && break
done' \; done' \;

3
.local/bin/scripts/nas Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh -e
cd /mnt/nas
find -mindepth 1 -maxdepth 1 -exec mount {} \;

View File

@ -5,4 +5,5 @@ pkill --echo --ignore-case discord
pkill --echo signal pkill --echo signal
pkill --echo aw-server pkill --echo aw-server
pkill --echo aw-qt pkill --echo aw-qt
systemctl stop --user syncthing plasma-baloorunner kde-baloo openvpn-client@deltaPeak.service systemctl stop --user syncthing plasma-baloorunner kde-baloo
systemctl stop openvpn-client@deltaPeak.service

View File

@ -1,6 +1,7 @@
#!/bin/sh -ex #!/bin/sh -ex
test "$1" = "-q" && quiet=$1 && shift test "$1" = "-q" && quiet=$1 && shift
test ! -r "$1" && echo "Usage: sign <document.pdf> [hoffset (-160) [voffset (-310) [scale [signature-image]]]]" && exit 1 case "$1" in ([0-9]) page=$1; shift;; esac
test ! -r "$1" && echo "Usage: sign [page] <document.pdf> [hoffset (-160) [voffset (-310) [scale [signature-image]]]]" && exit 1
signature=$(pass info/signature$(test -n "$5" && echo "-$5") || echo "$5") signature=$(pass info/signature$(test -n "$5" && echo "-$5") || echo "$5")
@ -22,15 +23,18 @@ fi
export TEXMF="" export TEXMF=""
pdfjam $quiet "$signature" --outfile "$sig" --papersize "{595pt, 842pt}" --noautoscale true \ pdfjam $quiet "$signature" --outfile "$sig" --papersize "{595pt, 842pt}" --noautoscale true \
--offset "${h}pt ${v}pt" --scale "${4:-1}" --offset "${h}pt ${v}pt" --scale "${4:-1}"
pdfjam $quiet "$1" last "$sig" --outfile "$tmp_signed" --delta "0 -842pt" --nup "1x2" --fitpaper true pdfjam $quiet "$1" ${page:-last} "$sig" --outfile "$tmp_signed" --delta "0 -842pt" --nup "1x2" --fitpaper true
# TODO consider pdftk stamp # TODO consider pdftk stamp
timg "$tmp_signed" timg "$tmp_signed"
# https://apple.stackexchange.com/questions/198854/shell-command-to-count-pages-in-a-pdf-other-than-pdftk # https://apple.stackexchange.com/questions/198854/shell-command-to-count-pages-in-a-pdf-other-than-pdftk
if test "$(pdftk "$1" dump_data | grep Pages | cut -d' ' -f2)" -gt 1 if test "$page"
then pdfjam $quiet "$1" 1-$(expr $page - 1) "$tmp_signed" 1 "$1" $(expr $page + 1)-last --outfile "$result"
elif test "$(pdftk "$1" dump_data | grep Pages | cut -d' ' -f2)" -gt 1
then then
pdfjam $quiet "$1" last-1 --outfile "$tmp_reversed" pdfjam $quiet "$1" last-1 --outfile "$tmp_reversed"
pdfjam $quiet "$tmp_reversed" last-2 "$tmp_signed" --outfile "$result" pdfjam $quiet "$tmp_reversed" last-2 "$tmp_signed" --outfile "$result"
else cp "$tmp_signed" "$result" else cp "$tmp_signed" "$result"
fi fi

2
.local/bin/scripts/topng Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
convert -background white -density 500 "$@" "$1.png"

View File

@ -2,18 +2,32 @@
# Update an Easy2Boot USB Stick after adding ISOs # Update an Easy2Boot USB Stick after adding ISOs
# Call with Linux ISOs to be copied as args # Call with Linux ISOs to be copied as args
# Need to be around E2B mountpoint if it is not the default # Need to be around E2B mountpoint if it is not the default
if ! dir="$(find . "${MNT:-${XDG_RUNTIME_DIR}/mnt}" -maxdepth 3 -name _ISO -type d | grep .)" if ! dir="$(find . "${MNT:-${XDG_RUNTIME_DIR}/mnt}" -maxdepth 3 -name _ISO -type d | grep --max-count 1 .)"
then echo "Please mount your multiboot stick first!" then echo "Please mount your multiboot stick first!"
exit 1 exit 1
fi fi
cmd=mv cmd=cp
case $1 in case $1 in
(-upgrade) upgrade=$2; shift 2;;
(-cp) cmd=cp; shift;; (-cp) cmd=cp; shift;;
(-mv) cmd=mv; shift;;
esac esac
test $# -eq 0 || $cmd -vi "$@" "$dir/LINUX" test $# -eq 0 || $cmd -vi "$@" "$dir/LINUX"
find "$dir" -type f -iname "*32-*.iso" -exec mv -vi {} {}def32 \; find "$dir" -type f -iname "*32-*.iso" -exec mv -vi {} {}def32 \;
find "$dir" -type f -name "*.iso" -exec mv -vi {} {}def64 \; find "$dir" -type f -name "*.iso" -exec mv -vi {} {}def64 \;
drive=$(mount | grep "$(dirname "$dir")" | cut -d' ' -f1) mountdir="$(dirname "$dir")"
sudo umount $drive drive=$(mount | grep "$mountdir" | cut -d' ' -f1)
sudo udefrag $drive sudo umount "$drive"
if test "$upgrade"; then
echo "Do you want to reformat $drive as NTFS? (Ctrl-C to abort)"
read
mkfs -t ntfs "$drive"
ntfslabel "$drive" "E2B"
sudo mount "$drive" "$mountdir"
unzip "$upgrade" -d "$mountdir"
touch -v "$dir/nodelay.txt"
cp -v /mnt/nas/media/iso/utilities/*.iso "$dir/UTILITIES"
else
sudo udefrag -m "$drive"
fi