-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
04e9e16
clone.sh options template (fixes #2067)
JLKwong d06ab11
add detect sub-subcommand (fixes #2067)
JLKwong 327c154
fix case (fixes #2067)
JLKwong 06252d8
fix cases (fixes #2067)
JLKwong d30c867
fix cases (fixes #2067)
JLKwong 1f1ce12
fix cases (fixes #2067)
JLKwong 740924a
add text (fixes #2067)
JLKwong 6820b98
if then (fixes #2067)
JLKwong 1e80c5e
if then (fixes #2067)
JLKwong 2bbd8f1
if then (fixes #2067)
JLKwong d3ec25c
if then (fixes #2067)
JLKwong 6166c04
if then (fixes #2067)
JLKwong 9c8127a
if then (fixes #2067)
JLKwong e5ed5af
if then (fixes #2067)
JLKwong 35f81b9
if then (fixes #2067)
JLKwong 7f8723a
if then (fixes #2067)
JLKwong 0e366f9
if then (fixes #2067)
JLKwong 110faaa
if then (fixes #2067)
JLKwong c03c98e
if then (fixes #2067)
JLKwong 9f087fa
if then (fixes #2067)
JLKwong c548403
if then (fixes #2067)
JLKwong 9a26416
if then (fixes #2067)
JLKwong 683b2bc
if then (fixes #2067)
JLKwong a21ee47
if then (fixes #2067)
JLKwong 847d2e8
if then (fixes #2067)
JLKwong e2e69d8
if then (fixes #2067)
JLKwong ecf32b1
help text (fixes #2067)
JLKwong 367a6d3
help text (fixes #2067)
JLKwong 00738a5
add help text (fixes #2067)
JLKwong 041b09d
upgrade detect (fixes #2067)
JLKwong dcc30f9
debug detect (fixes #2067)
JLKwong 7dc9074
debug detect (fixes #2067)
JLKwong ed7d343
add text for detect (fixes #2067)
JLKwong c4c2137
Update package.json
dogi 4591f39
Merge branch 'master' into 2067-clone-detect
dogi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,68 @@ | ||
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=$(fdisk -l | 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 $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 | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
fdisk -l
piped to the grep command will never output since the^
will try to find a line beginning with/dev/
;fdisk -l
will begin the line with Disk.Also
fdisk -l
requires sudo privileges (I think) which may lead to problems if not running as root.Finally remember to surround the variable value with quotes. Without wrapped quotes, its going to word split.
Heres the piped commands I used for the hardrive path:
path="$(lsblk -lp | awk '{print $1}' | grep -E '/dev/sd.*')"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dogi improved it with this line
lsblk -lp | grep disk | awk '{print $1}' | grep -E '/dev/sd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I test these new piped commands, I get unnecessary duplicates of the same device:
/dev/sdc /dev/sdc1 /dev/sdc2
I'll see if I can get it to only display
/dev/sdc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified it to look like this:
path="$(lsblk -lp | awk '{print $1}' | grep -o '/dev/sd[a-z]' | sort -u)"
On testing it only echoed:
/dev/sdc