Преглед изворни кода

update vbuilder.sh.in: defined some functions for mounting file systems

git-svn-id: http://trac.vinelinux.org/repos/projects/vbootstrap/trunk@454 ec354946-7b23-47d6-9f5a-488ba84defc7
munepi пре 15 година
родитељ
комит
823b061ce0
1 измењених фајлова са 101 додато и 76 уклоњено
  1. 101 76
      vbuilder.sh.in

+ 101 - 76
vbuilder.sh.in

@@ -302,66 +302,91 @@ apt-get-update(){
     esac
 }
 
-## mount /home
-mount_home(){
+## mount-chroot {|--umount} [file system|name]
+## support file systems: /home /tmp /sys /proc /dev/shm /dev/pts /dev
+## support name: vfs chache_dir
+## NOTE: /tmp needs for applications which use X
+##       vfs is virtual file systems
+##       cache_dir is ${CACHE_DIR} to ${ARCHIVES_DIR}
+mount-chroot(){
     if [ "$1" = "--umount" ]; then
-	[ -d ${BUILD_ROOT}/home ] || return 1
-	[ -z "$(mount | grep ${BUILD_ROOT}/home)" ] || \
-    	    umount ${BUILD_ROOT}/home
+	mount-chroot-umount $2 || return 1
     else
-	[ -d ${BUILD_ROOT}/home ] || mkdir -p ${BUILD_ROOT}/home
-	[ -z "$(mount | grep ${BUILD_ROOT}/home)" ] && \
-	    mount -o rbind /home ${BUILD_ROOT}/home
+	mount-chroot-mount $1 || return 1
     fi
+    return 0
 }
 
-## mount /tmp for applications which use X
-mount_tmp(){
-    if [ "$1" = "--umount" ]; then
-	[ -d ${BUILD_ROOT}/tmp ] || return 1
-	[ -z "$(mount | grep ${BUILD_ROOT}/tmp)" ] || \
-    	    umount ${BUILD_ROOT}/tmp
-    else
-	[ -d ${BUILD_ROOT}/tmp ] || mkdir -p ${BUILD_ROOT}/tmp
-	[ -z "$(mount | grep ${BUILD_ROOT}/tmp)" ] && \
-	    mount --bind /tmp ${BUILD_ROOT}/tmp
-    fi
+## mount-chroot-umount [file system|name]
+mount-chroot-umount(){
+    local fs=$1
+    case $fs in
+	/home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
+	    [ -d ${BUILD_ROOT}${fs} ] || return 1
+	    [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] || \
+    		umount ${BUILD_ROOT}${fs}
+	    return 0
+	    ;;
+	vfs)
+	    # for dir in /sys /proc /dev/shm /dev/pts /dev; do
+	    # 	mount-chroot-umount ${dir} || return 1
+	    # done
+	    [ -d ${BUILD_ROOT}/proc ] || return 1
+	    [ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
+		umount ${BUILD_ROOT}/proc
+	    return 0
+	    ;;
+	cache_dir)
+	    [ -d ${ARCHIVES_DIR} ] || return 1
+	    [ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
+    		umount ${ARCHIVES_DIR}
+	    return 0
+	    ;;
+	*)
+	    echo mount-chroot-umount: unknown file system $fs
+	    exit 1
+	    ;;
+    esac
 }
 
-## mount virtual file systems
-mount_vfs(){
-    if [ "$1" = "--umount" ]; then
-	# for dir in /sys /proc /dev/shm /dev/pts /dev; do
-	# [ -z "$(mount | grep ${BUILD_ROOT}${dir})" ] || \
-	# 	umount ${BUILD_ROOT}${dir}
-	# done
-	[ -d ${BUILD_ROOT}/proc ] || return 1
-	[ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] || \
-	    umount ${BUILD_ROOT}/proc
-    else
-	# for dir in /dev /dev/pts /dev/shm /proc /sys; do
-	# 	[ -d ${BUILD_ROOT}${dir} ] || mkdir -p ${BUILD_ROOT}${dir}
-	# 	mount --bind ${dir} ${BUILD_ROOT}${dir}
-	# done
-	[ -d ${BUILD_ROOT}/proc ] || mkdir -p ${BUILD_ROOT}/proc
-	[ -z "$(mount | grep ${BUILD_ROOT}/proc)" ] && \
-	    mount --bind /proc ${BUILD_ROOT}/proc
-    fi
-}
+## mount-chroot-mount [file system|name]
+mount-chroot-mount(){
+    local fs=$1
+    local mnt_opts=""
 
-## mount ${CACHE_DIR} to ${ARCHIVES_DIR}
-mount_cache_dir(){
-    if [ "$1" = "--umount" ]; then
-	[ -d ${ARCHIVES_DIR} ] || return 1
-	[ -z "$(mount | grep ${ARCHIVES_DIR})" ] || \
-    	    umount ${ARCHIVES_DIR}
-    else
-	[ -d ${CACHE_DIR} ] || mkdir -p ${CACHE_DIR}
-	[ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
-	[ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
-	    mount --bind ${CACHE_DIR} ${ARCHIVES_DIR}
-	[ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
-    fi
+    case $fs in
+	/home)
+	    mnt_opts="-o rbind"
+	    ;;
+	*)
+	    mnt_opts="--bind"
+	    ;;
+    esac
+
+    case $fs in
+	/home|/tmp|/sys|/proc|/dev/shm|/dev/pts|/dev)
+	    [ -d ${BUILD_ROOT}${fs} ] || mkdir -p ${BUILD_ROOT}${fs}
+	    [ -z "$(mount | grep ${BUILD_ROOT}${fs})" ] && \
+		mount ${mnt_opts} ${fs} ${BUILD_ROOT}${fs}
+	    return 0
+	    ;;
+	vfs)
+	    # for dir in /dev /dev/pts /dev/shm /proc /sys; do
+	    # 	mount-chroot-mount ${dir} || return 1
+	    # done
+	    mount-chroot-mount /proc || return 1
+	    return 0
+	    ;;
+	cache_dir)
+	    [ -d ${CACHE_DIR} ] || mkdir -p ${CACHE_DIR}
+	    [ -d ${ARCHIVES_DIR} ] || mkdir -p ${ARCHIVES_DIR}
+	    [ -z "$(mount | grep ${ARCHIVES_DIR})" ] && \
+		mount ${mnt_opts} ${CACHE_DIR} ${ARCHIVES_DIR}
+	    [ -d ${ARCHIVES_DIR}/partial ] || mkdir -p ${ARCHIVES_DIR}/partial
+	    return 0
+	    ;;
+    esac
+   
 }
 
 
