Skip to content

Instantly share code, notes, and snippets.

View ruzickap's full-sized avatar

Petr Ruzicka ruzickap

View GitHub Profile
@ruzickap
ruzickap / grafana_cloud_raspberry_pi.sh
Last active January 8, 2022 15:52
Few commands to configure Grafana Agent to allow sending data to Grafana Cloud
# Install blackbox-exporter
apt update
apt install -y prometheus-blackbox-exporter
# Chnage the garfana agent config file /etc/grafana-agent.yaml
cat > /etc/grafana-agent.yaml << EOF
integrations:
agent:
enabled: true
@ruzickap
ruzickap / remove_zone_route53.sh
Created November 15, 2020 15:19
Remove DNS Zone form AWS Route 53 (including all zone records)
ZONE_NAME="test.example.com"
ZONE_ID=$(aws route53 list-hosted-zones --query "HostedZones[?Name==\`${ZONE_NAME}.\`].Id" --output text)
aws route53 list-resource-record-sets --hosted-zone-id "${ZONE_ID}" | jq -c '.ResourceRecordSets[] | select (.Type != "SOA" and .Type != "NS")' |
while read -r RESOURCERECORDSET; do
aws route53 change-resource-record-sets \
--hosted-zone-id "${CLUSTER_FQDN_ZONE_ID}" \
--change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet": '"${RESOURCERECORDSET}"' }]}' \
--output text --query 'ChangeInfo.Id'
done
@ruzickap
ruzickap / k8s_get_pod_count_per_nodes.sh
Created August 28, 2020 13:13
Show number of containers running on all the worker nodes in Kubernetes
GET_NODES=$(kubectl get node -o=custom-columns='NAME:metadata.name' | grep -v ^NAME)
for NODE in ${GET_NODES}; do
echo -en "${NODE}:\t"
kubectl get po --field-selector=status.phase=Running --all-namespaces -o json | jq -r ".items[] | select(.spec.nodeName==\"${NODE}\") | .metadata.name" | wc -l
done
@ruzickap
ruzickap / headset.sh
Created August 20, 2020 09:20
Move all sound output to Headset
#!/bin/bash -eu
HEADSET=$(pacmd list-sinks | sed -n 's/.*name: <\(.*output.*Headset.*\)>/\1/p')
HEADSET_MIC=$(pacmd list-sources | sed -n 's/.*name: <\(.*input.*Headset.*\)>/\1/p')
pacmd "set-default-sink ${HEADSET}"
pacmd "set-default-source ${HEADSET_MIC}"
pactl set-sink-mute "${HEADSET}" 0
pactl set-sink-volume "${HEADSET}" 80%
@ruzickap
ruzickap / install_raspap.sh
Last active October 15, 2022 06:14
Script for quick installation of RaspAP
#!/bin/bash -eux
DEVICE="sdc"
lsblk --output NAME,MODEL,MODEL | grep ${DEVICE}
read -r -p "Press enter to remove everything from ${DEVICE}"
curl -L https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-09-26/2022-09-22-raspios-bullseye-arm64-lite.img.xz | xzcat | sudo dd of=/dev/${DEVICE} bs=4M
sudo partprobe /dev/${DEVICE}
@ruzickap
ruzickap / aws_route53_subdomain.sh
Created May 6, 2020 06:30
AWS Route53 subdomain delegation
# You have defined the "cna.example.cloud" zone in Route53
# You want to create subdomain "${USER}-k8s.cna.example.cloud" and configure proper delegation form parrent zone
echo "* Create DNS zone ${USER}-k8s.cna.example.cloud"
aws route53 create-hosted-zone --output json \
--name ${USER}-k8s.cna.example.cloud \
--caller-reference "$(date)" \
--hosted-zone-config="{\"Comment\": \"Created by ${USER}@example.com\", \"PrivateZone\": false}" | jq
@ruzickap
ruzickap / Deploy public ssh key from GitHub user
Last active December 18, 2020 09:25
deploy-public-ssh-key-github.sh
GITHUB_USERNAME="${GITHUB_USERNAME:-ruzickap}"
DESTINATION_DIRECTORY="${DESTINATION_DIRECTORY:-/root/.ssh}"
[[ ! -d "${DESTINATION_DIRECTORY}" ]] && mkdir -v --mode=0700 "${DESTINATION_DIRECTORY}"
wget "https://github.com/${GITHUB_USERNAME}.keys" -O "${DESTINATION_DIRECTORY}/authorized_keys"
chmod 0600 "${DESTINATION_DIRECTORY}/authorized_keys"
@ruzickap
ruzickap / k8s-debug.sh
Created March 21, 2020 15:54
Kubernetes debug notes
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl logs -n monitoring prometheus-prometheus-operator-prometheus-0 --all-containers
@ruzickap
ruzickap / check_urls.sh
Last active February 2, 2020 09:16
Automatically check links on web pages
git clone git@github.com:ruzickap/check_urls.git
cd check_urls
mkdir -p .github/workflows
cat > .github/workflows/periodic-broken-link-checks.yml << \EOF
name: periodic-broken-link-checks
on:
schedule:
- cron: '0 0 * * *'
@ruzickap
ruzickap / git-repository-gpg-crypt
Created November 1, 2019 15:54
Make git repository encrypted with generated GPG key which can be used by CI/CD to access the git repo when using GitHub Actions
# Make sure you are using gpg2
git config --global gpg.program gpg2
# Clone empty repository
git clone git@github.com:ruzickap/terraform-gitops.git
# Configure a repository to use git-crypt
cd terraform-gitops
git-crypt init