Home > OS >  bash install with group that does not exist
bash install with group that does not exist

Time:01-05

I am writing a linux installation script, where I boot into a RAM disk image of linux and then install the new version of linux to flash on a mount.

The RAM disk (running) version of linux does not have a user group called "bob", but the image I have installed on the mounted partition does.

The installation completes, but one of the last steps I want to do is create a couple of folders that are owned by the group "bob"

So I use do something like:

# Note: /tmp/test is not the actual mount point - this is just an example
install -o user -g bob -d /tmp/test
install: invalid group ‘bob’

My current running version of linux does not have the group bob, but I know that the target folder I am creating does have this group - when I reboot into that image.

Is there a way to do this? The only thing I can think of is to create the group "bob" temporarily, do the install command and then delete it again.

CodePudding user response:

Extract bob's GID from the /etc/group file in the mounted image, and use that.

I think you also need to do the same thing for the UID if user, since that may not be the same as in the host system.

uid=$(awk -F: '$1 == "user" {print $3}' /tmp/test/etc/passwd)
gid=$(awk -F: '$1 == "bob" {print $3}' /tmp/test/etc/group)
if [ -n "$uid" && -n "$gid" ]
then
    install -o "$uid" -g "$gid" -d /tmp/test
fi
  • Related