Skip to content

Instantly share code, notes, and snippets.

@Ykidia
Ykidia / ts5b-watchdog.sh
Created June 19, 2026 18:07
SOCKS checker
#!/bin/sh
get_script_dir() { case "${0}" in *"/"*) d="${0%/*}";; *) d=.;; esac; CDPATH="" cd -- "${d}" && pwd -P; }
try_lib_at() { f="${1}/libshell.sh"; [ -r "${f}" ] && . "${f}" 2>/dev/null; }; _THIS_DIR_="$(get_script_dir)"
if ! try_lib_at "${_THIS_DIR_}/.."; then if ! try_lib_at "${_THIS_DIR_}/../common"; then
if ! try_lib_at "${_THIS_DIR_}"; then echo "Error loading library."; exit 1; fi; fi; fi
ts5b_update_only=0
ts5b_check_retry=5
@Ykidia
Ykidia / libshell.sh
Created June 19, 2026 18:10
Common shell library
#!/bin/sh
LC_ALL=C
PATH="/usr/sbin:/usr/bin:/sbin:/bin"
re_ip4s='([0-1]([0-9][0-9]?)?|2([0-4][0-9]?|5[0-5]?|[6-9])?|[3-9][0-9]?)'
re_ip4address='('"${re_ip4s}"'\.){3,3}'"${re_ip4s}"
re_ip4nopub='(^0\.0\.0\.0)|(^127\.)|(^10\.)|(^192\.168\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)'
re_ip4subnet='([0-2][0-9]?|3[0-2]?|[3-9])'
re_ip6s='[0-9a-fA-F]{1,4}'