|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +PASSFILE=/opt/deployment-scripts/config/master-luks-password.txt |
| 4 | +DEVLIST=/opt/deployment-scripts/config/drivebadger-devices.txt |
| 5 | +LOCAL=/opt/deployment-scripts/config/local-drives.txt |
| 6 | + |
| 7 | +DISK=$1 # eg. ata-SanDisk_SD9SN8W2T00_19359H123456 |
| 8 | +ARCH=$2 # eg. amd64 |
| 9 | +IMAGE=/opt/deployment-scripts/iso/kali-linux-2021.4a-live-$ARCH.iso |
| 10 | + |
| 11 | +if [ "$2" = "" ]; then |
| 12 | + echo "USAGE: $0 <disk> <architecture> [--plain]" |
| 13 | + exit 1 |
| 14 | +elif [ ! -f $IMAGE ]; then |
| 15 | + echo "ERROR: $IMAGE not found (you need to download image for chosen architecture: $2)" |
| 16 | + exit 1 |
| 17 | +elif [ ! -e /dev/disk/by-id/$DISK ]; then |
| 18 | + echo "ERROR: $DISK not found" |
| 19 | + exit 1 |
| 20 | +elif grep -qxF $DISK $DEVLIST; then |
| 21 | + echo "ERROR: disk $DISK already configured" |
| 22 | + exit 1 |
| 23 | +elif grep -qxF $DISK $LOCAL; then |
| 24 | + echo "ERROR: disk $DISK is a local drive" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +DEVICE=`readlink -f /dev/disk/by-id/$DISK |cut -d'/' -f3` |
| 29 | + |
| 30 | +if grep -q "$DEVICE " /proc/mounts; then |
| 31 | + echo "ERROR: disk $DISK is mounted (as device $DEVICE)" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +echo "copying image $IMAGE" |
| 36 | +echo "to device /dev/$DEVICE" |
| 37 | +dd if=$IMAGE of=/dev/$DEVICE status=progress |
| 38 | + |
| 39 | +echo "adding new partition" |
| 40 | +parted /dev/$DEVICE --script -- mkpart primary 10GB 100% |
| 41 | +mkdir -p /mnt/drivebadger_setup |
| 42 | + |
| 43 | +if [ "$3" = "--plain" ]; then |
| 44 | + mkfs.ext4 -m 0 -L persistence /dev/${DEVICE}3 |
| 45 | + mount /dev/${DEVICE}3 /mnt/drivebadger_setup |
| 46 | +else |
| 47 | + echo "configuring LUKS encryption" |
| 48 | + cat $PASSFILE |cryptsetup --cipher aes-xts-plain64 --key-size 512 --hash sha512 --iter-time 5000 luksFormat /dev/${DEVICE}3 |
| 49 | + cat $PASSFILE |cryptsetup luksOpen /dev/${DEVICE}3 drivebadger_setup |
| 50 | + mkfs.ext4 -m 0 -L persistence /dev/mapper/drivebadger_setup |
| 51 | + mount /dev/mapper/drivebadger_setup /mnt/drivebadger_setup |
| 52 | +fi |
| 53 | + |
| 54 | +echo "setting up persistent filesystem contents" |
| 55 | +/opt/deployment-scripts/drivebadger/install.sh /mnt/drivebadger_setup |
| 56 | +umount /mnt/drivebadger_setup |
| 57 | + |
| 58 | +if [ "$3" != "--plain" ]; then |
| 59 | + cryptsetup luksClose drivebadger_setup |
| 60 | +fi |
| 61 | + |
| 62 | +echo "adding $DISK to device list $DEVLIST" |
| 63 | +echo $DISK >>$DEVLIST |
0 commit comments