From 31d7ef27a8d94cf0be832b37e9bb6be9c1c83ca5 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 24 Jul 2023 12:42:39 +0200 Subject: [PATCH] Add bin/devhamctl Add bin/docker-traverse.sh Add bin/exec-sanity.sh Add bin/lunardev.sh Add bin/record.sh Add bin/restart-builds-drone.sh Add bin/run-dosier.sh Add bin/sanity.sh Add bin/scan-for-bad-indexes.sh Add bin/ssh-agent.sh Add bin/terraform.sh Add bin/tmux.sh Add bin/update-vault.sh Add bin/zimfwupdate.sh --- bin/executable_devhamctl | 24 ++++++++++ bin/executable_docker-traverse.sh | 66 ++++++++++++++++++++++++++ bin/executable_exec-sanity.sh | 7 +++ bin/executable_lunardev.sh | 33 +++++++++++++ bin/executable_record.sh | 14 ++++++ bin/executable_restart-builds-drone.sh | 19 ++++++++ bin/executable_run-dosier.sh | 16 +++++++ bin/executable_sanity.sh | 13 +++++ bin/executable_scan-for-bad-indexes.sh | 24 ++++++++++ bin/executable_ssh-agent.sh | 9 ++++ bin/executable_terraform.sh | 10 ++++ bin/executable_tmux.sh | 9 ++++ bin/executable_update-vault.sh | 22 +++++++++ bin/executable_zimfwupdate.sh | 21 ++++++++ 14 files changed, 287 insertions(+) create mode 100644 bin/executable_devhamctl create mode 100644 bin/executable_docker-traverse.sh create mode 100644 bin/executable_exec-sanity.sh create mode 100644 bin/executable_lunardev.sh create mode 100644 bin/executable_record.sh create mode 100644 bin/executable_restart-builds-drone.sh create mode 100644 bin/executable_run-dosier.sh create mode 100644 bin/executable_sanity.sh create mode 100644 bin/executable_scan-for-bad-indexes.sh create mode 100644 bin/executable_ssh-agent.sh create mode 100644 bin/executable_terraform.sh create mode 100644 bin/executable_tmux.sh create mode 100644 bin/executable_update-vault.sh create mode 100644 bin/executable_zimfwupdate.sh diff --git a/bin/executable_devhamctl b/bin/executable_devhamctl new file mode 100644 index 0000000..0b6ba0c --- /dev/null +++ b/bin/executable_devhamctl @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +function cleanupTempDir() { + temp=$1 + echo "cleaning up $temp" + + rm -r $temp + + echo "cleaned up tempdir" +} + +tempdir=$(mktemp -d -t "devhamctl") +trap "cleanupTempDir $tempdir" EXIT + +pushd $tempdir +echo "fetching release manager [hamctl]" +wget -q https://github.com/lunarway/release-manager/releases/download/$1/hamctl-darwin-amd64 -O binhamctl +shift +echo "calling release manager [hamctl] with args [$@]" +chmod +x binhamctl +HAMCTL_URL="http://some-url" ./binhamctl "$@" +popd diff --git a/bin/executable_docker-traverse.sh b/bin/executable_docker-traverse.sh new file mode 100644 index 0000000..b3def2b --- /dev/null +++ b/bin/executable_docker-traverse.sh @@ -0,0 +1,66 @@ +#!/bin/bash +set -euo pipefail + +# Parse command line arguments +while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + --image) + IMAGE_NAME="$2" + shift + shift + ;; + *) + echo "Error: Unknown option: $key" + echo "Usage: $0 --image IMAGE_NAME" + exit 1 + ;; + esac +done + +# Define the path to the temporary directory where the files will be extracted +DESTINATION="/tmp/docker_images/${IMAGE_NAME}" +MANIFEST="${DESTINATION}/manifest.json" + +# Define a function to download and extract the Docker image layers +function extract_docker_image { + # Pull image to make sure we have it before we save it. + docker pull "$IMAGE_NAME" + + # Save the Docker image as a tar file + echo "Saving Docker image as a tar file..." >&2 + docker save "$1" -o "${DESTINATION}/${IMAGE_NAME}.tar" + + # Extract the Docker image layers to the destination directory + echo "Extracting Docker image layers..." >&2 + mkdir -p "${DESTINATION}/layers" + tar -xf "${DESTINATION}/${IMAGE_NAME}.tar" -C "${DESTINATION}/" + + # Rename the layer directories to their respective layer IDs + LAYERS=$(jq -r '.[0].Layers[]' "${MANIFEST}") + + # Extract each layer + for LAYER in ${LAYERS}; do + BLOB="${LAYER}" + # Extract the layer tar file to the destination directory + echo "Extracting layer ${LAYER}..." >&2 + mkdir -p "${DESTINATION}/$(dirname ${BLOB})" + tar -xf "${DESTINATION}/${BLOB}" -C "${DESTINATION}/layers" + echo "Layer ${LAYER} extracted" >&2 + done +} + +# Ensure that the user has provided the Docker image name using the --image flag +if [ -z "$IMAGE_NAME" ]; then + echo "Error: Docker image name not provided." >&2 + echo "Usage: $0 --image IMAGE_NAME" >&2 + exit 1 +fi + +# Create the destination directory if it doesn't already exist +rm -rf "${DESTINATION}" +mkdir -p "${DESTINATION}" + +# Call the function to download and extract the Docker image layers +extract_docker_image "$IMAGE_NAME" + diff --git a/bin/executable_exec-sanity.sh b/bin/executable_exec-sanity.sh new file mode 100644 index 0000000..e299a36 --- /dev/null +++ b/bin/executable_exec-sanity.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e + +podid=$(kubectl get pods | rg sanity | rg -v mesh | awk '{print $1}') + +kubectl exec -it "$podid" -- sh diff --git a/bin/executable_lunardev.sh b/bin/executable_lunardev.sh new file mode 100644 index 0000000..948b446 --- /dev/null +++ b/bin/executable_lunardev.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env zsh + +function lunardev () +{ + nolunardev + + tmux new-window -n lunardev + + tmux send-keys -t lunardev "shuttle run local_up" C-m + + # allow for user input + tmux split-window -h + + shuttle run generate_dotenv + + + tmux send-keys -t lunardev 'export $(cat local.env | xargs)' C-m + tmux send-keys -t lunardev "air -c ~/.config/air/.air.toml" C-m + tmux split-window -v + + export $(cat local.env | xargs) + tmux send-keys -t lunardev "PGPASSWORD=$DBPASSWORD psql -h $DBHOST -U $DBUSER -d $DBDATABASE" C-m + + # set user input to first + tmux select-pane -t 0 + + + tmux attach-session -t lunardev +} + +function nolunardev() { + tmux kill-window -t lunardev || true +} diff --git a/bin/executable_record.sh b/bin/executable_record.sh new file mode 100644 index 0000000..84374f4 --- /dev/null +++ b/bin/executable_record.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Get the current timestamp +timestamp=$(date +%Y%m%d%H%M%S) + +# Construct the filename +filename="recording_$timestamp.cast" + +mkdir -p ~/Documents/arecordings + +# Start the recording +asciinema rec ~/Documents/arecordings/${filename} + +echo "Recording saved to ~/Documents/arecordings/${filename}" diff --git a/bin/executable_restart-builds-drone.sh b/bin/executable_restart-builds-drone.sh new file mode 100644 index 0000000..c9e92cd --- /dev/null +++ b/bin/executable_restart-builds-drone.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +drone_url=https://ci.i.kjuulh.io/api/ +auth="Authorization: Bearer z1gpPUNI0dAgxtCqvk1aFhyyRn6S1n05" + +curl -s "${drone_url}user/repos" -H "$auth" | jq -r .[].slug | +while read -r repo; do + echo "processing $repo" + curl -s "${drone_url}repos/$repo/builds" -H "$auth" | jq -c '.[1:5] | .[] | select(.status | contains("failure")) | .number' | jq -r | + while read -r build_id; do + echo "building: $repo - $build_id" + curl -s -X POST "${drone_url}repos/$repo/builds/$build_id" -H "$auth" + sleep 1 + done +done + + diff --git a/bin/executable_run-dosier.sh b/bin/executable_run-dosier.sh new file mode 100644 index 0000000..bb29144 --- /dev/null +++ b/bin/executable_run-dosier.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env zsh + +LOG="$HOME/morning.log" + +exec > >(tee -i ${LOG}) +exec 2>&1 + +echo "# Starting morning run: $(date)" + +pushd ~/git/git.front.kjuulh.io/kjuulh/morning/ || return 1 + +cargo run oneshot + +popd || return 1 + +echo "Finished monring run: $(date)" diff --git a/bin/executable_sanity.sh b/bin/executable_sanity.sh new file mode 100644 index 0000000..eea3abb --- /dev/null +++ b/bin/executable_sanity.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh + +function sanity() { + env=${1:-dev} + + k8s "$env" + + pod=$(k get pods -n "$env" | rg sanity | rg -v mesh | awk '{print $1}') + + echo "$pod" + + k exec "$pod" -it -n "$env" -- sh +} diff --git a/bin/executable_scan-for-bad-indexes.sh b/bin/executable_scan-for-bad-indexes.sh new file mode 100644 index 0000000..fb210dd --- /dev/null +++ b/bin/executable_scan-for-bad-indexes.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +psql -AtF',' -c 'SELECT datname FROM pg_database WHERE datistemplate = false;' | rg -v rdsadmin | + while read -r line + do + echo "running for $line" + + psql -d "$line" -AtF',' -c ' +SELECT pg_class.relname +FROM pg_class, pg_index +WHERE pg_index.indisvalid = false +AND pg_index.indexrelid = pg_class.oid;' + + echo + done + +#psql < >(tee -i ${LOG}) +exec 2>&1 + +echo "# Starting update vault: $(date)" + +pushd ~/Documents/vaults/kjuulh/ || return 1 + +git add . + +git commit -m "auto commit" + +git pull origin main --rebase + +git push + +popd || return 1 + +echo "Finished update vault: $(date)" diff --git a/bin/executable_zimfwupdate.sh b/bin/executable_zimfwupdate.sh new file mode 100644 index 0000000..839e6de --- /dev/null +++ b/bin/executable_zimfwupdate.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env zsh + +function refresh_zimfw() { + echo "refreshing zimfw / zplug" + cd ~/git/github.com/lunarway/lw-zsh/ + echo "pulling changes" + git pull origin master --rebase + git push -f + cd + cd .zim/modules + echo "refreshing zim" + rm -rf lw-zsh + echo "installing new updates" + zimfw install + cd + echo "done refreshing zimfw / zplug" + echo "refreshing zsh" + zsh +} + +