Posts

script to explode a pdf into jpgs for individual page editing

 script to explode a pdf into jpgs for individual page editing #!/bin/bash sanitize_filename() {     echo "$1" | sed 's/[^a-zA-Z0-9._-]/_/g' } if [ $# -ne 1 ]; then     echo "Usage: $0 <pdf-file>"     exit 1 fi input_file="$1" if [ ! -f "$input_file" ]; then     echo "Error: file not found: $input_file"     exit 1 fi base_filename=$(basename "$input_file" .pdf) sanitized_filename=$(sanitize_filename "$base_filename") output_dir="exploded_$sanitized_filename" mkdir -p "$output_dir" echo "Input file: $input_file" echo "Output folder: $output_dir" pdftoppm -jpeg "$input_file" "$output_dir/${sanitized_filename}_page" if [ $? -ne 0 ]; then     echo "Error during PDF to JPEG conversion."     exit 1 fi i=1 for img in "$output_dir"/"${sanitized_filename}_page"-*.jpg; do     [ -f "$img" ] || continue     mv "...

make minimal bootable linux disk

 #!/bin/bash TARGET_DISK="/dev/sdb" TARGET_EFI="${TARGET_DISK}1" TARGET_ROOT="${TARGET_DISK}2" MOUNTPOINT="/mnt/newroot" RELEASE="noble" MIRROR="http://archive.ubuntu.com/ubuntu/" echo "WARNING: This will erase ${TARGET_DISK}" echo "Press CTRL+C now if this is wrong." sleep 10 sudo apt-get update sudo apt-get install -y debootstrap gdisk dosfstools e2fsprogs grub-efi-amd64-bin grub-efi-amd64-signed shim-signed linux-image-generic sudo umount "${TARGET_EFI}" 2>/dev/null sudo umount "${TARGET_ROOT}" 2>/dev/null sudo umount "${MOUNTPOINT}/boot/efi" 2>/dev/null sudo umount "${MOUNTPOINT}" 2>/dev/null sudo sgdisk --zap-all "${TARGET_DISK}" sudo sgdisk -n 1:2048:+512M -t 1:ef00 -c 1:"EFI System" "${TARGET_DISK}" sudo sgdisk -n 2:0:0 -t 2:8300 -c 2:"Linux root" "${TARGET_DISK}" sudo partprobe "${TARGET_DISK}...

pdf paginator script

#!/bin/bash if [ -z "$1" ]; then   echo "Usage: $0 filename.pdf [colour]"   exit 1 fi f="$1" colour="$2" if [ -z "$colour" ]; then   colour="red"   echo "No colour supplied; defaulting to red."   echo "Options: red orange green cyan blue brown purple black" fi case "$colour" in   red) rgb="1 0 0" ;;   orange) rgb="1 0.5 0" ;;   green) rgb="0 0.6 0" ;;   cyan) rgb="0 0.8 0.8" ;;   blue) rgb="0 0 1" ;;   brown) rgb="0.55 0.27 0.07" ;;   purple) rgb="0.5 0 0.5" ;;   black) rgb="0 0 0" ;;   *)     echo "Invalid colour: $colour"     echo "Options: red orange green cyan blue brown purple black"     exit 1     ;; esac n=$(pdftk "$f" dump_data | awk '/NumberOfPages/ {print $2}') ps="${f%.pdf}_numbers.ps" stamp="${f%.pdf}_numbers.pdf" out="${f%.pdf}_numbered.pdf...

Dropbox spinning but never syncing

  Symptom On Ubuntu (e.g. 24.04), Dropbox sits on: Starting... or reports: Unable to monitor entire Dropbox folder hierarchy dropbox status may show it stuck indexing or perpetually “Starting…” despite restarts. Cause Dropbox relies on the Linux kernel’s inotify subsystem to monitor file changes in real time. Each file or directory requires an inotify “watch”. Ubuntu’s default limit is often: fs.inotify.max_user_watches = 65536 Large Dropbox folders (hundreds of thousands of files) exceed this limit. When the watch limit is exhausted, Dropbox cannot monitor the full directory tree and stalls during startup or indexing. This is unrelated to inodes. It is a kernel event-watch limit. Diagnostic Test Check your current limit: cat /proc/sys/fs/inotify/max_user_watches Check your file count: find ~/Dropbox -type f | wc -l If file count approaches or exceeds the watch limit, that is the problem. You may also see this error explicitly: dropbox status Output example: Unable to monitor ent...

hikvision brand flash drives are garbage do not buy

 hi. I have a low-quality usb ssd drive, hikvision brand. I have engaged with you on this particuilar drive before. When I try copy files to it, it fails quite quickly. I remember that f3 (fighting flash fraud) software can check a drive for integrity (hardware). I also believe there are ways to mark and deallocate bad blocks. Please give me a script to do this, asssumiing bash ubuntu linux 24 and that it must pre-install any apt-get packages needed when it runs Below is a single self-contained bash script that: Installs required tools ( f3 , e2fsprogs , smartmontools where applicable) Destructively tests the USB SSD with f3 (integrity / fake-capacity check) Optionally recreates the filesystem and marks bad blocks (only works reliably for ext4) ⚠️ WARNING : THIS WILL ERASE ALL DATA ON THE DRIVE. usb_ssd_check_and_repair.sh #!/usr/bin/env bash set -e if [ " $EUID " -ne 0 ]; then echo "Run as root." exit 1 fi DEV= " $1 " ...

setup google drive and dropbox as automounts on linux

 #!/bin/bash set -e # mount points mkdir -p "$HOME/DropboxMount" mkdir -p "$HOME/GDriveMount" # ensure systemd user dir exists mkdir -p "$HOME/.config/systemd/user" # Dropbox service cat > "$HOME/.config/systemd/user/rclone-dropbox.service" <<'EOF' [Unit] Description=Mount Dropbox via rclone After=network-online.target [Service] Type=simple ExecStartPre=/bin/mkdir -p %h/DropboxMount ExecStart=/usr/bin/rclone mount dropbox: %h/DropboxMount --vfs-cache-mode writes ExecStop=/bin/fusermount -u %h/DropboxMount Restart=on-failure [Install] WantedBy=default.target EOF # Google Drive service cat > "$HOME/.config/systemd/user/rclone-gdrive.service" <<'EOF' [Unit] Description=Mount Google Drive via rclone After=network-online.target [Service] Type=simple ExecStartPre=/bin/mkdir -p %h/GDriveMount ExecStart=/usr/bin/rclone mount gdrive: %h/GDriveMount --vfs-cache-mode writes ExecStop=/bin/fusermount -u %h/GDriveMou...

convert any annoying media format into a standard media format

 #!/bin/bash # mediaconvert – auto-convert any media file with progress bar infile="$1" [ -z "$infile" ] && { echo "Usage: mediaconvert <file>"; exit 1; } ext="${infile##*.}" base="${infile%.*}" case "$ext" in     avi|mov|mkv|webm|flv|mpg|mpeg|mp4)         outfile="${base}.mp4"         pv "$infile" | ffmpeg -y -i - -c:v libx264 -c:a aac -strict -2 "$outfile"         ;;     mp3|m4a|ogg|wav|flac|aac|webm)         outfile="${base}.mp3"         pv "$infile" | ffmpeg -y -i - -acodec libmp3lame -q:a 2 "$outfile"         ;;     jpg|jpeg|png|bmp|gif|tiff|webp)         outfile="${base}.jpg"         pv "$infile" | ffmpeg -y -i - -q:v 2 "$outfile"         ;;     *)         echo "Unsupported file type: $ext"         exit 1 ...