Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
What distro? Different distros do different things. –  womble Jul 13 '12 at 9:16
    
xubuntu 12.04 is in use –  lug Jul 13 '12 at 9:20
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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 9: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
show 1 more comment

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.

share|improve this answer
add comment

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

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

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.