Skip to content

Commit dad9037

Browse files
committed
* pd -> popd
* improved help messages of cli tools * `sysinfocachegen` * `randmac` disabled and deprecated (the corresponding private cli tools were disasbled since macOS Sonoma) * networksetup improvements * `mytorsocks` now sets proxy on all found "Network Services" * improved nix SRI hashes support * legacy nix deprecated stuff was ditched for good * `vn`: verifying notarization
1 parent 597f75f commit dad9037

File tree

1 file changed

+117
-91
lines changed

1 file changed

+117
-91
lines changed

lib.sh

+117-91
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LIBSH_VERSION=20250310_1b90edd
1+
LIBSH_VERSION=20250320_597f75f
22
export LIBSH_VERSION
33
cat <<EOF
44
lib.sh v$LIBSH_VERSION
@@ -16,6 +16,14 @@ set -o pipefail
1616

1717
# helpers
1818

19+
function pd() {
20+
if [ $# = 0 ]; then
21+
popd 1>/dev/null
22+
else
23+
pushd "$1" 1>/dev/null
24+
fi
25+
}
26+
1927
_alias() {
2028
local name="$1"
2129
shift
@@ -187,15 +195,18 @@ alias sinfo=bf # small info
187195
rand() {
188196
if [[ $# == 0 ]]; then
189197
cat <<EOF
190-
the util takes <count> bytes from /dev/random and outputs lower-case hex values
198+
The util takes <count> bytes from /dev/random and outputs lower-case hex values
191199
192-
usage: rand <count> [-f] [-n]
200+
Usage:
201+
rand <count> [-f] [-n]
193202
194-
<count> byte count
195-
-f, --force if count > 64, the flag is required
196-
-n, --newline if specified, '\n' is added after the output
203+
Parameters:
204+
<count> byte count
205+
-f, --force if count > 64, the flag is required
206+
-n, --newline if specified, '\n' is added after the output
197207
198-
example: to get 256 bit nonce use: $(rand 32)
208+
Example:
209+
To get 256 bit nonce use: $(rand 32)
199210
200211
EOF
201212
return 1
@@ -236,19 +247,19 @@ EOF
236247
function randpass() {
237248
if [[ $1 == "--help" || $1 == "-h" ]]; then
238249
cat <<EOF
239-
generates random password
240-
usage: randpass [length]
241-
default length is 16
250+
Generates random password
251+
252+
Usage:
253+
randpass [length]
254+
255+
Parameters:
256+
length length in characters, default is 16
242257
243-
<count> symbol count
244258
EOF
245259
exit 1
246260
fi
247261

248-
if ! command -v python >/dev/null 2>&1; then
249-
echo ERROR: python not found
250-
exit 1
251-
fi
262+
_require python3 || return 1
252263

253264
local length="${1:-16}"
254265

@@ -328,6 +339,8 @@ alias pig=isnet
328339
_salias ap /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
329340
_salias apd /usr/libexec/airportd
330341

342+
_salias sysinfocachegen /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/sysinfocachegen
343+
331344
# use always native ifconfig for the purpose of lib.sh!
332345
_salias ifc /sbin/ifconfig
333346

@@ -410,30 +423,34 @@ if0() {
410423
}
411424

412425
randmac() {
426+
echo "🪦 you've just stumbled upon a tumbstone with the text on it: 🪦"
427+
echo
413428

414-
if (($# > 1)); then
415-
cat <<'EOF'
429+
cat <<'EOF'
416430
Temporary changes network interface mac address. This does not survice a reboot.
417431
418-
usage: randmac [<interface>]
419-
420-
[<interface>] optionally specified interace for the mac address to be set on
421-
EOF
422-
return 1
423-
fi
432+
Usage:
433+
randmac [<interface>]
424434
425-
local interface=en0
435+
Parameters:
426436
427-
if [ "$1" != "" ]; then
428-
interface="$1"
429-
fi
437+
[<interface>] optionally specified interace for the mac address to be set on
438+
EOF
439+
return 1
430440

431-
ap -z
432-
local mac=$(rand 6 | sed -E 's/([0-9a-f]{2})/:\1/g' | sed 's/^://g')
441+
# local interface=en0
442+
#
443+
# if [ "$1" != "" ]; then
444+
# interface="$1"
445+
# fi
446+
#
447+
# ap -z
448+
# local mac=$(rand 6 | sed -E 's/([0-9a-f]{2})/:\1/g' | sed 's/^://g')
449+
#
450+
# echo -- "generated value: $mac; attempting to set..."
451+
# ifc $interface ether "$mac"
452+
# (($? == 0)) && mac && echo done.
433453

434-
echo -- "generated value: $mac; attempting to set..."
435-
ifc $interface ether "$mac"
436-
(($? == 0)) && mac && echo done.
437454
}
438455

439456
alias ms='m status'
@@ -478,16 +495,53 @@ msss() {
478495
printf "\tRelay info:\n\t\t%s\n" "$(m relay get | sed -E 's/^[^:]+: //g')"
479496
}
480497

481-
function nets() {
498+
function netsetup() {
482499
_exec networksetup "$@"
483500

484501
}
485-
function dhinfo() {
486-
nets -getinfo "Wi-Fi" | rg --color=never '(^[^:]+$)|(^[^:]+:.+$)' --replace '$1 $2'
502+
alias nsetup=netsetup
503+
504+
alias _netservices='networksetup -listnetworkserviceorder'
505+
506+
function netservices() {
507+
508+
for ((i = 1; i <= $#; i++)); do
509+
case "${!i}" in
510+
-h | --help)
511+
cat <<'EOF'
512+
513+
Lists macos network services, in their order (priority)
514+
515+
Usage:
516+
netservices [-h|--help] [--json]
517+
518+
Parameters:
519+
--json output JSON
520+
521+
EOF
522+
return 1
523+
;;
524+
525+
--json)
526+
local json=1
527+
_require rg || return 1
528+
;;
529+
esac
530+
done
531+
532+
if [[ $json == 1 ]]; then
533+
_netservices | rg --color never -o 'Hardware Port: ([^,]+), Device: (en[\d]+)' --replace '{"name":"$1","port":"$2"}'
534+
else
535+
_netservices
536+
fi
487537
}
488538

489-
function netsocks() {
490-
nets -setsocksfirewallproxy "Wi-Fi" "$1" "$2"
539+
alias nservices=netservices
540+
alias nsvc=nservices
541+
alias nsvcj='nsvc --json'
542+
543+
function dhinfo() {
544+
netsetup -getinfo "Wi-Fi" | rg --color=never '(^[^:]+$)|(^[^:]+:.+$)' --replace '$1 $2'
491545
}
492546

493547
alias dhi=dhinfo
@@ -570,27 +624,6 @@ alias pxgh='pxg help'
570624
alias hch=hatch
571625
alias ach=hch
572626
alias tch=hch
573-
alias pd=pdm
574-
575-
alias mm=mamba
576-
alias um=micromamba
577-
alias uma='um activate'
578-
alias umd='um deactivate'
579-
alias umc='um env create -n'
580-
alias uml='um env list'
581-
alias umll='um list'
582-
alias umu='um update'
583-
alias umua='umu -a'
584-
585-
umca() {
586-
umc "$1"
587-
uma "$1"
588-
}
589-
590-
alias umi='um install'
591-
alias umr='um remove'
592-
alias umrm='um env remove -n'
593-
alias ums='um search'
594627

595628
# venv / uv
596629
alias _venv='python -m venv'
@@ -1085,6 +1118,7 @@ alias nxconf='nx show-config'
10851118
alias nxc=nxconf
10861119
alias nxsh='nx shell'
10871120
alias nxs='nix-search'
1121+
alias nxsd='nxs -d'
10881122

10891123
alias nxb='nx build'
10901124
alias nxbi="nxb $_nxi"
@@ -1117,7 +1151,8 @@ nxdrvpaths() {
11171151
Prints nix store "requisites" paths for specified derivation(s).
11181152
Useful when one needs to do fine-grained filtering (like for pushing to binary cache).
11191153
1120-
Usage: $0 <derivation...>
1154+
Usage:
1155+
$0 <derivation...>
11211156
EOF
11221157
return 1
11231158
fi
@@ -1138,7 +1173,7 @@ nxfi() {
11381173

11391174
if [[ $1 =~ -h|--help ]]; then
11401175
cat <<'EOF'
1141-
initializes nix flake in the current directory, using one of
1176+
Initializes nix flake in the current directory, using one of
11421177
flake.parts template
11431178
11441179
Usage:
@@ -1239,6 +1274,8 @@ alias nxw='nxp wipe-history'
12391274

12401275
alias nxhash='nx hash'
12411276
alias nxh='nxhash'
1277+
alias nxhsri='nxh to-sri --type sha256'
1278+
alias xsri='xargs nix hash to-sri --type sha256'
12421279

12431280
nxhrand() {
12441281
_require nix || return 1
@@ -1303,36 +1340,8 @@ EOF
13031340
open /Applications/nix
13041341
}
13051342

1306-
# deprecated
1307-
# TODO: remove
1308-
#alias nu-legacy='nix-env --upgrade' # broken allegedly by nixpkgs' 8a5b9ee
1309-
#
1310-
## creates upggradeable list of packages as --attr parameters to nix-env --upgrade
1311-
#_nuattrs() {
1312-
#
1313-
# nix-shell -p ripgrep --run sh < <(
1314-
# cat <<'EOF'
1315-
#nix-env -q | rg -o '^([a-zA-Z-]+)[.-](?:[\d.-]+)*' --replace '--attr nixpkgs.$1' | sed -e 's/-i/I/g;s/-min/Min/g;s/nss-//g;s/-(wrapped|unstable)//g'
1316-
#EOF
1317-
# )
1318-
# return 0
1319-
#}
1320-
#
1321-
#_nu() {
1322-
# _nuattrs $@ | xargs nix-env --upgrade
1323-
#
1324-
#}
1325-
#
1326-
#alias nu-attrs=_nuattrs
1327-
#alias nu='nix-env --upgrade'
1328-
#
1329-
#alias ncu='nix-channel --update'
1330-
#
1331-
#alias u='nix-env -e'
1332-
#alias q='nix-env -q'
1333-
13341343
# direnv / nix-direnv
1335-
alias renv=nix-direnv-reload
1344+
alias dre=nix-direnv-reload
13361345

13371346
# filesystem
13381347

@@ -2784,9 +2793,23 @@ alias rgnc='rg --color=never'
27842793

27852794
# tor
27862795
mytorsocks() {
2787-
_exec netsocks localhost 9050
2796+
# set it up on all the services available
2797+
2798+
_require jq
2799+
2800+
local svcs=
2801+
2802+
mapfile -t svcs < <(netservices --json | jq '.name' -r)
2803+
2804+
for svc in "${svcs[@]}"; do
2805+
netsetup -setsocksfirewallproxy "$svc" localhost 9050
2806+
done
2807+
27882808
tor
2789-
_exec netsocks "" ""
2809+
2810+
for svc in "${svcs[@]}"; do
2811+
netsetup -setsocksfirewallproxy "$svc" "" ""
2812+
done
27902813
}
27912814

27922815
# gollama
@@ -3068,6 +3091,9 @@ snkc() {
30683091
snyk config | rg -o 'INTERNAL_OAUTH_TOKEN_STORAGE: (.+)$' --replace '$1' | jq
30693092
}
30703093
alias snc=snkc
3094+
3095+
alias verifyNotarization='spctl -a -vvv -t install'
3096+
alias vn=verifyNotarization
30713097
# TODO: ✂ - - - - - - - - - - - - - - - - - - -
30723098

30733099
_init() {

0 commit comments

Comments
 (0)