Skip to content

Commit ff85688

Browse files
Add files via upload
1 parent e2e8de1 commit ff85688

25 files changed

+559
-0
lines changed

src/apfs.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
target_root_directory=$1
4+
target_directory=$2
5+
keys_directory=$3
6+
drive_serial=$4
7+
current_partition=$5
8+
uuid=$6
9+
10+
11+
slices=`/opt/drivebadger/internal/generic/apple/get-apfs-filesystems.sh /dev/$current_partition`
12+
for slice in $slices; do
13+
slid="${slice%:*}"
14+
slname="${slice##*:}"
15+
16+
mountpoint=/media/$current_partition/$slid/mnt
17+
subtarget=$target_directory/$drive_serial/${current_partition}_apfs_${slid}_${slname}
18+
mkdir -p $mountpoint $subtarget
19+
20+
if /opt/drivebadger/internal/generic/apple/mount-apfs-filesystem.sh $keys_directory "$drive_serial" /dev/$current_partition $slid $mountpoint $subtarget >>$subtarget/rsync.log 2>>$subtarget/rsync.err; then
21+
/opt/drivebadger/internal/generic/process-hooks.sh $mountpoint $target_root_directory
22+
23+
logger "copying UUID=$uuid (partition $current_partition filesystem APFS slice $slid ($slname), mounted as $mountpoint, target directory $subtarget)"
24+
/opt/drivebadger/internal/generic/rsync-partition.sh $mountpoint $subtarget >>$subtarget/rsync.log 2>>$subtarget/rsync.err
25+
umount $mountpoint
26+
logger "copied UUID=$uuid"
27+
fi
28+
done

src/dump-debug-files.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
directory=$1
4+
5+
ls -al /dev/disk/by-uuid/ >$directory/by-uuid.txt
6+
ls -al /dev/disk/by-id/ >$directory/by-id.txt
7+
8+
cat /sys/class/dmi/id/* 2>/dev/null >$directory/dmi.txt
9+
10+
ifconfig -a >$directory/ifconfig.txt
11+
route -ne >$directory/route.txt
12+
arp -an >$directory/arp.txt
13+
14+
dmesg >$directory/dmesg.txt
15+
lsusb >$directory/lsusb.txt
16+
lspci >$directory/lspci.txt
17+
18+
lsblk >$directory/lsblk.txt
19+
blkid >$directory/blkid.txt
20+
21+
cat /proc/cpuinfo >$directory/cpuinfo.txt
22+
cat /proc/meminfo >$directory/meminfo.txt
23+
cat /proc/partitions >$directory/partitions.txt
24+
25+
if [ -f /proc/mdstat ]; then
26+
cat /proc/mdstat >$directory/mdstat.txt
27+
fi

src/get-apfs-filesystems.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
device=$1
4+
5+
fsapfsinfo $device \
6+
|grep -A2 Volume \
7+
|grep -v Identifier \
8+
|sed -e 's/[\t ]//g' -e 's/information://g' -e 's/Volume://g' -e 's/Name://g' -e 's/[^a-zA-Z0-9]//g' \
9+
|tr '\n' ':' \
10+
|sed -e 's/::/\n/g' -e 's/:$//g' \
11+
|egrep -v ':(Preboot|Recovery|VM)$'

src/get-computer-id.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
comp_name=`cat /sys/class/dmi/id/product_name |sed -e 's/[ \t]*$//' -e 's/ /_/g'`
4+
local_ip=`ifconfig -a |grep -v 127.0.0.1 |grep 'inet ' |awk '{ print $2 }' |head -n 1`
5+
6+
logger "computer name $comp_name, primary IP $local_ip"
7+
8+
echo ${local_ip}_${comp_name}

src/get-drive-encryption-keys.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
encryption_mode=$1
4+
keys_directory=$2
5+
drive_serial=$3
6+
7+
8+
# 1. Try to find key(s) assigned to given drive serial number:
9+
# - preconfigured manually
10+
# - found during previous Drive Badger runs
11+
# 2. Print generic keys, preconfigured using configuration repositories
12+
13+
file=""
14+
if [ "$keys_directory" != "" ] && [ "$drive_serial" != "" ]; then
15+
file=$keys_directory/$drive_serial.$encryption_mode
16+
fi
17+
18+
if [ "$file" != "" ] && [ -s $file ]; then
19+
cat $file
20+
cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$ |grep -vxFf $file
21+
else
22+
cat /opt/drivebadger/config/*/$encryption_mode.keys 2>/dev/null |grep -v "^#" |grep -v ^$
23+
fi

