3

Is there any possibility to use a placeholder in the config files located in /etc/skel that is replaced by the username later?

e.g. I place ":USER:" in one config file and create a new user with the username "test". Then ":USER:" should be replaced by "test".

Thanks for your replies.

2
  • What distro? Different distros do different things.
    – womble
    Jul 13, 2012 at 9:16
  • xubuntu 12.04 is in use
    – lug
    Jul 13, 2012 at 9:20

3 Answers 3

3

Ubuntu uses adduser from Debian, and that program just does a straight up file copy from /etc/skel, so you're out of luck there. However, it does support hook scripts (look in adduser(8) for adduser.local), and you could write a little hook script that did a sed -i over some or all of the files in the newly-created home directory to do your text substitution magic.

6
  • I did cp /usr/share/doc/adduser/examples/adduser.local /usr/local/sbin/ Where in adduser.local do I have to place the search and replace code? I'm not quite familiar with perl syntax.
    – lug
    Jul 13, 2012 at 9:50
  • adduser.local doesn't have to be a Perl script.
    – womble
    Jul 13, 2012 at 10:01
  • that's great and how do I get the username parameter from adduser within the bash script?
    – lug
    Jul 13, 2012 at 10:09
  • I'm able to get the parameter by $1 but that does not have to be the username if additionally flags are used. Do I have to check each parameter if it begins with a "-"? There has to be a more comfortable solution.
    – lug
    Jul 13, 2012 at 10:22
  • 1
    From adduser(8): "The arguments passed to adduser.local are: username uid gid home-directory". Documentation is a wonderful thing.
    – womble
    Jul 13, 2012 at 10:22
0

You can make use of environment variables directly within your shell init scripts. For initialization files interpreted/used by other tools, refer to their methods.

PATH=$PATH:$HOME/bin/

... would add the user's home directory to their path (you might want to do some sanity checks such as that the directory exists first).

See "Shell Variables" within the bash(1) manpage for a list of variables defined/used by bash.

It would help if you'd clarify specifically what you're trying to do, and why.

0

I got some useraccount crash thing here, so I'm posting from a new registered account here. Sorry for that.

I Did the following: https://serverfault.com/a/407613/128083

Made it "community wiki" so everyone can add his or her idea how to do it better.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .