thiagoojack/packettracer-fedora

Postinst script from .deb breaks /etc/profile lines ending with backslashes

Closed this issue · 0 comments

ignapk commented

Fedora's /etc/profile has lines that end with backslashes, and this part of the postinst script from the cisco packet tracer deb package corrupts the /etc/profile:

PROFILE="/etc/profile" 

# error exit if file does not exist or unreadable
if [ ! -f $PROFILE ]; then
   exit 1
elif [ ! -r $PROFILE ]; then
   exit 2
fi

# read contents
CONTENTS=""
EXPORT_PT8_EXISTS=0
PT8HOME_EXISTS=0
PT8HOME_FOUND=0
exec 3<&0
exec 0<$PROFILE
while IFS= read -r line
do
  
  # replace existing entries
  PT8HOME_FOUND=`expr match "$line" 'PT8HOME'`
  if [ $PT8HOME_FOUND -gt 0 ]; then
	line="PT8HOME=$PTDIR"
        PT8HOME_EXISTS=1
  fi

  # check for export statement
  if [ $EXPORT_PT8_EXISTS -eq 0 ]; then
      EXPORT_PT8_EXISTS=`expr match "$line" 'export PT8HOME'`
  fi

  #append the line to the contents
  CONTENTS="$CONTENTS\n$line"
done
exec 0<&3

if [ $PT8HOME_EXISTS -eq 0 ]; then
  CONTENTS="$CONTENTS\nPT8HOME=$PTDIR"
fi

if [ $EXPORT_PT8_EXISTS -eq 0 ]; then
  CONTENTS="$CONTENTS\nexport PT8HOME"
fi

sudo echo -e "$CONTENTS" > /etc/profile

Specifically line

CONTENTS="$CONTENTS\n$line"

Because the $CONTENTS ends with a backslash, it escapes the backslash from the newline symbol and as a result we get single letter "n" instead of a new line. This in turn results in following error when opening terminal session:

bash: n: command not found…