Skip to content

Commit fd081dc

Browse files
author
Chiradeep Vittal
committed
Bug 8199: only inject if needed
1 parent 8a1ca01 commit fd081dc

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

scripts/vm/systemvm/injectkeys.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ inject_into_iso() {
1616
local newpubkey=$2
1717
local backup=${isofile}.bak
1818
local tmpiso=${TMP}/$1
19-
rm -rf $TMPDIR
20-
mkdir -p $TMPDIR
21-
[ ! -d $TMPDIR ] && echo "$(basename $0): Could not find/create temporary dir $TMPDIR" && return 1
2219
[ ! -f $isofile ] && echo "$(basename $0): Could not find systemvm iso patch file $isofile" && return 1
23-
cp -b $isofile $backup
24-
[ $? -ne 0 ] && echo "$(basename $0): Failed to backup original iso $isofile" && return 1
2520
mount -o loop $isofile $MOUNTPATH
2621
[ $? -ne 0 ] && echo "$(basename $0): Failed to mount original iso $isofile" && return 1
22+
diff -q $MOUNTPATH/authorized_keys $newpubkey &> /dev/null && return 0
23+
cp -b $isofile $backup
24+
[ $? -ne 0 ] && echo "$(basename $0): Failed to backup original iso $isofile" && return 1
25+
rm -rf $TMPDIR
26+
mkdir -p $TMPDIR
27+
[ ! -d $TMPDIR ] && echo "$(basename $0): Could not find/create temporary dir $TMPDIR" && return 1
2728
cp -fr $MOUNTPATH/* $TMPDIR/
2829
[ $? -ne 0 ] && echo "$(basename $0): Failed to copy from original iso $isofile" && return 1
2930
cp $newpubkey $TMPDIR/authorized_keys
@@ -39,6 +40,7 @@ inject_into_iso() {
3940

4041
copy_priv_key() {
4142
local newprivkey=$1
43+
diff -q $newprivkey $(dirname $0)/id_rsa.cloud && return 0
4244
cp -fb $newprivkey $(dirname $0)/id_rsa.cloud && chmod 0600 $(dirname $0)/id_rsa.cloud
4345
return $?
4446
}

0 commit comments

Comments
 (0)