@@ -370,10 +395,10 @@ mount_cache_dir(){
 Clean(){
     setup-vbootstrap
 
-    # mount_home --umount
-    # mount_tmp --umount
-    mount_vfs --umount
-    mount_cache_dir --umount
+    # mount-chroot --umount /home
+    # mount-chroot --umount /tmp
+    mount-chroot --umount vfs
+    mount-chroot --umount cache_dir
     apt-get-update --host
 
     if [ -d ${BUILD_ROOT} ]; then
@@ -401,10 +426,10 @@ Build(){
 	/usr/sbin/vbootstrap ${VERSION} ${BUILD_ROOT}
     fi
 
-    mount_cache_dir
-    mount_vfs
-    # mount_tmp
-    # mount_home
+    mount-chroot cache_dir
+    mount-chroot vfs
+    # mount-chroot /tmp
+    # mount-chroot /home
 
     $__chroot_sh 'apt-get update && apt-get -y dist-upgrade'
 
@@ -435,10 +460,10 @@ Build(){
 	$__chroot_sh "sed -i -e 's/^%_topdir/#%_topdir/' /home/${BUILD_USER}/.rpmmacros"
     fi
 
-    # mount_home --umount
-    # mount_tmp --umount
-    mount_vfs --umount
-    mount_cache_dir --umount
+    # mount-chroot --umount /home
+    # mount-chroot --umount /tmp
+    mount-chroot --umount vfs
+    mount-chroot --umount cache_dir
     apt-get-update --host
 
     echo "Making a build farm for ${VERSION} done."
@@ -446,8 +471,8 @@ Build(){
 
 RPM_Remove(){
     setup-vbootstrap-rpm
-    mount_cache_dir
-    mount_vfs
+    mount-chroot cache_dir
+    mount-chroot vfs
 
     if [ -f $RPM_PKG ]; then
 	Msg_NotPackageName_$LOCALE
@@ -455,28 +480,28 @@ RPM_Remove(){
     fi
     $__chroot_sh "apt-get -y remove $BASE_RPM_PKG"
 
-    mount_vfs --umount
-    mount_cache_dir --umount
+    mount-chroot --umount vfs
+    mount-chroot --umount cache_dir
     apt-get-update --host
 }
 
 RPM_Install(){
     setup-vbootstrap-rpm
-    mount_cache_dir
-    mount_vfs
+    mount-chroot cache_dir
+    mount-chroot vfs
     apt-get-update --chroot
 
     $__chroot_sh "cd ${BUILD_DIR} && apt-get -y install $BASE_RPM_PKG"
 
-    mount_vfs --umount
-    mount_cache_dir --umount
+    mount-chroot --umount vfs
+    mount-chroot --umount cache_dir
     apt-get-update --host
 }
 
 RPM_Build(){
     setup-vbootstrap-rpm
-    mount_cache_dir
-    mount_vfs
+    mount-chroot cache_dir
+    mount-chroot vfs
 
     if [ ! -f $RPM_PKG ]; then
 	Msg_NotSourceRPM_$LOCALE
@@ -514,8 +539,8 @@ RPM_Build(){
 	fi
     done
 
-    mount_vfs --umount
-    mount_cache_dir --umount
+    mount-chroot --umount vfs
+    mount-chroot --umount cache_dir
     apt-get-update --host
 
     echo "done."