There are two parts to the answer to your question. First you need to add a post-install part in your Makefile. Once you have that, you can script anything you wish, like adding users and setting ownerships. The package for Tor has a nice example of how to do this. I have pasted the relevant part of the Tor Makefile here, which I will comment on afterwards:
define Package/tor/postinst
#!/bin/sh
# # check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
# create copies of passwd and group, if we use squashfs
rootfs=`mount |awk '/root/ { print $$5 }'`
if [ "$$rootfs" = "squashfs" ]; then
if [ -h /etc/group ]; then
rm /etc/group
cp /rom/etc/group /etc/group
fi
if [ -h /etc/passwd ]; then
rm /etc/passwd
cp /rom/etc/passwd /etc/passwd
fi
fi
fi
echo ""
# add group if it doesn't exist
if [ -z "$$(grep ^\\$${name}: $${IPKG_INSTROOT}/etc/group)" ]; then
echo "adding group $$name to /etc/group"
echo "$${name}:x:$${id}:" >> $${IPKG_INSTROOT}/etc/group
fi
# add user if it doesn't exist
if [ -z "$$(grep ^\\$${name}: $${IPKG_INSTROOT}/etc/passwd)" ]; then
echo "adding user $name to /etc/passwd"
echo "$${name}:x:$${id}:$${id}:$${name}:/tmp/.$${name}:/bin/false" >> $${IPKG_INSTROOT}/etc/passwd
fi
endef
So, let's analyze this briefly:
- A post install script is defined by "define Package/tor/postinst" and ends with "endef".
- The text between these two delimiters is the actual script that will be run; notice the #!/bin/sh at the beginning of the script.
- Very important: Postinst scripts can be executed twice; once during build time and a second time during installation on the OpenWRT device. This is somewhat logical because the build process is also an installation process; it installs the application you are compiling into a package. Because of this double execution, you have to make your script explicitly check in what phase it is in: Build or Install. This is what the "if [ -z "$${IPKG_INSTROOT}" ]" part is for. It checks to see if the variable IPKG_INSTROOT is zero-length. If so, then it assumes that it is not in the build phase, but running on a 'real' system. Once this has been confirmed, you can run all sorts of actions, limited only by your imagination.
- All variables in your script should have double-string characters ($$) instead of a single. This is to tell "make" not to interpret the value as a variable, but to just ignore the string and replace the $$ by a single $.
- During the build process, the contents of the postinst section will be copied to build_dir/<architecture>/<package-name>/ipkg/<module-name>/CONTROL/postinst. This is good to know, because now you can check the postinst script after you have built your package. One of the things you can check for, is to see if you accidentally forgot to add double $ characters, for example. If so, then you know your script is broken.
- The above rules also apply to preinst , prerm and postrm scripts.
In the example script above, you can see that it checks for the existence of a certain group and user and then adds these to their respective files if they do not exist. That should answer your question on how to add a user. Your next question "how to change ownership of files" is now a no-brainer. Just use chown in the postinst script.
As to your question: "How would I add a line to a certain config-file?" That is more a general scripting related question than an OpenWRT specific question. You could use the command "patch", but that command is usually not installed on OpenWRT or included in Busybox. So you will have to be creative. This seems to be related to your question: http://www.unix.com/shell-programming-s … -line.html
Hope that helps.