Posts

renew ssl certs automatically and clear out expired

 Letsencrypt used to auto fix your expired certs. This no longer happens. Here's a script to do it. Flags: --delete : remove expired certs --renew: renew soon-to-expire certs (3< days) #!/bin/bash # check-certs.sh base="/etc/letsencrypt/archive" delete_mode=0 renew_mode=0 if [ "$1" == "--delete" ]; then     delete_mode=1 elif [ "$1" == "--renew" ]; then     renew_mode=1 fi # First: find all current certs in archive declare -A cert_status find "$base" -type f -name "cert*.pem" | while read cert; do     domain=$(echo "$cert" | sed -E "s|$base/([^/]+)/cert[0-9]+\.pem|\1|")     expiry=$(openssl x509 -enddate -noout -in "$cert" | cut -d= -f2)     exp_epoch=$(date -d "$expiry" +%s)     now_epoch=$(date +%s)     days_left=$(( (exp_epoch - now_epoch) / 86400 ))     echo "$domain: $expiry  ($days_left days left)"     if [ $delete_mode -eq 1 ] && [ $days_left -lt...

find deleted files

Sometimes you want to compare an archive backup drive and a target folder and see what items got  deleted in that folder. Useful if you have a flaky backup system like dropbox. #!/usr/bin/env bash # find_deleted.sh — list non-image files that exist in SOURCE but not in TARGET # usage: ./find_deleted.sh [--rsync-check] SOURCE_DIR TARGET_DIR set -euo pipefail usage() {   echo "Usage: $0 [--rsync-check] SOURCE_DIR TARGET_DIR" >&2   exit 1 } RSYNC_CHECK=0 if [ "${1:-}" = "--rsync-check" ]; then   RSYNC_CHECK=1   shift fi [ $# -eq 2 ] || usage SRC="${1%/}" DST="${2%/}" [ -d "$SRC" ] || { echo "Source not found: $SRC" >&2; exit 2; } [ -d "$DST" ] || { echo "Target not found: $DST" >&2; exit 3; } # Returns 0 if the path looks like an image, 1 otherwise. is_image_path() {   # lower-case path (Bash-only ${var,,})   local p="${1,,}"   case "$p" in     *.jpg|*.jpeg|*....

folder deduper

 If like me you have thousands of duplicate photos, you need this. it only deduplicates on md5 (identical) files, not visually similar files. It does not run inside github as that will break any coding you are doing. #!/bin/bash # dupemd5.sh — report duplicate files by MD5; dry-run move + CSV log # Safety check: do not allow running inside GitHub directories if [[ "$(pwd)" =~ [Gg]ithub ]]; then     echo "Error: refusing to run inside a GitHub directory ($(pwd))" >&2     exit 1 fi APPLY=0 if [[ "${1:-}" == "--apply" ]]; then     APPLY=1     shift fi dir="${1:-.}" declare -A seen count=0 duplicates_dir="./duplicates" csv="$duplicates_dir/duplicates_found.csv" mkdir -p "$duplicates_dir" touch "$csv" if [[ ! -s "$csv" ]]; then     echo '"item";"original";"duplicate";"target"' > "$csv" fi print_summary() {     echo "Tota...

DropboxMount turns your Dropbox into a live, on-demand drive instead of a sync folder.

DropboxMount turns your Dropbox into a live, on-demand drive instead of a sync folder. Instead of duplicating gigabytes of files onto your computer, it creates a special mount point that behaves like a network filesystem. Your Dropbox directory appears instantly, with all files and folders visible, but the contents are only downloaded when you open them. Saving changes writes them straight back to the cloud. This means you can browse your entire Dropbox without using up local disk space, and the experience feels closer to an NFS or WebDAV share than the heavyweight Dropbox desktop client. How to Set Up DropboxMount on Linux  This method uses FUSE (Filesystem in Userspace) to mount Dropbox as if it were a local drive. The tool we use is rclone, which supports Dropbox natively.  1. Install rclone sudo apt update sudo apt install rclone 2. Configure Dropbox in rclone rclone config - Choose **n** for a new remote. - Name it something like `dropboxmount`. - Select `Dropbox` from t...

make ubuntu dock (dashboard) behave like macos dock

 #!/usr/bin/env bash set -e # Install real Dash to Dock sudo apt update sudo apt install -y gnome-shell-extension-dash-to-dock # Disable Ubuntu Dock, enable Dash to Dock gnome-extensions disable ubuntu-dock@ubuntu.com || true gnome-extensions enable dash-to-dock@micxgx.gmail.com # Settings: tooltips on, mac-like layout, auto-resize icons gsettings set org.gnome.shell.extensions.dash-to-dock hide-tooltip false gsettings set org.gnome.shell.extensions.dash-to-dock dock-position 'BOTTOM' gsettings set org.gnome.shell.extensions.dash-to-dock autohide false gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 64 gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize' gsettings set org.gnome.shell.extensions.dash-to-dock show-trash true gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts true gsettings set org.gnome.shell.extensions.dash-to-dock icon-size-fixed false echo "Done. If changes don’t appear, log out/in....

recover a usb flash drive

  Recovering Data from a Corrupted Flash Disk on Linux 🔧 Step 1: Install the Recovery Tools Install GNU ddrescue and testdisk (which includes photorec): sudo apt-get install gddrescue testdisk 💽 Step 2: Make a Full Disk Image with ddrescue Do NOT work on the damaged flash drive directly. Instead, make a safe copy: sudo ddrescue -n /dev/sdX rescued.img rescued.log Replace /dev/sdX with your actual USB device (e.g. /dev/sdb). Use lsblk to check. This may take a while — especially if the disk has errors. 🧠 Step 3: Mount the Image (If Possible) Try mounting the recovered image: mkdir /mnt/recovered sudo mount -o loop rescued.img /mnt/recovered If that fails with a superblock error, try: sudo mount -t vfat -o loop rescued.img /mnt/recovered Still not working? The partition table might be corrupted. 🔍 Step 4: Inspect the Partition Table Run: fdisk -l rescued.img If you see absurd sizes (e.g. hundreds of GB on an 8GB drive), your partition table is toast. 🧰 Step 5: Recover Files...

Make a docker instance serve SSL (https)

  Enabling SSL on an Apache Docker Instance Step 1 – Enable SSL inside the container docker exec -it <container_name> bash a2enmod ssl socache_shmcb Step 2 – Copy SSL certificate and key from host to container On the host, use the actual files from /etc/letsencrypt/archive/ (not the symlinks in live/ ): docker cp /etc/letsencrypt/archive/mysite.com/fullchain30.pem <container_name>:/etc/ssl/certs/mysite.crt docker cp /etc/letsencrypt/archive/mysite.com/privkey30.pem <container_name>:/etc/ssl/private/mysite.key Step 3 – Edit Apache vhost to use SSL Inside the container: vi /etc/apache2/sites-enabled/000-default.conf Replace content with: <VirtualHost *:80> SSLEngine on ServerName www.mysite.com ServerAlias mysite.com SSLCertificateFile /etc/ssl/certs/mysite.crt SSLCertificateKeyFile /etc/ssl/private/mysite.key DocumentRoot /var/www/html/dockerhtml/ DirectoryIndex index.html index.php </VirtualHost> Step 4 – A...