1
0
mirror of https://github.com/kmein/niveum synced 2026-03-18 11:01:07 +01:00
Files
niveum/.bin/fix-sd.sh

22 lines
472 B
Bash
Raw Normal View History

2024-09-25 22:14:38 +02:00
#!/bin/sh
2024-10-05 14:53:59 +02:00
set -xfu
2024-09-25 22:14:38 +02:00
drive="$1"
mountpoint="/media/sd-card-$(date +%s)"
2024-10-05 14:53:59 +02:00
backup_directory="$(pwd)"
2024-09-25 22:14:38 +02:00
trap clean EXIT
clean() {
umount "$mountpoint"
2024-10-23 07:54:18 +02:00
rmdir "$mountpoint"
fsck.exfat "$drive"
2024-09-25 22:14:38 +02:00
}
filenames="$(fsck.exfat "$drive" 2>&1 | sed -nE "s/.* file '(.*?)' is not allocated.*/\1/p")"
mkdir "$mountpoint"
mount "$drive" "$mountpoint"
echo "$filenames" | while read -r filename; do
2024-10-05 14:53:59 +02:00
find "$mountpoint" -type f -name "$filename" -exec mv {} "$backup_directory" \;
2024-09-25 22:14:38 +02:00
done