diff --git a/README.md b/README.md index 29a75a98fd..ec8ee8e662 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ ntp sets rpi to host timing locally or to networkmode outputs the current network mode button gives the gpio pin 18 an action feedback sends feedback -clone [device path] clones the current SD Card onto a secondary SD Card or specified device +clone [detect|device path] clones the current SD Card onto a secondary SD Card or specified device restore [device path] restores a treehouses image to an SD Card or specified device burn [device path] download and burns the latest treehouses image to the SD card or specified device rebootneeded shows if reboot is required to apply changes diff --git a/_treehouses b/_treehouses index c565821854..38d8a2feb9 100644 --- a/_treehouses +++ b/_treehouses @@ -47,6 +47,7 @@ treehouses changelog treehouses changelog compare treehouses changelog view treehouses clone +treehouses clone detect treehouses config treehouses config add treehouses config clear diff --git a/modules/clone.sh b/modules/clone.sh index 636d17c910..3b7bbf5cdf 100644 --- a/modules/clone.sh +++ b/modules/clone.sh @@ -1,41 +1,58 @@ function clone { - local device a b + local argument a b checkrpi checkroot checkargn $# 1 - device="$1" - if [ -z "$device" ]; then - device="/dev/sdb" - fi - - a=$(fdisk -l |grep /dev/mmcblk0: | grep -P '\d+ (?=bytes)' -o) - #echo "$a - /dev/mmcblk0" - - b=$(fdisk -l |grep "$device": | grep -P '\d+ (?=bytes)' -o) - #echo "$b - /dev/sdb" - - if [ -z "$a" ] || [ -z "$b" ]; then - echo "Error: the device $device wasn't detected. Please use 'fdisk -l' to find the device name." - return 1 - fi - - if [ $b -lt $a ]; then - echo "Error: the device $device is not big enough" - return 1 - fi - - if [ $a -eq $b ] || [ $a -lt $b ]; then - echo "copying...." - echo u > /proc/sysrq-trigger - dd if=/dev/mmcblk0 bs=1M of="$device" status=progress - fi - - echo ; echo "A reboot is needed to re-enable write permissions to OS." + argument="$1" + path="$(lsblk -lp | awk '{print $1}' | grep -o '/dev/sd[a-z]' | sort -u)" + + case $argument in + + "detect") + if [[ $path != *"dev"* ]]; then + echo "Error: Could not detect any devices. Try plugging your device into a different slot." + + else + echo "Detected the following devices:" + echo $path + fi + ;; + + *) + if [ -z "$argument" ]; then + argument="/dev/sdb" + fi + + a=$(fdisk -l |grep /dev/mmcblk0: | grep -P '\d+ (?=bytes)' -o) + #echo "$a - /dev/mmcblk0" + + b=$(fdisk -l |grep "$argument": | grep -P '\d+ (?=bytes)' -o) + #echo "$b - /dev/sdb" + + if [ -z "$a" ] || [ -z "$b" ]; then + echo "Error: the device $argument wasn't detected. Please use '$BASENAME clone detect' to find the device name." + return 1 + fi + + if [ $b -lt $a ]; then + echo "Error: the device $argument is not big enough" + return 1 + fi + + if [ $a -eq $b ] || [ $a -lt $b ]; then + echo "copying...." + echo u > /proc/sysrq-trigger + dd if=/dev/mmcblk0 bs=1M of="$argument" status=progress + fi + + echo ; echo "A reboot is needed to re-enable write permissions to OS." + ;; + esac } function clone_help { echo - echo "Usage: $BASENAME clone [device path]" + echo "Usage: $BASENAME clone [detect|device path]" echo echo "clones your treehouses image to an SDCard" echo @@ -43,7 +60,10 @@ function clone_help { echo " $BASENAME clone" echo " Will clone the current system to /dev/sdb (by default)." echo + echo " $BASENAME clone detect" + echo " Will display the paths for connected devices (e.g. /dev/sda)." + echo echo " $BASENAME clone /dev/sda" - echo " Will clone the current system to /dev/sda" + echo " Will clone the current system to /dev/sda." echo } diff --git a/modules/help.sh b/modules/help.sh index f1efa15926..519abe8b28 100644 --- a/modules/help.sh +++ b/modules/help.sh @@ -61,7 +61,7 @@ ntp sets rpi to host timing locally or to networkmode outputs the current network mode button gives the gpio pin 18 an action feedback sends feedback -clone [device path] clones the current SD card onto a secondary SD card or specified device +clone [detect| device path] clones the current SD card onto a secondary SD card or specified device restore [device path] restores a treehouses image to an SD card or specified device burn [device path] download and burns the latest treehouses image to the SD card or specified device rebootneeded shows if reboot is required to apply changes diff --git a/package.json b/package.json index 8598910798..dc7df25dfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@treehouses/cli", - "version": "1.25.21", + "version": "1.25.22", "remote": "4000", "description": "Thin command-line interface for Raspberry Pi low level configuration.", "main": "cli.sh",