Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treehouses clone detect (fixes #2067) #2083

Merged
merged 35 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
04e9e16
clone.sh options template (fixes #2067)
JLKwong Mar 11, 2021
d06ab11
add detect sub-subcommand (fixes #2067)
JLKwong Mar 11, 2021
327c154
fix case (fixes #2067)
JLKwong Mar 11, 2021
06252d8
fix cases (fixes #2067)
JLKwong Mar 11, 2021
d30c867
fix cases (fixes #2067)
JLKwong Mar 11, 2021
1f1ce12
fix cases (fixes #2067)
JLKwong Mar 11, 2021
740924a
add text (fixes #2067)
JLKwong Mar 11, 2021
6820b98
if then (fixes #2067)
JLKwong Mar 11, 2021
1e80c5e
if then (fixes #2067)
JLKwong Mar 11, 2021
2bbd8f1
if then (fixes #2067)
JLKwong Mar 11, 2021
d3ec25c
if then (fixes #2067)
JLKwong Mar 11, 2021
6166c04
if then (fixes #2067)
JLKwong Mar 11, 2021
9c8127a
if then (fixes #2067)
JLKwong Mar 11, 2021
e5ed5af
if then (fixes #2067)
JLKwong Mar 11, 2021
35f81b9
if then (fixes #2067)
JLKwong Mar 11, 2021
7f8723a
if then (fixes #2067)
JLKwong Mar 11, 2021
0e366f9
if then (fixes #2067)
JLKwong Mar 11, 2021
110faaa
if then (fixes #2067)
JLKwong Mar 11, 2021
c03c98e
if then (fixes #2067)
JLKwong Mar 11, 2021
9f087fa
if then (fixes #2067)
JLKwong Mar 11, 2021
c548403
if then (fixes #2067)
JLKwong Mar 11, 2021
9a26416
if then (fixes #2067)
JLKwong Mar 11, 2021
683b2bc
if then (fixes #2067)
JLKwong Mar 11, 2021
a21ee47
if then (fixes #2067)
JLKwong Mar 11, 2021
847d2e8
if then (fixes #2067)
JLKwong Mar 11, 2021
e2e69d8
if then (fixes #2067)
JLKwong Mar 11, 2021
ecf32b1
help text (fixes #2067)
JLKwong Mar 11, 2021
367a6d3
help text (fixes #2067)
JLKwong Mar 11, 2021
00738a5
add help text (fixes #2067)
JLKwong Mar 11, 2021
041b09d
upgrade detect (fixes #2067)
JLKwong Mar 13, 2021
dcc30f9
debug detect (fixes #2067)
JLKwong Mar 13, 2021
7dc9074
debug detect (fixes #2067)
JLKwong Mar 13, 2021
ed7d343
add text for detect (fixes #2067)
JLKwong Mar 13, 2021
c4c2137
Update package.json
dogi Mar 13, 2021
4591f39
Merge branch 'master' into 2067-clone-detect
dogi Mar 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ntp <local|internet> sets rpi to host timing locally or to
networkmode outputs the current network mode
button <off|bluetooth> gives the gpio pin 18 an action
feedback <message> 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
Expand Down
1 change: 1 addition & 0 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 51 additions & 31 deletions modules/clone.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,69 @@
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
echo "Example:"
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
}
2 changes: 1 addition & 1 deletion modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ntp <local|internet> sets rpi to host timing locally or to
networkmode outputs the current network mode
button <off|bluetooth> gives the gpio pin 18 an action
feedback <message> 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
Expand Down