Home · RSS · E-Mail · GitHub · GitLab · Mastodon · Twitter · LinkedIn

$tool bits

first published:

Same procedure as last time? Same procedure, just for stuff which won’t require an own post (yet).

» curl

Save with remote filename (short -O):

1
curl http://example.com --remote-name

Save with given filename (short -o):

1
curl http://example.com --output filename

http://www.compciv.org/recipes/cli/downloading-with-curl/

To follow redirects add --location (short -L). Silent add --silent (short -s).

» dd

» Copy an ISO to an USB-stick

1
sudo dd if=ubuntu-20.04.1-live-server-amd64.iso of=/dev/xyz bs=16M status=progress

https://www.cyberciti.biz/faq/creating-a-bootable-ubuntu-usb-stick-on-a-debian-linux/

» Takeover Installation

Overwrite your existing system. Sseems to be a bit buggy, maybe important parts of the image itself get overwritten. Preferably, store your image in a tmpfs mount (e.g. /run/shm).

1
xz -d -c /rum/shm/talos.raw.xz | dd of=/dev/sda bs=16M status=progress && sync

» envsubst

Replace environment variables (e.g. ${MY_VAR}) in a file:

1
envsubst < "source.txt" > "destination.txt"

If the input and output file should be the same:

1
envsubst < "source.txt" | sponge "source.txt"

or without sponge but more verbose:

1
envsubst < "source.txt" > "destination.txt" && mv "destination.txt" "source.txt" && rm "destination.txt"

envsubst is part of the gettext package and sponge of the moreutils package in Alpine Linux.

Reference: derobert and Derek Mahar

» find

List all files with a specific name, e.g. .DS_Store:

1
find . -type f -name '.DS_Store'

Add -delete to delete all of them.

» git

» Delete remote tag

1
git push --delete origin <TAG>

» Delete merged branches

1
2
git fetch --prune
git branch -vv | grep ': gone]' | grep -v '\*' | awk '{ print $1; }' | xargs -r git branch -d

Reference: https://digitaldrummerj.me/git-remove-local-merged-branches/

» Globally set default branch to main

1
git config --global init.defaultBranch main

» Rebase current branch to drop a given commit

Attention to the ~:

1
git rebase -i <commit-hash-to-remove>~

Then “normally” drop the commits you want to remove.

Reference: David Deutsch and KiriSakow

As an alternative and you know that the commit you want to remove is within the last N (e.g. 10) commits, use:

1
git rebase -i HEAD~10

» Compare local branch with remote branch

Gets the current branch name from a subshell, so you can reuse the command from your shell history.

1
git diff origin/$(git rev-parse --abbrev-ref HEAD)

» Reset local branch to remote branch

Similarly to the comparison, we can reset our local branch to the remote branch:

1
git reset origin/$(git rev-parse --abbrev-ref HEAD)

» Github Workflows

» Access a private repository

When you need access to another private repository inside a Github Workflow (e.g. private Go package repo), add this to your Job’s steps:

1
2
- name: "Setup git to fetch private repos"
  run: git config --global url.https://${{ secrets.ACCESS_TOKEN }}@github.com/.insteadOf https://github.com/

Where ACESS_TOKEN is a token which has access to the private repo.

References:

» grep

List all files with occurences of SearchPattern in /path/to/folder and subfolders:

1
grep --color=always --recursive --binary-file=without-match --files-with-matches --ignore-case --fixed-strings "SearchPattern" /path/to/folder

If you want to use a regexp, remove --fixed-strings.

Reference: How to use “grep” command to find text including subdirectories

» helm

» Cascade check possible null values

When you want to check a value (here addr) where other sections might be null (e.g. networking or ipv4) use round brackets so the if condition will be false instead of just crashing.

1
2
3
{{- if not ((.Values.networking).ipv4).addr }}
    {{ fail "setting 'networking.ipv4.addr' is required"}}
{{- end }}

» Resource Checksum Annotation

