Skip to content

Commit da02f16

Browse files
Anurag AwasthiSpaceman1984
authored andcommitted
Revert "Extract systemvm.iso using bsdtar (apache#3536)" (apache#3800)
This reverts commit 8a55c93.
1 parent 7a18650 commit da02f16

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Homepage: http://www.cloudstack.org/
99

1010
Package: cloudstack-common
1111
Architecture: all
12-
Depends: ${misc:Depends}, ${python:Depends}, genisoimage, nfs-common, bsdtar
12+
Depends: ${misc:Depends}, ${python:Depends}, genisoimage, nfs-common
1313
Conflicts: cloud-scripts, cloud-utils, cloud-system-iso, cloud-console-proxy, cloud-daemonize, cloud-deps, cloud-python, cloud-setup
1414
Description: A common package which contains files which are shared by several CloudStack packages
1515

packaging/centos7/cloud.spec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ Requires: python
9090
Requires: python3
9191
Requires: python-argparse
9292
Requires: python-netaddr
93-
Requires: bsdtar
9493
Group: System Environment/Libraries
9594
%description common
9695
The Apache CloudStack files shared between agent and management server

scripts/vm/systemvm/injectkeys.sh

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# to you under the Apache License, Version 2.0 (the
77
# "License"); you may not use this file except in compliance
88
# with the License. You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing,
1313
# software distributed under the License is distributed on an
1414
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -30,31 +30,35 @@ TMPDIR=${TMP}/cloud/systemvm
3030
umask 022
3131

3232
clean_up() {
33-
rm -rf --preserve-root $MOUNTPATH
34-
}
35-
36-
backup_iso() {
37-
$SUDO cp -b ${systemvmpath} ${systemvmpath}.bak
33+
$SUDO umount $MOUNTPATH
3834
}
3935

4036
inject_into_iso() {
4137
local isofile=${systemvmpath}
4238
local newpubkey=$2
39+
local backup=${isofile}.bak
4340
local tmpiso=${TMP}/$1
4441
mkdir -p $MOUNTPATH
4542
[ ! -f $isofile ] && echo "$(basename $0): Could not find systemvm iso patch file $isofile" && return 1
46-
bsdtar -C $MOUNTPATH -xf $isofile
47-
[ $? -ne 0 ] && echo "$(basename $0): Failed to extract original iso $isofile" && clean_up && return 1
43+
$SUDO mount -o loop $isofile $MOUNTPATH
44+
[ $? -ne 0 ] && echo "$(basename $0): Failed to mount original iso $isofile" && clean_up && return 1
4845
diff -q $MOUNTPATH/authorized_keys $newpubkey &> /dev/null && clean_up && return 0
49-
backup_iso
46+
$SUDO cp -b $isofile $backup
5047
[ $? -ne 0 ] && echo "$(basename $0): Failed to backup original iso $isofile" && clean_up && return 1
51-
$SUDO cp $newpubkey $MOUNTPATH/authorized_keys
48+
rm -rf $TMPDIR
49+
mkdir -p $TMPDIR
50+
[ ! -d $TMPDIR ] && echo "$(basename $0): Could not find/create temporary dir $TMPDIR" && clean_up && return 1
51+
$SUDO cp -fr $MOUNTPATH/* $TMPDIR/
52+
[ $? -ne 0 ] && echo "$(basename $0): Failed to copy from original iso $isofile" && clean_up && return 1
53+
$SUDO cp $newpubkey $TMPDIR/authorized_keys
5254
[ $? -ne 0 ] && echo "$(basename $0): Failed to copy key $newpubkey from original iso to new iso " && clean_up && return 1
53-
mkisofs -quiet -r -o $tmpiso $MOUNTPATH
54-
[ $? -ne 0 ] && echo "$(basename $0): Failed to create new iso $tmpiso from $MOUNTPATH" && clean_up && return 1
55+
mkisofs -quiet -r -o $tmpiso $TMPDIR
56+
[ $? -ne 0 ] && echo "$(basename $0): Failed to create new iso $tmpiso from $TMPDIR" && clean_up && return 1
57+
$SUDO umount $MOUNTPATH
58+
[ $? -ne 0 ] && echo "$(basename $0): Failed to unmount old iso from $MOUNTPATH" && return 1
5559
$SUDO cp -f $tmpiso $isofile
5660
[ $? -ne 0 ] && echo "$(basename $0): Failed to overwrite old iso $isofile with $tmpiso" && return 1
57-
clean_up
61+
rm -rf $TMPDIR
5862
}
5963

6064
copy_priv_key() {
@@ -70,7 +74,7 @@ then
7074
SUDO="sudo -n "
7175
fi
7276

73-
mkdir -p $MOUNTPATH
77+
$SUDO mkdir -p $MOUNTPATH
7478

7579
[ $# -ne 3 ] && echo "Usage: $(basename $0) <new public key file> <new private key file> <systemvm iso path>" && exit 3
7680
newpubkey=$1
@@ -81,8 +85,17 @@ systemvmpath=$3
8185

8286
command -v mkisofs > /dev/null || (echo "$(basename $0): mkisofs not found, please install or ensure PATH is accurate" ; exit 4)
8387

84-
if [ ! -x "$(command -v bsdtar)" ]; then
85-
echo "bsdtar is unavailable. Skipping ssh key insertion in systemvm.iso"
88+
# if running into Docker as unprivileges, skip ssh verification as iso cannot be mounted due to missing loop device.
89+
if [ -f /.dockerenv ]; then
90+
if [ -e /dev/loop0 ]; then
91+
# it's a docker instance with privileges.
92+
inject_into_iso systemvm.iso $newpubkey
93+
[ $? -ne 0 ] && exit 5
94+
copy_priv_key $newprivkey
95+
else
96+
# this mean it's a docker instance, ssh key cannot be verify.
97+
echo "We run inside Docker, skipping ssh key insertion in systemvm.iso"
98+
fi
8699
else
87100
inject_into_iso systemvm.iso $newpubkey
88101
[ $? -ne 0 ] && exit 5

0 commit comments

Comments
 (0)