From d9616f7f324717f69d95269078653dace074dcde Mon Sep 17 00:00:00 2001 From: PrincessPi3 Date: Mon, 18 May 2026 09:10:48 -0600 Subject: [PATCH] i thiiink da img_dump be workan ok nao.. maybe idk --- customscripts/img_dump.sh | 53 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/customscripts/img_dump.sh b/customscripts/img_dump.sh index 8925498..bd66298 100644 --- a/customscripts/img_dump.sh +++ b/customscripts/img_dump.sh @@ -1,4 +1,13 @@ #!/bin/bash +# todo: +## environment checks for webhook, xz-tools, and pishrink +### install if not found +## sanity checks in cleanup error trap to make sure nothing is wrongly deleted +## ERR/TERMINATE traps +### NO cleanup trap on EXIT +## finish the pi query +## add filename query + set -e # fail on fuckups to iterate fasterrr timestamp="$(date +%Y-%m-%d-%H%M-%Z)" disk="" @@ -6,9 +15,24 @@ log="${timestamp}_img_dump_testin.log" echo > "$log" # initialize to empty img_name="${timestamp}_Kali-Pi5-1TB-Working.img" +check_command() { + command -v "$1" >/dev/null 2>&1 || { + # outputz it as errror + echo >&2 "Required command '$1' not found. Install it and retry." | tee -a "$log" + exit 1 + } +} + +# check da needed cmds~ +for cmd in webhook xz pishrink sha256 sudo; do + check_command "$cmd" +done + # trap function cleanup cleanup () { - webhook "img_dump errored! Cleaning up! seconds: $SECONDS line: $LINENO command: $BASHCOMMAND" true + webhook "$0 errored! Cleaning up! seconds: $SECONDS line: $LINENO command: $BASHCOMMAND" true + # supress errors if they not there + # to save me from testing each one or writing a fun :poe: rm -f "$img_name" 2>/dev/null rm -f "$img_name.sha256" 2>/dev/null rm -f "$img_name.xz" 2>/dev/null @@ -16,14 +40,21 @@ cleanup () { rm -f "$log" 2>/dev/null } -# cleanup any errant files on error -trap cleanup EXIT +# cleanup any errant files on error/termination +trap cleanup ERR +trap cleanup SIGINT +trap cleanup SIGTERM echo -e "\n\n\nSTARTING DUMP OPS\n\n\n" lsblk read -p "Enter Disk Name (ex. sda, sdb no /dev or anything else) " disk_choice disk="/dev/$disk_choice" + +read -p "For Raspberry Pi? y\n default y" picheck + +# for when ask for tag +# read -p "Input File Tag" filetag clear webhook "runnan raw dd img on $disk at to $img_name using 4M bs size (Script Has Run $SECONDS Seconds)" @@ -36,16 +67,30 @@ sudo chmod 660 "$img_name" webhook "generating sha256 checksum of $img_name (from $disk) to $img_name.sha256 (Script Has Run $SECONDS Seconds)" sha256sum "$img_name" | tee -a "$img_name.sha256" +if [[ "$picheck" =~ [nN] ]]; then + webhook "Doing non-pi xz compression on $img_name into $img_name.xz" + xz -v "$img_name" | tee -a "$log" +else + # pishrink + ## -v verbose + ## -r use advanced filesystem repair option if the normal one fails + ## -Z xz compression + ## -a compress using multiple cores + webhook "Doing pi compress using pishrink from $img_name ($disk) to $img_name.xz (Script Has Run $SECONDS Seconds)" + pishrink -v -r -Z -a "$img_name" | tee -a "$log" +fi + # pishrink ## -v verbose ## -r use advanced filesystem repair option if the normal one fails ## -Z xz compression ## -a compress using multiple cores webhook "doing pishrink from $img_name ($disk) to $img_name.xz (Script Has Run $SECONDS Seconds)" -pishrink -v -r -Z -a "$img_name" +pishrink -v -r -Z -a "$img_name" | tee -a "$log" webhook "testing xz integrity: $img_name.xz (Script Has Run $SECONDS Seconds)" xz -t -v "$img_name.xz" | tee -a "$log" +webhook "xz integrity response code: $?" webhook "Generating sha256 checksums of $img_name.xz to $img_name.xz.sha256 (Script Has Run $SECONDS Seconds)" sha256sum "$img_name.xz" | tee -a "$img_name.xz.sha256"