FIX: Change ownership of newly-created VGs 10/3710/1
authordave kormann <davek@research.att.com>
Fri, 18 Sep 2020 18:39:49 +0000 (14:39 -0400)
committerdave kormann <davek@research.att.com>
Fri, 18 Sep 2020 18:42:10 +0000 (14:42 -0400)
When creating a new volume group, allow a user/group to be specified
to own the root directory.  If no user/group is provided, use the
owner of the mountpoint or (if it doesn't exist) the current user/group.

This should fix the problem with mariadb permission problems when
installing to a vg, as opposed to the existing directory in the
image.

signed-off-by: dave korman   <davek@research.att.com>
Change-Id: Idf4418dca288a374c53fa6c180c3bdf62db10abb

roles/partfs_rootdisk/scripts/vol_mgmt.sh

index b1ac984..85214fe 100755 (executable)
 # This tool is meant to stop processes running in a given directory.
 # Evacuate its contents to a temp location.
 # Mount a given LVM to the Directory
+# optionally change ownership of the root of the LVM
 # Start those services again
 
 #arg1: Directory to evacuate
 #arg2: Volume dev path to mount
+#arg3/arg4 (optional, must provide both): owner/group of root directory of new mount
 
 exec >> /tmp/vol_mgmt_logfile
 exec 2>&1
 
-
-if [[ $# != 2 ]];then
+if [[ $# == 4 ]];then
+  evac_dir=$1
+  mount_vol_dev=$2
+  owner=$3
+  group=$4
+elif [[ $# == 2 ]]; then
+  evac_dir=$1
+  mount_vol_dev=$2
+  # they didn't provide a u/g.  use the owner of the mountpoint if
+  # it exists or our own user/group (almost certaimly root) if not.
+  owner=`stat -c '%U' ${evac_dir} 2>/dev/null || id -un`
+  group=`stat -c '%G' ${evac_dir} 2>/dev/null || id -gn`
+else
   echo "Improper number of arguments passed!!"
   exit 1
 fi
 
-evac_dir=$1
-mount_vol_dev=$2
-
 echo "Trying to mount $mount_vol_dev on $evac_dir"
 
 # Run partprobe to load new volumes
@@ -104,6 +114,8 @@ rm -rf ${evac_dir}/*
 # Mount the volume on dir
 mount $evac_dir
 
+chown ${owner}:${group} ${evac_dir}
+
 cp -rpf $tmp_dir/* ${evac_dir}/
 rm -rf $tmp_dir