xci: scripts: build-dib-os.sh: chmod and chown files using sudo 39/44339/4
authorMarkos Chandras <mchandras@suse.de>
Thu, 5 Oct 2017 09:01:09 +0000 (10:01 +0100)
committerMarkos Chandras <mchandras@suse.de>
Thu, 5 Oct 2017 14:31:23 +0000 (15:31 +0100)
Some of the files may be owned by root so we need to ensure that
everything is reset properly. Moreover, only clean the image files
for the one we are building.

Change-Id: I45b78db6715534187f19d9f513e8288fd076cb6b
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/scripts/vm/build-dib-os.sh
xci/scripts/vm/start-new-vm.sh

index 7547d40..7688ee6 100755 (executable)
@@ -24,17 +24,21 @@ fi
 # Prepare new working directory
 dib_workdir="${XCI_CACHE_DIR:-${HOME}/.cache/opnfv_xci_deploy}/clean_vm/images"
 [[ ! -d $dib_workdir ]] && mkdir -p $dib_workdir
-chmod 777 -R $dib_workdir
 
 # Record our information
 uid=$(id -u)
 gid=$(id -g)
 
+sudo chmod 777 -R $dib_workdir
+sudo chown $uid:$gid -R $dib_workdir
+
 echo "Getting the latest docker image..."
 eval $docker_cmd pull hwoarang/docker-dib-xci:latest
 
 # Get rid of stale files
-rm -rf $dib_workdir/*.qcow2 $dib_workdir/*.sha256.txt $dib_workdir/*.d
+rm -rf $dib_workdir/${ONE_DISTRO}.qcow2 \
+       $dib_workdir/${ONE_DISTRO}.sha256.txt \
+       $dib_workdir/${ONE_DISTRO}.d
 echo "Initiating dib build..."
 eval $docker_cmd run --name ${docker_name} \
        --rm --privileged=true -e ONE_DISTRO=${ONE_DISTRO} \
index 4ad41f6..a1f4080 100755 (executable)
@@ -110,6 +110,11 @@ sudo systemctl -q start docker
 
 echo "Preparing XCI cache..."
 mkdir -p ${XCI_CACHE_DIR}/ ${XCI_CACHE_DIR}/clean_vm/images/
+# Record our information
+uid=$(id -u)
+gid=$(id -g)
+sudo chmod 777 -R $XCI_CACHE_DIR/clean_vm/images/
+sudo chown $uid:$gid -R $XCI_CACHE_DIR/clean_vm/images/
 
 if ${XCI_BUILD_CLEAN_VM_OS}; then
        echo "Building new ${OS} image..."
@@ -132,6 +137,9 @@ fi
 # Doesn't matter if we just built an image or got one from artifacts. In both
 # cases there should be a copy in the cache so copy it over.
 sudo rm -f ${BASE_PATH}/${OS}.qcow2
+# Fix perms again...
+sudo chmod 777 -R $XCI_CACHE_DIR/clean_vm/images/
+sudo chown $uid:$gid -R $XCI_CACHE_DIR/clean_vm/images/
 cp ${XCI_CACHE_DIR}/clean_vm/images/${OS}.qcow2 ${BASE_PATH}/
 declare -r OS_IMAGE_FILE=${OS}.qcow2