-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_bash_aliases
More file actions
512 lines (441 loc) · 14.4 KB
/
dot_bash_aliases
File metadata and controls
512 lines (441 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# keychain
# keychain --eval --lockwait 45 --quick \
# ~/Documents/bunker/pwet
# tilix vte
if [[ "$TILIX_ID" ]] || [[ "$VTE_VERSION" ]]; then
source /etc/profile.d/vte-2.91.sh
fi
# aliases
alias bazel='bazelisk'
alias cat='bat --plain --no-pager'
alias dotadd='chezmoi add'
alias dotdir='cd ~/.local/share/chezmoi'
alias kubelog='kubeLog'
alias kubelogs='kubeLog'
alias l='ls -CF'
alias la='ls -A'
alias less='bat --color always --decorations always'
alias ll='ls -alF'
alias meteo='curl -s https://wttr.in/Lyon'
alias myip='dig txt +short o-o.myaddr.l.google.com @ns1.google.com'
alias pingtcp='nping --traceroute --tcp-connect -p443 --delay 0ms --count 10'
alias pip='pip3'
alias grep='rg'
alias skynet='ansible-playbook'
alias top='btm --dot_marker --tree --theme nord'
alias pgrep='pgrep -laf'
alias k='kubectl'
alias kube='kubectl'
alias vim='micro'
alias vi='micro'
alias opencode='nono run --profile skynet --allow-cwd -- opencode'
# functions
amqt() {
curl -s https://amp.cloudflare.com/q/${1} | jq;
}
# ecdsa key
crtgenkey() {
openssl ecparam -name prime256v1 -genkey -out "$1";
}
# csr req
# optional subjectAltName if needed
# -subj
# "/C=US/ST=NY/L=NYC/O=Alphabet/OU=Google/
# CN=*.google.com/subjectAltName=DNS.1=google.com/
# emailAddress=infra@google.com"
crtgencsr() {
openssl req -new -nodes -sha256 -key "$1.key" -out "$2.csr";
}
# x509 ecdsa self-signed cert with sha256 mac
crtgen() {
genecdsa selfkey.pem && \
openssl req -x509 -days 1095 -nodes \
-sha256 -new -key selfkey.pem -out selfcert.pem;
}
# csr req details
csrinfo() { openssl req -noout -text -in "$1"; }
# ecdsa key details
ecinfo() { openssl ec -in "$1" -text -noout; }
# x509 cert details
crtinfo() { openssl x509 -in "$1" -noout -text; }
# web stream download
tvdl() {
youtube-dl $1 -f '[width=?640]' \
--max-filesize 1536M --referer "http://www.arte.tv" \
--user-agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.166 Safari/537.36 OPR/20.0.1396.73172";
}
# fuse mount of hubic
hubicmount() {
hubicfuse /mnt/hubic -o noauto_cache,sync_read,noatime,nodev,noexec;
}
# file sync with hubic
hubicsync() {
if [[ -d /mnt/hubic ]]; then
rsync -avhc --max-size=100M --inplace "${1}" "${2}"
else
echo "hubicfuse unmounted. rsync impossible."
exit 1
fi
}
# ansible helpers
skynetGo() {
if [[ -n "${1}" ]]; then
echo -e "\n...Starting Ansible play : ${1}\nChecking the syntax\n";
skynet -vv --syntax-check "${1}";
echo -e "\nPress a key to continue...\n";
read;
echo -e "Running Ansible play : ${1}";
skynet -Dv "${1}";
echo -e "\nDone.\n";
fi
}
skynetTest() {
if [[ -n "${1}" ]]; then
echo -e "\n...Starting Ansible play : ${1}\nChecking the syntax\n";
skynet -vv --syntax-check "${1}";
echo -e "\nPress a key to continue...\n";
read;
echo -e "Show Ansible play diff (check mode) : ${1}";
skynet -CD "${1}";
echo -e "\nDone.\n";
fi
}
# wireguard helpers
wgvpnup() {
# client
crts_path="~/Documents/bunker/certs"
if [[ ! -e ${crts_path}/wgd-private-key ]]; then
wg genkey>${crts_path}/wgd-private-key
echo "Get the pre-shared keys (wgd-preshared-key) on the server side"
fi
sudo bash -c "
crts_path="${HOME}/Documents/bunker/certs"
ip link add dev wg0 type wireguard
ip address add 192.168.150.2/24 dev wg0
wg set wg0 listen-port 57932 private-key "${crts_path}/wgd-private-key"
wg set wg0 peer "uberBase64"\
preshared-key "${crts_path}/wgd-preshared-key"\
allowed-ips "0.0.0.0/0"\
endpoint "1.2.3.4:57932"\
persistent-keepalive 120
ip link set up dev wg0
# use the true default route to access wireguard server
gw=$(ip route | grep -oP 'default\Wvia.*wlp58s0' | sed 's/default/1.2.3.4/g')
ip route add ${gw}
# route all the trafic through wireguard int
ip route add 0.0.0.0/0 via 192.168.150.1 dev wg0
"
}
wgvpndn() {
sudo ip link delete wg0
sudo ip route del 0.0.0.0/0 via 192.168.150.1 dev wg0
}
# vmware govc
vmwareSearchByIp () {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (IP) allowed'; return; }
govc vm.info -vm.ip ${1}
}
vmwareSearchByName () {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (DNS) allowed'; return; }
govc vm.info -vm.dns ${1}
}
# tilix configuration helpers
backupTilixConfig () {
type tilix &>/dev/null || { echo 'Tilix not installed, quitting'; return; }
dconf dump /com/gexperts/Tilix/ > ~/.config/tilix/tilix.conf
}
restoreTilixConfig () {
type tilix &>/dev/null || { echo 'Tilix not installed, quitting'; return; }
dconf load /com/gexperts/Tilix/ < ~/.config/tilix/tilix.conf
}
# gpg
gpgExport () {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (key ID) allowed'; return; }
gpg --list-key && echo
gpg --armor --export ${1}
}
# qemu
qemuRun () {
local _ARCH="x86_64"
local _ACCEL="kvm:tcg"
local _RAM="1G"
local _DRIVE="${1}"
local _KEYMAP="en-us"
local _DISPLAY="gtk"
sudo qemu-system-${_ARCH} \
-boot once="d",menu=on,splash-time=10000 \
-drive file=${_DRIVE},if=virtio,cache=writeback,discard=ignore,format=qcow2,detect-zeroes=off \
-accel "${_ACCEL} \
-m "${_RAM} \
-k ${_KEYMAP} \
-display ${_DISPLAY} \
-name "QEMU-${_DRIVE}"
}
# extraction helper
extract () {
if [[ -f ${1} ]]; then
case ${1} in
*.tar.bz2) tar xjvf $1 ;;
*.tar.gz) tar xzvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xjvf $1 ;;
*.tgz) tar xzvf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# nmcli wifi
nmcliWifiList () {
nmcli device wifi rescan
nmcli device wifi list
}
nmcliWifiConnect () {
nmcli con add con-name "${1}" ifname wlp3s0 type wifi ssid "${1}" \
autoconnect yes ipv4.dns "9.9.9.9,1.1.1.1"
nmcli con modify ${1} wifi-sec.key-mgmt wpa-psk
nmcli con modify ${1} wifi-sec.psk ${2}
nmcli con show
nmcli con up ${1}
}
# aws
ecrLogin() {
eval "$(aws ecr get-login \
--no-include-email \
--region us-west-2 \
--profile common
)"
}
ec2List() {
aws ec2 describe-instances \
--filters Name=tag-key,Values=Name \
--query 'Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value}' \
--output table
}
eksListAddons() {
aws eks describe-addon-versions \
--kubernetes-version 1.29 \
--query 'addons[].{Name: addonName, Owner: owner Publisher: publisher, Type: type, latest: addonVersions[0].addonVersion}' \
--output table
}
# ebooks
syncEbooks() {
local _backend=gdrive:documentation/Calibre/
local _source=~/Documents/ebook/Calibre/
local _bwlimit=80k
rclone --fast-list copy --progress \
${_source} ${_backend} --dry-run
read -n 1 -rep "Launch the copy ? [Y/n]" _reply
case ${_reply:-Y} in
("y"|"Y")
rclone --bwlimit ${_bwlimit} --fast-list --transfers 4 --update \
copy --progress ${_source} ${_backend}
;;
("n"|"N")
echo "canceling, doing nothing..."
;;
(*)
echo "invalid choice, must be yY or nN"
;;
esac
}
# kubernetes
kubeEvents() {
[[ ${#} == 0 ]] || { echo 'Syntax error, no argument expected'; return; }
viddy -n 5 kubectl get events --sort-by=lastTimestamp
}
kubeDebugPod() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (pod name) allowed'; return; }
local _debug_image="268380563144.dkr.ecr.us-west-2.amazonaws.com/tenten-debug"
kubectl debug pod/"$1" --stdin --tty --image="$_debug_image" --container=debug --profile=sysadmin -- bash
}
kubeDebugIstioProxy() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (pod name) allowed'; return; }
local _debug_image="268380563144.dkr.ecr.us-west-2.amazonaws.com/tenten-debug"
kubectl debug pod/"$1" --stdin --tty --image="$_debug_image" --container=debug --target=istio-proxy --profile=sysadmin -- bash
}
kubeDebugNode() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (node name) allowed'; return; }
local _debug_image="268380563144.dkr.ecr.us-west-2.amazonaws.com/tenten-debug"
kubectl debug node/"$1" --stdin --tty --image="$_debug_image" --container=debug --profile=sysadmin -- bash
}
kubeGetPod() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (pod name) allowed'; return; }
kubectl get po \
"$1" --output yaml | bat --theme Nord --language yaml
}
kubeDeleteAllPods() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (namespace) allowed'; return; }
read -n 1 -rep "Are you sure to delete all pods in $1 namespace ? [y/N]" _reply
case ${_reply:-N} in
("y"|"Y")
kubectl get po \
--namespace "$1" --output custom-columns=POD:.metadata.name --no-headers | \
xargs -I{} -P50 -- echo kubectl --namespace "$1" delete po {}
;;
("n"|"N")
echo "canceling, doing nothing..."
;;
(*)
echo "invalid choice, must be yY or nN"
;;
esac
}
kubeFailedPods() {
kubectl get po \
--field-selector=status.phase=Failed \
-o custom-columns=CONTAINER:.metadata.name,NODE:.spec.nodeName,REASON:.status.message
}
kubePendingPods() {
kubectl get po \
--field-selector=status.phase=Pending \
--output custom-columns=CONTAINER:.metadata.name,NODE:.spec.nodeName,PHASE:.status.phase,REASON:.status.message \
--all-namespaces
}
kubeGenerateYaml() {
kinds=(clusterrole
clusterrolebinding
configmap
cronjob
deployment
ingress
job
namespace
poddisruptionbudget
priorityclass
quota
role
rolebinding
secret
service
serviceaccount
token)
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (kind) allowed'; return;}
[[ ${kinds[*]} =~ ${1} ]] || { echo "Kind error, must be one of ${kinds[*]}"; return; }
kubectl create "$1" cyberpunkYaml --image=uberImage --namespace=cryptoNamespace --dry-run=client --output=yaml
}
kubePodsPerNodeLabel() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (node label key=value) allowed'; return;}
echo "Getting all pods located on nodes with $1 label"
kubectl get no -l "$1" -ojsonpath='{.items[*].metadata.name}' | \
xargs -P1 -I## -d' ' \
-- kubectl get po --all-namespaces -ojsonpath='Kubernetes Node: "##"{"\n"}{range .items[?(@.spec.nodeName=="##")]}{"\t"}{.metadata.name} (node: {.spec.nodeName}) {"\n"} {end}{"\n"}'
}
kubePodsPerNodeName() {
[[ ${#} -ge 1 && ${#} -le 10 ]] || { echo 'Syntax error, a maximum of 10 node names is allowed'; return;}
echo "Getting all pods located on nodes named $@"
echo -n "$@" | \
xargs -P1 -I## -d' ' \
-- kubectl get po --all-namespaces -ojsonpath='Kubernetes Node: "##"{"\n"}{range .items[?(@.spec.nodeName=="##")]}{"\t"}{.metadata.name} (node: {.spec.nodeName}) {"\n"} {end}{"\n"}'
}
kubeLog() {
kubectl stern \
"${1}" \
--color always \
--highlight 'err' \
--since 30m \
--tail 25 \
--max-log-requests 100 \
--timestamps short \
--diff-container \
--all-namespaces
}
function ciliumAllEndpoints {
kubectl get cep --all-namespaces -ojson | jq -r '.items[].metadata | .namespace + "/" + .name';
}
function ciliumAllPods {
kubectl get pods --all-namespaces -ojson | \
jq -r '.items[] | select((.status.phase=="Running" or .status.phase=="Pending") and (.spec.hostNetwork==true | not)) | .metadata | .namespace + "/" + .name';
}
ciliumNotManagedPods() {
echo "Skipping pods with host networking enabled or with status not in Running or Pending phase..."
sort <(ciliumAllEndpoints) <(ciliumAllPods) | uniq -u
}
sopsEncrypt() {
type sops &>/dev/null || { echo 'sops not installed, quitting'; return; }
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (file path) allowed'; return; }
sops -i -e --verbose "$1"
}
sopsDecrypt() {
type sops &>/dev/null || { echo 'sops not installed, quitting'; return; }
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (file path) allowed'; return; }
sops -i -d --verbose "$1"
}
codeStart() {
local _server_id=9f9af7d0-a7d2-4677-8215-1c2e6ee25b3b
scw instance server start $_server_id --wait
}
codeStop() {
local _server_id=9f9af7d0-a7d2-4677-8215-1c2e6ee25b3b
scw instance server stop $_server_id --wait
}
curlDebugCdn() {
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (url) allowed'; return;}
curl -o/dev/null -vIH 'X-EC-Debug: x-ec-cache,x-ec-check-cacheable,x-ec-cache-key,x-ec-cache-state' "$1"
}
bcryptHash() {
case ${1} in
"")
local _uuid=$(uuidgen --random)
python3 -c "import bcrypt; print('$_uuid' + ': ' + bcrypt.hashpw(b'$_uuid', bcrypt.gensalt(12)).decode('utf-8'))"
;;
*)
[[ ${#} == 1 ]] || { echo 'Syntax error, only one argument (string) allowed'; return;}
python3 -c "import bcrypt; print('$1' + ': ' + bcrypt.hashpw(b'$1', bcrypt.gensalt(12)).decode('utf-8'))"
;;
esac
}
llamaCppBuildAndDeploy() {
local _required_dir="llama.cpp"
local _current_dir
_current_dir=$(basename "$(pwd)")
if [[ "${_current_dir}" != "${_required_dir}" ]]; then
echo "Error: Execution directory must be '${_required_dir}'. Current: '${_current_dir}'" >&2
return 1
fi
# build
echo "Starting optimized build for ${_required_dir}..."
cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_CCACHE=ON \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_CUDA=ON \
-DGGML_VULKAN=ON \
-DGGML_NATIVE=ON \
-DCMAKE_CUDA_ARCHITECTURES="86;89" \
-DGGML_CUDA_ENABLE_UNIFIED_MEMORY=1 \
-DLLAMA_BUILD_TESTS=OFF \
-DLLAMA_BUILD_EXAMPLES=ON \
-DLLAMA_BUILD_SERVER=ON || {
echo "Error: CMake configuration failed." >&2
return 1
}
local _cpu_cores
_cpu_cores=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
echo "Compiling with ${_cpu_cores} cores..."
cmake --build build --target llama-server llama-bench llama-cli llama-quantize --config Release -j "${_cpu_cores}" || {
echo "Error: Build failed." >&2
return 1
}
# deployment
local _dest_dir="${HOME}/.local/bin"
local _src_dir="build/bin"
echo "Deploying binaries from ${_src_dir} to ${_dest_dir}..."
find "${_src_dir}" -maxdepth 1 -type f -executable -exec cp -vp {} "${_dest_dir}/" \; || {
echo "Error: Failed to copy binaries to ${_dest_dir}" >&2
return 1
}
# cleanup
echo "Cleaning up build artifacts..."
cmake --build build --target clean || {
echo "Warning: Build cleanup failed, but deployment was successful." >&2
}
echo "Deployment successful. Binaries are located in: ${_dest_dir}"
}