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.

lug
  • 33
  • 3

3 Answers3

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.

womble
  • 95,029
  • 29
  • 173
  • 228
  • 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 '12 at 09:50
  • `adduser.local` doesn't have to be a Perl script. – womble Jul 13 '12 at 10:01
  • that's great and how do I get the username parameter from adduser within the bash script? – lug Jul 13 '12 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 '12 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 '12 at 10:22
  • thanks a lot, your made my day read the documentation too but was irritated because i tested `adduser.local -n username` - sorry for that ;) – lug Jul 13 '12 at 10:28
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.

lug
  • 41
  • 1
  • 8