开发者

PackageMaker install script for rxtx

开发者 https://www.devze.com 2022-12-26 13:47 出处:网络
I am using PackageMaker to create an installer for my application. During installation I need to run a bash script to properly install rxtx, a JNI library for serial port communication. This library n

I am using PackageMaker to create an installer for my application. During installation I need to run a bash script to properly install rxtx, a JNI library for serial port communication. This library needs to have the directory /var/lock in place with user "root" and group "uucp". The installation script also needs to add the current user to the group "uucp" for the lib to be able to write to /var/lock.

Now when I run my application installer the preinstall script is run as root. Therefore "whoami" returns root instead of the user who is actually running the installer. The result is that rxtx is not able to create lock files in /var/lock because the actual user was not added as a member to "uucp".

How can I get the user while my script is run by the installer. Or is it better to set the permissions for /var/lock to a different group maybe? Any suggestions are welcome!


#!/bin/sh

curruser=`whoami`
logger "Setting permissions for /var/lock for user $curruser!"

if [ ! -d /var/lock ]
then
  logger "Creating /var/lock!"
  sudo mkdir /var/lock
fi

sudo chgrp uucp /var/lock
sud开发者_如何学Co chmod 775 /var/lock

# MacOSX 10.5 and later use dscl
if [ `sudo dscl . -read /Groups/uucp GroupMembership | grep $curruser | wc -l` = "0" ]
then
  logger "Add user $curruser to /Groups/uucp!"
  sudo dscl . -append /Groups/uucp GroupMembership $curruser
  # to revert use:
  # sudo dscl . -delete /Groups/uucp GroupMembership $curruser
else
  logger "User already member of group uucp!"
fi


Instead of

curruser=`whoami`

I am now using

curruser=`users`

which gets me a list of the currently logged in users wich is partly fixing the problem. Remaining issues are:

  • In case there really are two or more users logged in to the Mac at the moment of installation, my script will fail to add the users to group uucp.

  • In case another user on the Mac wants to run my application it will fail again because this user was not added to group uucp.

Maybe someone has got a hint on those issues?

0

精彩评论

暂无评论...
验证码 换一张
取 消