Last active
May 29, 2017 14:47
-
-
Save imrehg/f2270b966ab166b4462d57698e4410f5 to your computer and use it in GitHub Desktop.
system copier for resin devices
This file contains hidden or 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 | |
# Copy everything up intil resin-data (mmcblk0p6 usually) | |
# and send it over the ssh connection, compressed | |
DEVICE=/dev/mmcblk0 | |
PARTITION=mmcblk0p5 | |
# Get partition end position in blocks | |
FSSIZE=$(/sbin/fdisk -l -o Device,End ${DEVICE} | grep ${PARTITION} | awk '{ print $2 }') | |
# Copy data, compress, and send over STDOUT | |
/bin/dd if=/dev/mmcblk0 conv=sync,noerror bs=512 status=none count=${FSSIZE} | gzip -c |
This file contains hidden or 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 | |
function fatal() | |
{ | |
echo $@ >&2 | |
if [ -f /tmp/systemcopy_err ]; then | |
echo -e "\nOUTPUT:\n" | |
cat /tmp/systemcopy_err | |
fi | |
exit 1 | |
} | |
rm -f /tmp/systemcopy_err | |
if [ -z "$1" ]; then | |
fatal usage: $(basename $0) [device uuid] | |
fi | |
if [ ! -f copycmd.sh ]; then | |
fatal Missing copycmd.sh file. | |
fi | |
uuid=$1 | |
# Gets current script dir, see http://stackoverflow.com/a/246128. | |
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | |
out_dir=${script_dir}/out | |
out_file=${uuid}_$(date +%Y%m%d%H%M).img.gz | |
output=${out_dir}/${out_file} | |
mkdir -p ${out_dir} | |
ssh_opts="-o Hostname=$uuid.vpn -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | |
echo Executing script... | |
ssh $ssh_opts resin 'bash -s' <${script_dir}/copycmd.sh >$output 2>/tmp/systemcopy_err | |
[ "$?" != 0 ] && fatal "ERROR: Script execution failed." | |
echo Done! Output stored in $out_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment