Browse code

Unbind repo dir if necessary.

Change-Id: Ib751f6e2e2f57efc66de15e8cc7c154d74d37dde
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/3172
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Bo Gan <ganb@vmware.com>

xiaolin-vmware authored on 2017/07/07 06:45:50
Showing 2 changed files
... ...
@@ -291,6 +291,13 @@ class Installer(object):
291 291
         if subprocess.call(['mkdir', '-p', rpm_cache_dir]) != 0 or subprocess.call(['mount', '--bind', self.rpm_path, rpm_cache_dir]) != 0:
292 292
             modules.commons.log(modules.commons.LOG_ERROR, "Fail to bind cache rpms")
293 293
             self.exit_gracefully(None, None)
294
+    def unbind_repo_dir(self):
295
+        rpm_cache_dir = self.photon_root + '/cache/tdnf/photon-iso/rpms'
296
+        if self.rpm_path.startswith("https://") or self.rpm_path.startswith("http://"):
297
+            return
298
+        if subprocess.call(['umount', rpm_cache_dir]) != 0  or subprocess.call(['rm', '-rf', rpm_cache_dir]) != 0:
299
+            modules.commons.log(modules.commons.LOG_ERROR, "Fail to unbind cache rpms")
300
+            self.exit_gracefully(None, None)
294 301
 
295 302
     def update_fstab(self):
296 303
         fstab_file = open(os.path.join(self.photon_root, "etc/fstab"), "w")
... ...
@@ -373,6 +380,7 @@ class Installer(object):
373 373
             # remove the installer directory
374 374
             process = subprocess.Popen(['rm', '-rf', os.path.join(self.photon_root, "installer")], stdout=self.output)
375 375
             retval = process.wait()
376
+            self.unbind_repo_dir()
376 377
             # Disable the swap file
377 378
             process = subprocess.Popen(['swapoff', '-a'], stdout=self.output)
378 379
             retval = process.wait()
... ...
@@ -6,65 +6,68 @@
6 6
 #      Author:  mbassiouny@vmware.com           #
7 7
 #     Options:                                  #
8 8
 #################################################
9
-#	Overview
10
-#		Preparing the system to install photon
11
-#	End
9
+#   Overview
10
+#       Preparing the system to install photon
11
+#   End
12 12
 #
13
-set -o errexit		# exit if error...insurance ;
14
-set -o nounset		# exit if variable not initalized
15
-set +h			# disable hashall
13
+set -o errexit      # exit if error...insurance ;
14
+set -o nounset      # exit if variable not initalized
15
+set +h          # disable hashall
16 16
 source config.inc
17 17
 source function.inc