Add the checksum of another resource (e.g. configmap or secret) to the deployment annoatations. This way, the deployment will be restarted when the checksum (configmap/secret) changes. Otherwise, it could be easily forgotten to restart the deployment and you are wondering why it doesn’t behave as you would expect.

1
2
annotations:
    checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}

Reference

» Homebrew

» Cleanup and upgrade everything

1
brew autoremove; brew upgrade; brew upgrade --cask --greedy

» Bundle

Dump:

1
brew bundle dump --global --all

Install:

1
brew bundle --global --all

Cleanup:

1
brew bundle cleanup --global --all

» Remove all installed tools

1
2
brew remove --force $(brew list --formula)
brew remove --cask --force $(brew list)

https://apple.stackexchange.com/a/339096/487634

» KeePassXC

Export password as environment variable:

1
KEY=$(keepassxc-cli show <database.kdbx> -k <keyfile.keyx> "<entry name>" -a Password)

» Minio Client

» Add Oracle Object Storage

Adjust <NAMESPACE> and <REGION> and add the following entry to your Minio Client Config (e.g. ~/.mc/config.json):

1
2
3
4
5
6
7
"oracle": {
    "url": "https://<NAMESPACE>.compat.objectstorage.<REGION>.oci.customer-oci.com",
    "accessKey": "CHANGE_ME",
    "secretKey": "CHANGE_ME",
    "api": "s3v4",
    "path": "auto"
}

https://docs.oracle.com/en-us/iaas/Content/Object/Concepts/dedicatedendpoints.htm

» NixOS

Use sudo as channels are set per user!

Show the current release channel:

1
sudo nix-channel --list

Switch to another channel, e.g. 23.05:

1
sudo nix-channel --add https://channels.nixos.org/nixos-23.05 nixos

Update the system (equivalent to apt update && apt upgrade on Debian):

1
sudo nixos-rebuild switch --upgrade

Delete old generations:

1
sudo nix-collect-garbage --delete-old --delete-older-than 14d

https://nixos.org/manual/nixos/stable/#sec-upgrading

» Prometheus

» 0 instead of no data

Add OR on() vector(0) to your query.

Credits: Nicolai Antiferov

» tar

extract:

1
tar --extract --gzip --file file.tar.gz [file1 file2 dir1 dir2]

Add --verbose when you want to see which files got extracted.

Not so difficult when you use the long flag names. The flags all together in short: -xzvf.

https://www.cyberciti.biz/faq/linux-unix-bsd-extract-targz-file/

» talosctl

» Reboot

1
talosctl reboot --wait

» Upgrade Talos

Upgrade to e.g. v1.3.0. Use --preserve when you are running a single node cluster.

1
talosctl upgrade --image ghcr.io/siderolabs/installer:v1.3.0 --wait --debug --preserve

» Upgrade Kubernetes

When you upgrade the Talos version, it will not automatically upgrade the Kubernetes version. You have to do this in a separate step. For example, to upgrade Kubernetes to version 1.26.0:

1
talosctl upgrade-k8s --to 1.26.0

» timeout

Kill a command after a specified duration:

1
2
3
4
5
➜  ~ timeout 3s ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=118 time=19.914 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=51.778 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=21.253 ms

Stop with SIGINT:

1
2
3
4
5
6
7
8
9
➜  ~ timeout --signal SIGINT 3s ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: icmp_seq=0 ttl=118 time=20.661 ms
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=19.799 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=20.925 ms

--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 19.799/20.462/20.925/0.481 ms

Add --preserve-status to use the status of the invoked tool even when timeout kills it.

» ts

Add a timestamp to every output line:

1
2
3
4
5
➜  ~ ping 8.8.8.8 | ts
Jun 13 18:09:11 PING 8.8.8.8 (8.8.8.8): 56 data bytes
Jun 13 18:09:11 64 bytes from 8.8.8.8: icmp_seq=0 ttl=118 time=19.638 ms
Jun 13 18:09:12 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=20.715 ms
Jun 13 18:09:13 64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=19.597 ms

ts is part of the moreutils package.




Home · RSS · E-Mail · GitHub · GitLab · Mastodon · Twitter · LinkedIn