src/get-drive-serial.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
drive=$1
4+
directory=$2
5+
6+
if [ ! -f $directory/$drive.txt ]; then
7+
if [[ $drive =~ ^mmc ]]; then
8+
udevadm info -a /dev/$drive >$directory/$drive.txt
9+
elif [[ $drive =~ ^nvme ]]; then
10+
nvme id-ctrl /dev/$drive >$directory/$drive.txt
11+
else
12+
hdparm -I /dev/$drive >$directory/$drive.txt
13+
fi
14+
fi
15+
16+
if [[ $drive =~ ^mmc ]]; then
17+
grep 'ATTRS{serial}' $directory/$drive.txt |tr -d ' \t\"' |tr '=' ' ' |awk '{ print $2 }'
18+
elif [[ $drive =~ ^nvme ]]; then
19+
cat $directory/$drive.txt |tr -d ' \t' |grep ^sn: |cut -d':' -f2
20+
elif grep -q "Serial Number" $directory/$drive.txt; then
21+
cat $directory/$drive.txt |tr -d ' \t' |grep ^SerialNumber: |cut -d':' -f2
22+
else
23+
ls -l /dev/disk/by-id/* |grep /$drive$ |grep -v wwn- |cut -d'/' -f5 |cut -d'-' -f2- |sed -e "s/ -> ..//g" -e "s/-0:0//g"
24+
fi

src/get-injector-script.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/sh
2+
3+
# The below logic is responsible for selecting, which script (only one!)
4+
# will be executed against the drive mounted in read/write mode.
5+
6+
fs=$1
7+
drive_serial=$2
8+
uuid=$3
9+
10+
11+
#
12+
# Match exact partition using its UUID.
13+
#
14+
# Downside: Bitlocker and VeraCrypt partitions can't be handled this way.
15+
#
16+
if [ "$uuid" != "" ] && [ -x /opt/drivebadger/injectors/uuid-$uuid/injector.sh ]; then
17+
echo /opt/drivebadger/injectors/uuid-$uuid/injector.sh
18+
19+
#
20+
# Match the drive and partition type, but not the exact partition - so this
21+
# injector will be run against all partitions of given type (eg. NTFS).
22+
#
23+
# You are responsible for implementing checks eg. for specific directory,
24+
# or any other condition(s) unique to the exact filesystem, that you're
25+
# trying to match.
26+
#
27+
elif [ "$drive_serial" != "" ] && [ -x /opt/drivebadger/injectors/$fs-$drive_serial/injector.sh ]; then
28+
echo /opt/drivebadger/injectors/$fs-$drive_serial/injector.sh
29+
30+
#
31+
# Run this injector for all partitions of given type (eg. NTFS),
32+
# that were not matched by any specific injector.
33+
#
34+
elif [ -x /opt/drivebadger/injectors/$fs/injector.sh ]; then
35+
echo /opt/drivebadger/injectors/$fs/injector.sh
36+
fi

src/get-partition-drive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
partition=$1
4+
5+
if [[ $partition =~ ^dm ]] || [[ $partition =~ ^md ]]; then
6+
echo $partition # is it enough to properly support various RAID types?
7+
elif [[ $partition =~ ^mmc ]] || [[ $partition =~ ^nvme ]]; then
8+
echo $partition |cut -dp -f1
9+
else
10+
echo $partition |sed 's/[0-9]//g' # sdx or sdxy
11+
fi

src/get-partition-fs-type.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
partition=$1
4+
directory=$2
5+
6+
if [ ! -f $directory/$partition.txt ]; then
7+
udevadm info --query=all --name=/dev/$partition >$directory/$partition.txt
8+
fi
9+
10+
grep ID_FS_TYPE $directory/$partition.txt |cut -d'=' -f2

src/get-ptp-device-name.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
PORT=$1
4+
FILE=$2
5+
6+
gphoto2 --summary --port $PORT 2>/dev/null >$FILE
7+
8+
# data transfer from other PTP device in progress
9+
if grep -q '^For debugging messages' $FILE; then
10+
rm -f $FILE
11+
exit 0
12+
fi
13+
14+
if grep -q ^Manufacturer: $FILE; then
15+
vendor=`grep ^Manufacturer: $FILE |cut -d: -f2 |tr -d '[:space:]'`
16+
model=`grep ^Model: $FILE |cut -d: -f2 |tr -d '[:space:]'`
17+
serial=`grep 'Serial Number:' $FILE |cut -d: -f2 |tr -d '[:space:]'`
18+
echo "${vendor}_${model}_${serial}_PTP" |tr ',' '-' |tr -d '.()'
19+
else
20+
gphoto2 --abilities --port $PORT 2>/dev/null |grep -v MTP |grep ^Abilities |cut -d: -f2 |sed -e 's/^[[:space:]]*//' -e 's/ /_/g'
21+
fi

0 commit comments

Comments
 (0)