2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 03:32:04 +00:00

Remove trailing spaces in file xCAT-server/share/xcat/scripts/xdcpmerge.sh

This commit is contained in:
GONG Jie 2017-12-31 23:59:59 +00:00
parent 121b4cb59c
commit 2124252630

View File

@ -1,24 +1,24 @@
#!/bin/bash
# This script is used by the xdcp MERGE: function to perform the
# merge operation on the nodes for the /etc/passwd, /etc/shadow and
# merge operation on the nodes for the /etc/passwd, /etc/shadow and
# and /etc/group files. These are the only supported files for merge.
# The MERGE function is also only supported on Linux.
#First parameter is nodesyncfiledir
#The next parameter is the MERGE clause put in the following format
#The next parameter is the MERGE clause put in the following format
#mergefile1:currfile1 mergefile2:currfile2.....
#For example:
#/tmp/myusers:/etc/passwd /tmp/mypasswds:/etc/shadow /tmp/mygrps:/etc/group
#
# Check for Linux, AIX not supported
# Check for Linux, AIX not supported
if [ "$(uname -s)" != "Linux" ]; then
logger -t xcat -p local4.err "Merge: xdcp merge is only supported on Linux"
logger -t xcat -p local4.err "Merge: xdcp merge is only supported on Linux"
exit 1
fi
#this is the base path to the merge directory
nodesyncfiledir=$1
#this is the backup copy of the original current file
#this is the backup copy of the original current file
nodesyncfiledirorg="$nodesyncfiledir/org"
#this is the path to merge working files
nodesyncfiledirmerge="$nodesyncfiledir/merge"
@ -39,13 +39,13 @@ for i in $*; do
# get the file path and name to merge into, for example /etc/passwd
curfile=`echo "$i"|cut -d ':' -f 2`
# if curfile not /etc/passwd or /etc/shadow or /etc/group
# if curfile not /etc/passwd or /etc/shadow or /etc/group
# exit error
#if [ "$curfile" != "/etc/passwd" ] && [ "$curfile" != "/etc/shadow" ] && [ "$curfile" != "/etc/group" ]; then
# logger -t xcat -p local4.err "Merge: $curfile is not /etc/passwd or /etc/shadow or /etc/group. It cannot be processes."
# logger -t xcat -p local4.err "Merge: $curfile is not /etc/passwd or /etc/shadow or /etc/group. It cannot be processes."
# exit 1
#fi
# get the directory to backup the original file
#fi
# get the directory to backup the original file
curfiledir=`dirname $curfile`
curfilename=`basename $curfile`
filebackupdir="$nodesyncfiledirorg$curfiledir"
@ -53,23 +53,23 @@ for i in $*; do
filebackup="$nodesyncfiledirorg$curfile"
# now do the work
# make the necessary directories
mkdir -p $filebackupdir
# copy current to backup
mkdir -p $filebackupdir
# copy current to backup
cp -p $curfile $filebackup
# Go though the backup copy and remove duplicate lines that are
# in the merge file and create a new backup
# first get a list of duplicate lines to remove
# in the merge file and create a new backup
# first get a list of duplicate lines to remove
# based on only username: the first field in the file
cut -d: -f1 $filebackup > $filebackup.userlist
cut -d: -f1 $mergefile > $mergefile.userlist
comm -12 <(sort $filebackup.userlist | uniq) <(sort $mergefile.userlist | uniq) > $filebackup.remove
# now if there is a remove file, use it to remove the dup lines in backup
# Need to buit a command like the following with all users
#grep -v -E ^(root|bin|...) $filebackup > $filebackup.nodups
# now if there is a remove file, use it to remove the dup lines in backup
# Need to buit a command like the following with all users
#grep -v -E ^(root|bin|...) $filebackup > $filebackup.nodups
if [ -s "$filebackup.remove" ]; then
grepcmd="grep -v -E "
grepcmd="grep -v -E "
removeusers=`cat $filebackup.remove`
startlist="'^("
userlist=$startlist
@ -96,14 +96,14 @@ for i in $*; do
cat $filebackup $mergefile > $curfile
#echo "cat $filebackup $mergefile > $curfile"
fi
# now cleanup
rm $filebackup.userlist
rm $filebackup.userlist
# echo "rm $filebackup.userlist"
rm $filebackup.remove
rm $filebackup.remove
# echo "rm $filebackup.remove"
rm $mergefile.userlist
rm $mergefile.userlist
# echo "rm $mergefile.userlist"
done
exit 0