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

Adding -H|--set-hostname flag #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions rpi-clone
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

VERSION=1.7.1
VERSION=1.7.2
# Version 1.7.2 2017/08/29
# * Adding option to set hostname on clone
# Version 1.7.1 2017/08/19
# * Bugfix: did not set SRC_ROOT when using -s option
# Version 1.7 2017/08/19
Expand Down Expand Up @@ -81,13 +83,14 @@ fi
usage()
{
echo ""
echo "usage: $PGM sdN {-v|--verbose} {-f|--force-initialize} {-s|--src-disk sdS} {-c|--cross-filesystems} {-x}"
echo "usage: $PGM sdN {-v|--verbose} {-f|--force-initialize} {-s|--src-disk sdS} {-c|--cross-filesystems} {-H|--set-hostname hostname} {-x}"
echo " -v - list all files as they are copied."
echo " -f - force initialize the destination partitions"
echo " -s sdS - specify sdS is the booted source disk to clone from."
echo " Use this if the boot source auto detect from /etc/mtab fails."
echo " Use with caution, be sure sdS is really the booted disk."
echo " -c - cross filesystem boundaries (include mounted drives)"
echo " -H - set hostname of cloned pi"
echo " -x - use set -x for very verbose bash shell script debugging"
echo ""
echo " Example: $PGM sda"
Expand Down Expand Up @@ -160,6 +163,11 @@ do
SRC_ROOT=${SRC_DISK}2
fi
;;
-H|--set-hostname)
shift
NEW_HOSTNAME=$1
SET_HOSTNAME=on
;;
-x)
set -x
;;
Expand Down Expand Up @@ -548,6 +556,12 @@ echo "$DATE $HOSTNAME $PGM : clone to $DST_DISK ($DST_ROOT_VOL_NAME)" \
>> $CLONE_LOG
echo "$DATE $HOSTNAME $PGM : clone to $DST_DISK ($DST_ROOT_VOL_NAME)" \
>> $CLONE/$CLONE_LOG

if [ "$SET_HOSTNAME" = "on" ]
then
echo $NEW_HOSTNAME > $CLONE/etc/hostname
sed -i "s/$HOSTNAME/$NEW_HOSTNAME/" $CLONE/etc/hosts
fi


STOP_TIME=`date '+%H:%M:%S'`
Expand Down