chbg: avoid the TOCTOU race
This commit is contained in:
24
bin/chbg
24
bin/chbg
@@ -1,12 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# to change wallpapers both niri workspace and niri tab view
|
# to change wallpapers both niri workspace and niri tab view
|
||||||
[ -z "$1" ] && {
|
[ -z "$1" ] && {
|
||||||
echo "Usage: ${0##*/} <image-file>"
|
echo "Usage: ${0##*/} <image-file>"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
fsize=$(magick identify -format "%w %h" -- "$1" 2>/dev/null) || {
|
fsize=$(magick identify -format "%w %h" -- "$1" 2>/dev/null) || {
|
||||||
echo "ERROR: unable to identify. is it an EXISTING ACCESSIBLE IMAGE file?"
|
echo "ERROR: unable to identify. is it an EXISTING ACCESSIBLE IMAGE file?"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
WP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
|
WP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||||
@@ -14,14 +14,14 @@ finput=$1
|
|||||||
|
|
||||||
read -r fw fh <<< "$fsize"
|
read -r fw fh <<< "$fsize"
|
||||||
(( fw > 3840 && fh > 2160 )) && {
|
(( fw > 3840 && fh > 2160 )) && {
|
||||||
finput="$(mktemp --dry-run).webp"
|
finput=$(mktemp "${TMPDIR:-/tmp}/chbg.XXXXXXXX.webp")
|
||||||
trap 'rm -f "$finput"' EXIT
|
trap 'rm -f "$finput"' EXIT
|
||||||
echo "WARNING: image too large, resizing ..."
|
echo "WARNING: image too large, resizing ..."
|
||||||
# echo "DEBUG: resized image at $finput"
|
# echo "DEBUG: resized image at $finput"
|
||||||
magick "$1" -resize "3840x2160^" \
|
magick "$1" -resize "3840x2160^" \
|
||||||
-quality 90 \
|
-quality 90 \
|
||||||
-define webp:method=6 \
|
-define webp:method=6 \
|
||||||
-define webp:alpha-quality=100 "$finput"
|
-define webp:alpha-quality=100 "$finput"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo -n "making blurred version of ${1##*/} ... "
|
echo -n "making blurred version of ${1##*/} ... "
|
||||||
|
|||||||
Reference in New Issue
Block a user