Last active
August 5, 2020 09:50
-
-
Save diginfo/73f6eff45a714c856582855c6be4aba0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# bash <(curl -Ls https://gist.github.com/diginfo/73f6eff45a714c856582855c6be4aba0/raw/) | |
# | |
## /etc/fstab | |
## NFS MOUNTS | |
# 192.168.42.35:/mnt/DroboFS/Shares/Public /nfs/drobo/Public nfs auto,_netdev,noatime,nolock,bg,intr,tcp,actimeo=1800 0 0 | |
# 192.168.42.35:/mnt/DroboFS/Shares/FTPusers /nfs/drobo/FTPusers nfs auto,_netdev,noatime,nolock,bg,intr,tcp,actimeo=1800 0 0 | |
# 192.168.42.35:/mnt/DroboFS/Shares/Backups /nfs/drobo/Backups nfs auto,_netdev,noatime,nolock,bg,intr,tcp,actimeo=1800 0 0 | |
# /etc/udev/rules.d/10-usb.rules | |
# ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ATTRS{idProduct}=="01bd", ATTRS{idVendor}=="054c", SYMLINK+="usbcf" | |
# ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ATTRS{idProduct}=="5106", ATTRS{idVendor}=="174c", SYMLINK+="usbcfast" | |
# ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ATTRS{idProduct}=="0711", ATTRS{idVendor}=="2109", SYMLINK+="usbsata" | |
# ACTION=="add", KERNEL=="sd*", SUBSYSTEM=="block", ATTRS{idProduct}=="5106", ATTRS{idVendor}=="174c", SYMLINK+="usbm2" | |
# udevadm trigger --action=add --subsystem-match=block | |
PATH="/nfs/drobo/Backups/archts/images/current/" | |
## Check if images are mounted. | |
if [ -d "$PATH" ]; then | |
echo "Directory $PATH exists." | |
else | |
echo "Error: Directory $PATH does not exist." | |
exit 1; | |
fi | |
## PATHS BASED ON ID ( ls /dev/disk/by-id -all ) | |
CFPATH="/dev/disk/by-id/usb-Sony_Card_R_W_-CF_00000014C9E6-0:0"; | |
FASTPATH="/dev/disk/by-id/wwn-0x5000000000000000"; | |
M2PATH="/dev/disk/by-id/usb-TO_Exter_nal_USB_3.0_201503310007F-0:0"; | |
SATAPATH="/dev/disk/by-id/usb-TS8GHSD3_10_000000000028-0:0"; | |
cd "$PATH" | |
function size { | |
CFSIZE=0 | |
CFSIZE=$(/usr/bin/fdisk -l $OFPATH | /usr/bin/grep "Disk $OFPATH:" | /usr/bin/tr -d ',' | /usr/bin/awk '{ print $5 }'); | |
IMGSIZE=$(/usr/bin/fdisk -l $IMG | /usr/bin/grep "Disk $IMG:" | /usr/bin/tr -d ',' | /usr/bin/awk '{ print $5 }'); | |
echo "CFSIZE:$CFSIZE, IMAGE:$IMGSIZE" | |
if [ -z "$CFSIZE" ] || [ $CFSIZE -lt "$IMGSIZE" ]; then | |
echo "CF Card is too small $CFSIZE" | |
exit 1 | |
fi | |
} | |
function safe { | |
if [ "$OFPATH" == "/dev/sda" ]; then | |
echo "Cannot write to System Disk." | |
exit 1 | |
fi | |
} | |
function clone { | |
safe; | |
read -p "Are you sure y/n ? " -n 1 -r | |
echo # (optional) move to a new line | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo "Cloning, Please Wait..." | |
/usr/bin/dd if=$IMG of=$OFPATH bs=512M status=progress | |
echo "##################################" | |
echo "Please Apply Label: $IMG" | |
echo "##################################" | |
fi | |
} | |
if [ "$1" == "830" ]; then | |
OFPATH=$CFPATH | |
IMG=$(/usr/bin/ls 5100T-830_*.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "832" ]; then | |
OFPATH=$CFPATH | |
IMG=$(/usr/bin/ls 5100T-832R_*.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "834" ]; then | |
OFPATH=$CFPATH; | |
IMG=$(/usr/bin/ls 5100T-834R_*.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "830-demo" ]; then | |
OFPATH=$CFPATH | |
IMG=$(/usr/bin/ls DEMOR_*.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "bios-cf" ]; then | |
OFPATH=$CFPATH | |
IMG=$(/usr/bin/ls PK*-BIOS.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "bios-cfast" ]; then | |
OFPATH=$FASTPATH; | |
IMG=$(/usr/bin/ls PK*-BIOS.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "uefi-sata" ]; then | |
OFPATH=$SATAPATH; | |
IMG=$(/usr/bin/ls PK*-UEFI.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
elif [ "$1" == "uefi-m2" ]; then | |
OFPATH=$M2PATH; | |
IMG=$(/usr/bin/ls PK*-UEFI.img) | |
echo "CLONE $IMG to $OFPATH" | |
size | |
clone | |
else | |
echo "usage (Old Firmware) : clone [830|830-demo|832|834" | |
echo "usage (New Firmware) : clone [bios-cf|bios-cfast|uefi-sata|uefi-m2" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment