diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-01-21 15:42:22 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-01-21 15:42:22 +0100 |
| commit | e5f5c9b635dca0c59808c2c2aeb5b5e4d569989e (patch) | |
| tree | 4e5e34d7a44c30dd3d6bb798f17b285eb3d2d1de | |
| parent | 7e5c61de7d243038d058973d191e729e52c4cbd2 (diff) | |
fix bin/update_hosts
| -rwxr-xr-x | bin/cursor | 24 | ||||
| -rwxr-xr-x | bin/cursor-linux | 13 | ||||
| -rwxr-xr-x | bin/update_hosts | 13 |
3 files changed, 46 insertions, 4 deletions
diff --git a/bin/cursor b/bin/cursor new file mode 100755 index 0000000..2ae069b --- /dev/null +++ b/bin/cursor @@ -0,0 +1,24 @@ +#!/bin/sh + +# Set cursor in xterm and compatibles. + +usage="Usage: $0 [black | blue | cyan | gray | green | magenta | orange | red | white | yellow]" + +cursor() { + case $1 in + (0|r|red) set -- '#f00' ;; + (1|n|green) set -- '#5f5' ;; + (2|b|blue) set -- '#55f' ;; + (3|c|cyan) set -- '#0ff' ;; + (4|y|yellow) set -- '#ff0' ;; + (5|m|magenta) set -- '#f0f' ;; + (6|o|orange) set -- '#f80' ;; + (7|g|gr[ae]y) set -- '#888' ;; + (k|black) set -- '#111' ;; + (w|white) set -- '#eee' ;; + esac + printf '\e[2 q\e]12;'$1'\e\' # set non blinking block, then color +} + +case $1 in -*) echo "$usage" >&2; exit 1;; esac +cursor "${1:-$((RANDOM % 8))}" diff --git a/bin/cursor-linux b/bin/cursor-linux new file mode 100755 index 0000000..c283ccc --- /dev/null +++ b/bin/cursor-linux @@ -0,0 +1,13 @@ +#!/bin/sh + +# Set linux console cursor to a non-blinking color. + +case $1 in + (1|r|red) printf '\033[?17;0;64c' ;; + (2|b|blue) printf '\033[?17;0;16c' ;; + (3|g|green) printf '\033[?17;0;32c' ;; + (4|m|magenta) printf '\033[?17;0;80c' ;; + (5|o|orange) printf '\033[?17;0;96c' ;; + (6|c|cyan) printf '\033[?17;0;48c' ;; + (*) echo "usage: $0 blue cyan green magenta orange red" >&2; exit 2 ;; +esac diff --git a/bin/update_hosts b/bin/update_hosts index 74bf25b..54aa528 100755 --- a/bin/update_hosts +++ b/bin/update_hosts @@ -5,13 +5,18 @@ [ "$USER" = root ] || exec sudo "$0" "$@" +cdate=date +case $(uname -s) in +(Darwin) cdate=gdate ;; # install gdate with 'brew install coreutils' +esac + echo 'Checking from https://github.com/StevenBlack/hosts:' lsd=$(curl -s 'https://api.github.com/repos/StevenBlack/hosts/commits?path=hosts&page=1&per_page=1' | jq -r '.[0].commit.committer.date') -#echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" -echo "last source update: $(date --date="$lsd")" +echo "last source update: $(date -j -f "%FT%TZ" "$lsd")" +#echo "last source update: $(date --date="$lsd")" # with BSD date echo "last local update: $(date -r /etc/hosts)" -# [ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit -[ $(date --date="$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit +[ $(date -j -f "%FT%TZ" "$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit +# [ $(date --date="$lsd" +%s) -lt $(date -r /etc/hosts +%s) ] && echo 'Nothing to do' && exit # with BSD date # with BSD date cd /etc cp -p hosts hosts.old |
