aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-11-27 20:46:19 -0500
committerEugene Triguba <hello@eugenetriguba.com>2025-11-27 20:46:19 -0500
commit09e3e8fde2f251f54803f129b9ffb68930e455ae (patch)
treeff6f0b53ccfff43313469f10b2d4b72c771723f0 /bin
parentIgnore other gpg files (diff)
downloaddotfiles-09e3e8fde2f251f54803f129b9ffb68930e455ae.zip
update openbsd install
Diffstat (limited to 'bin')
-rwxr-xr-xbin/.local/bin/get-password36
-rwxr-xr-xbin/.local/bin/gh-clone-all102
-rwxr-xr-xbin/.local/bin/migrate-to-sourcehut76
-rwxr-xr-xbin/.local/bin/optimize-image83
-rwxr-xr-xbin/.local/bin/sct-daemon18
5 files changed, 315 insertions, 0 deletions
diff --git a/bin/.local/bin/get-password b/bin/.local/bin/get-password
new file mode 100755
index 0000000..3b83bb7
--- /dev/null
+++ b/bin/.local/bin/get-password
@@ -0,0 +1,36 @@
+#!/bin/sh
+set -e
+
+VAULT="Private"
+CREDENTIAL=""
+
+main() {
+ parse_args "$@"
+ op read "op://$VAULT/$CREDENTIAL/password"
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --vault)
+ VAULT="$2"
+ shift 2
+ ;;
+ --credential)
+ CREDENTIAL="$2"
+ shift 2
+ ;;
+ *)
+ echo "Usage: $0 [--vault <name>] --credential <name>"
+ exit 1
+ ;;
+ esac
+ done
+
+ if [ -z "$CREDENTIAL" ]; then
+ echo "Invalid or empty CREDENTIAL" >&2
+ exit 1
+ fi
+}
+
+main "$@"
diff --git a/bin/.local/bin/gh-clone-all b/bin/.local/bin/gh-clone-all
new file mode 100755
index 0000000..77de93a
--- /dev/null
+++ b/bin/.local/bin/gh-clone-all
@@ -0,0 +1,102 @@
+#!/usr/bin/env bash
+# Clone all repositories from a GitHub user or organization using the gh CLI.
+#
+# Usage:
+# gh-clone-all [--exclude-archived] [--exclude-forks] [--pull] <github-entity> [target-directory]
+#
+# Args:
+# --exclude-archived: If set, skip archived repos (default: include all)
+# --exclude-forks: If set, skip forked repos
+# --pull: If set, pull latest changes in existing repos
+# --limit: The maximum number of repos to clone (default: 10000)
+# <github-entity>: The GitHub username or org (e.g. eugenetriguba)
+# [target-directory]: Optional directory to clone repos into
+set -euo pipefail
+
+EXCLUDE_ARCHIVED=0
+EXCLUDE_FORKS=0
+PULL_EXISTING=0
+ENTITY=""
+TARGET_DIR="."
+LIMIT=10000
+
+main() {
+ parse_args "$@"
+ clone_all_repos
+}
+
+parse_args() {
+ while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --exclude-archived)
+ EXCLUDE_ARCHIVED=1
+ shift
+ ;;
+ --exclude-forks)
+ EXCLUDE_FORKS=1
+ shift
+ ;;
+ --pull)
+ PULL_EXISTING=1
+ shift
+ ;;
+ --limit)
+ LIMIT="$2"
+ shift 2
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ if [[ -z "$ENTITY" ]]; then
+ ENTITY="$1"
+ elif [[ "$TARGET_DIR" == "." ]]; then
+ TARGET_DIR="$1"
+ else
+ usage
+ fi
+ shift
+ ;;
+ esac
+ done
+ if [[ -z "$ENTITY" ]]; then
+ usage
+ fi
+ mkdir -p "$TARGET_DIR"
+}
+
+usage() {
+ echo "Usage: $0 [--exclude-archived] [--exclude-forks] [--pull] [--limit] <github-entity> [target-directory]"
+ exit 1
+}
+
+clone_all_repos() {
+ gh repo list "$ENTITY" --limit "$LIMIT" --json name,sshUrl,archivedAt,isFork |
+ jq -c '.[]' | while read -r repo; do
+ NAME=$(echo "$repo" | jq -r '.name')
+ CLONE_URL=$(echo "$repo" | jq -r '.sshUrl')
+ ARCHIVED_AT=$(echo "$repo" | jq -r '.archivedAt')
+ IS_FORK=$(echo "$repo" | jq -r '.isFork')
+ DEST="$TARGET_DIR/$NAME"
+ if [[ "$EXCLUDE_ARCHIVED" -eq 1 && "$ARCHIVED_AT" != "null" ]]; then
+ continue
+ fi
+ if [[ "$EXCLUDE_FORKS" -eq 1 && "$IS_FORK" == "true" ]]; then
+ continue
+ fi
+ if [[ -d "$DEST" ]]; then
+ echo "Repo $NAME already exists."
+ if [[ "$PULL_EXISTING" -eq 1 ]]; then
+ echo "Pulling latest changes in $DEST"
+ git -C "$DEST" pull --ff-only || echo "Warning: git pull failed in $DEST, continuing..."
+ else
+ echo "Skipping $NAME (already exists)"
+ fi
+ continue
+ fi
+ echo "Cloning $CLONE_URL into $DEST"
+ git clone "$CLONE_URL" "$DEST"
+ done
+}
+
+main "$@"
diff --git a/bin/.local/bin/migrate-to-sourcehut b/bin/.local/bin/migrate-to-sourcehut
new file mode 100755
index 0000000..d7e471a
--- /dev/null
+++ b/bin/.local/bin/migrate-to-sourcehut
@@ -0,0 +1,76 @@
+#!/bin/bash
+set -euo pipefail
+set -x
+
+REPOS_DIR="$HOME/src/"
+SOURCEHUT_USER="eugenetriguba"
+
+main() {
+ parse_args "$@"
+
+ cd "$REPOS_DIR"
+ for repo in */; do
+ if [ -d "$repo/.git" ]; then
+ echo "Processing $repo..."
+ cd "$repo"
+
+ if ! git remote | grep -q "^origin$"; then
+ echo "No origin remote found for $repo, skipping..."
+ cd ..
+ continue
+ fi
+
+ if ! git remote get-url origin | grep -q "git.sr.ht"; then
+ echo "Migrating $repo to SourceHut..."
+
+ local repo_name
+ repo_name=$(git remote get-url origin | cut -d '/' -f 2 | cut -d '.' -f 1)
+ git remote remove origin
+ git remote add origin "git@git.sr.ht:~${SOURCEHUT_USER}/${repo_name}"
+
+ local current_branch
+ current_branch=$(git branch --show-current)
+ if [ "$current_branch" = "master" ]; then
+ echo "Renaming master branch to main..."
+ git branch -m master main
+ fi
+
+ git push --push-option visiblity="private" -u origin main
+ git push origin main --tags
+ fi
+
+ cd ..
+ fi
+ done
+}
+
+parse_args() {
+ while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --repos-dir)
+ REPOS_DIR="$2"
+ shift 2
+ ;;
+ --sourcehut-user)
+ SOURCEHUT_USER="$2"
+ shift 2
+ ;;
+ *)
+ echo "Usage: $0 [--repos-dir <path>] [--sourcehut-user <username>]"
+ exit 1
+ ;;
+ esac
+
+ if [[ -z "$REPOS_DIR" || ! -d "$REPOS_DIR" ]]; then
+ echo "Invalid or empty REPOS_DIR: $REPOS_DIR"
+ exit 1
+ fi
+
+ if [[ -z "$SOURCEHUT_USER" ]]; then
+ echo "SOURCEHUT_USER must be specified."
+ exit 1
+ fi
+ done
+}
+
+main "$@"
diff --git a/bin/.local/bin/optimize-image b/bin/.local/bin/optimize-image
new file mode 100755
index 0000000..075684b
--- /dev/null
+++ b/bin/.local/bin/optimize-image
@@ -0,0 +1,83 @@
+#!/bin/sh
+set -e
+
+quality=85
+source_img_path=""
+result_img_path=""
+
+main() {
+ parse_args "$@"
+
+ original_size=$(get_file_size "$source_img_path")
+ echo "Optimizing: $source_img_path -> $result_img_path (quality: $quality%)"
+ magick "$source_img_path" -strip -quality "${quality}%" "$result_img_path"
+ new_size=$(get_file_size "$result_img_path")
+ echo "File size: $original_size -> $new_size"
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case $1 in
+ --quality)
+ if [ -n "$2" ] && [ "$2" -ge 1 ] && [ "$2" -le 100 ] 2>/dev/null; then
+ quality="$2"
+ shift 2
+ else
+ echo "Error: --quality requires a number between 1 and 100"
+ exit 1
+ fi
+ ;;
+ -h | --help)
+ print_usage
+ exit 0
+ ;;
+ -*)
+ echo "Error: Unknown option $1"
+ print_usage
+ exit 1
+ ;;
+ *)
+ if [ -z "$source_img_path" ]; then
+ source_img_path="$1"
+ else
+ echo "Error: Too many arguments"
+ print_usage
+ exit 1
+ fi
+ shift
+ ;;
+ esac
+ done
+
+ if [ -z "$source_img_path" ]; then
+ echo "Error: source image path is required"
+ print_usage
+ exit 1
+ fi
+
+ if [ ! -f "$source_img_path" ]; then
+ echo "Error: Source file '$source_img_path' does not exist"
+ exit 1
+ fi
+
+ result_img_path="${source_img_path%.*}.webp"
+}
+
+print_usage() {
+ echo "Usage: $0 [OPTIONS] <source-img-path>"
+ echo ""
+ echo "Options:"
+ echo " --quality <value> Set quality (1-100, default: 85)"
+ echo " -h, --help Show this help message"
+ echo ""
+ echo "Examples:"
+ echo " $0 input.jpg"
+ echo " $0 --quality 90 input.jpg"
+ echo " $0 --quality 80 input.png"
+}
+
+get_file_size() {
+ du -h "$1" | awk '{ print $1 }'
+}
+
+main "$@"
diff --git a/bin/.local/bin/sct-daemon b/bin/.local/bin/sct-daemon
new file mode 100755
index 0000000..b16a67e
--- /dev/null
+++ b/bin/.local/bin/sct-daemon
@@ -0,0 +1,18 @@
+#!/bin/sh
+set -e
+
+while true; do
+ hour=$(date +%H)
+
+ if [ "$hour" -ge 6 ] && [ "$hour" -lt 18 ]; then
+ sct 6500 # day
+ elif [ "$hour" -ge 18 ] && [ "$hour" -lt 20 ]; then
+ sct 4500 # evening
+ elif [ "$hour" -ge 20 ] && [ "$hour" -lt 22 ]; then
+ sct 3500 # night
+ else
+ sct 3000 # late night/early morning
+ fi
+
+ sleep 600 # check every 10 minutes
+done