18
-PRGNAME=${0##*/}	# script name minus the path
18
+PRGNAME=${0##*/}    # script name minus the path
19 19
 
20
-LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"	#	set log file name
21
-#LOGFILE=/dev/null		#	uncomment to disable log file
20
+LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"    #   set log file name
21
+#LOGFILE=/dev/null      #   uncomment to disable log file
22 22
 
23
-[ ${EUID} -eq 0 ] 	|| fail "${PRGNAME}: Need to be root user: FAILURE"
24
-[ -z ${BUILDROOT} ]	&& fail "${PRGNAME}: Build root not set: FAILURE"
23
+[ ${EUID} -eq 0 ]   || fail "${PRGNAME}: Need to be root user: FAILURE"
24
+[ -z ${BUILDROOT} ] && fail "${PRGNAME}: Build root not set: FAILURE"
25 25
 
26
-if mountpoint ${BUILDROOT}/run	>/dev/null 2>&1; then umount ${BUILDROOT}/run; fi
27
-if mountpoint ${BUILDROOT}/sys	>/dev/null 2>&1; then umount ${BUILDROOT}/sys; fi
28
-if mountpoint ${BUILDROOT}/proc	>/dev/null 2>&1; then umount ${BUILDROOT}/proc; fi
29
-if mountpoint ${BUILDROOT}/dev/pts	>/dev/null 2>&1; then umount ${BUILDROOT}/dev/pts; fi
30
-if mountpoint ${BUILDROOT}/dev	>/dev/null 2>&1; then umount ${BUILDROOT}/dev; fi
31
-[ ${EUID} -eq 0 ]	|| fail "${PRGNAME}: Need to be root user: FAILURE"
26
+if mountpoint ${BUILDROOT}/run  >/dev/null 2>&1; then umount ${BUILDROOT}/run; fi
27
+if mountpoint ${BUILDROOT}/sys  >/dev/null 2>&1; then umount ${BUILDROOT}/sys; fi
28
+if mountpoint ${BUILDROOT}/proc >/dev/null 2>&1; then umount ${BUILDROOT}/proc; fi
29
+if mountpoint ${BUILDROOT}/dev/pts  >/dev/null 2>&1; then umount ${BUILDROOT}/dev/pts; fi
30
+if mountpoint ${BUILDROOT}/dev  >/dev/null 2>&1; then umount ${BUILDROOT}/dev; fi
31
+[ ${EUID} -eq 0 ]   || fail "${PRGNAME}: Need to be root user: FAILURE"
32 32
 
33 33
 cd ${BUILDROOT} || fail "${PRGNAME}: Change directory: ${BUILDROOT}: FAILURE"
34 34
 
35 35
 #
36
-#	Setup the filesystem for chapter 06
36
+#   Setup the filesystem for chapter 06
37 37
 #
38
-if [[	$# -gt 0 ]] && [[ $1 == 'install' ]]; then
39
-	mkdir -p ${BUILDROOT}/var/lib/rpm
40
-	mkdir -p ${BUILDROOT}/cache/tdnf
41
-	#Setup the disk
42
-	dd if=/dev/zero of=${BUILDROOT}/cache/swapfile bs=1M count=64
38
+if [[   $# -gt 0 ]] && [[ $1 == 'install' ]]; then
39
+    mkdir -p ${BUILDROOT}/var/lib/rpm
40
+    mkdir -p ${BUILDROOT}/cache/tdnf
41
+    #Setup the disk
42
+    dd if=/dev/zero of=${BUILDROOT}/cache/swapfile bs=1M count=64
43
+    chmod 600 ${BUILDROOT}/cache/swapfile
43 44
     mkswap -v1 ${BUILDROOT}/cache/swapfile
44 45
     swapon ${BUILDROOT}/cache/swapfile
45
-	rpm   --root ${BUILDROOT} --initdb
46
+    rpm   --root ${BUILDROOT} --initdb
46 47
     tdnf install filesystem --installroot ${BUILDROOT} --nogpgcheck --assumeyes
47 48
 else
48
-	RPMPKG="$(find RPMS -name 'filesystem-[0-9]*.rpm' -print)"
49
-	[ -z ${RPMPKG} ] && fail "	Filesystem rpm package missing: Can not continue"
50
-	run_command "	Installing filesystem" "rpm -Uvh --nodeps --root ${BUILDROOT} --dbpath /var/lib/rpm ${RPMPKG}" "${LOGFILE}"
49
+    RPMPKG="$(find RPMS -name 'filesystem-[0-9]*.rpm' -print)"
50
+    [ -z ${RPMPKG} ] && fail "  Filesystem rpm package missing: Can not continue"
51
+    run_command "   Installing filesystem" "rpm -Uvh --nodeps --root ${BUILDROOT} --dbpath /var/lib/rpm ${RPMPKG}" "${LOGFILE}"
51 52
 fi
52 53
  
53
-# 	Ommited in the filesystem.spec file - not needed for booting
54
-[ -e ${BUILDROOT}/dev/console ]	|| mknod -m 600 ${BUILDROOT}/dev/console c 5 1
54
+#   Ommited in the filesystem.spec file - not needed for booting
55
+[ -e ${BUILDROOT}/dev/console ] || mknod -m 600 ${BUILDROOT}/dev/console c 5 1
55 56
 [ -e ${BUILDROOT}/dev/null ]    || mknod -m 666 ${BUILDROOT}/dev/null c 1 3
56 57
 [ -e ${BUILDROOT}/dev/random ]  || mknod -m 444 ${BUILDROOT}/dev/random c 1 8
57 58
 [ -e ${BUILDROOT}/dev/urandom ] || mknod -m 444 ${BUILDROOT}/dev/urandom c 1 9
58 59
 
59
-chown -R 0:0 ${BUILDROOT}/*	|| :
60
+if [[   $# -eq 0 ]] || [[ $1 != 'install' ]]; then
61
+    chown -R 0:0 ${BUILDROOT}/* || :
62
+fi
60 63
 
61 64
 #
62
-#	Mount kernel filesystem
65
+#   Mount kernel filesystem
63 66
 #
64
-if ! mountpoint ${BUILDROOT}/dev	>/dev/null 2>&1; then mount --bind /dev ${BUILDROOT}/dev; fi
65
-if ! mountpoint ${BUILDROOT}/dev/pts	>/dev/null 2>&1; then mount -t devpts devpts ${BUILDROOT}/dev/pts -o gid=5,mode=620; fi
66
-if ! mountpoint ${BUILDROOT}/proc	>/dev/null 2>&1; then mount -t proc proc ${BUILDROOT}/proc; fi
67
-if ! mountpoint ${BUILDROOT}/sys 	>/dev/null 2>&1; then mount -t sysfs sysfs ${BUILDROOT}/sys; fi
68
-if ! mountpoint ${BUILDROOT}/run	>/dev/null 2>&1; then mount -t tmpfs tmpfs ${BUILDROOT}/run; fi
69
-if [ -h ${BUILDROOT}/dev/shm ];			 then mkdir -pv ${BUILDROOT}/$(readlink ${BUILDROOT}/dev/shm); fi
67
+if ! mountpoint ${BUILDROOT}/dev    >/dev/null 2>&1; then mount --bind /dev ${BUILDROOT}/dev; fi
68
+if ! mountpoint ${BUILDROOT}/dev/pts    >/dev/null 2>&1; then mount -t devpts devpts ${BUILDROOT}/dev/pts -o gid=5,mode=620; fi
69
+if ! mountpoint ${BUILDROOT}/proc   >/dev/null 2>&1; then mount -t proc proc ${BUILDROOT}/proc; fi
70
+if ! mountpoint ${BUILDROOT}/sys    >/dev/null 2>&1; then mount -t sysfs sysfs ${BUILDROOT}/sys; fi
71
+if ! mountpoint ${BUILDROOT}/run    >/dev/null 2>&1; then mount -t tmpfs tmpfs ${BUILDROOT}/run; fi
72
+if [ -h ${BUILDROOT}/dev/shm ];          then mkdir -pv ${BUILDROOT}/$(readlink ${BUILDROOT}/dev/shm); fi
70 73
 exit 0