Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[S] Proper way of managing a new regular user under chroot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
etnull
Guru
Guru


Joined: 26 Mar 2019
Posts: 464
Location: Russia

PostPosted: Thu Oct 15, 2020 3:39 pm    Post subject: [S] Proper way of managing a new regular user under chroot Reply with quote

At the end of Gentoo install you usually create a regular user, assign groups, passwords and make other small finishing edits. Creating user under chroot is not a problem, but making edits for that user turned out to be more tricky than I expected, I can't just edit files in ~/ of the regular user from root, it will mess up ownership of these files, so I did all my edits with something like this:
Code:
runuser -l *USER* -c '*command*'

I created basic folder structure:
Code:
runuser -l *USER* -c 'mkdir ~/{desktop,documents,downloads,music,pictures,public,videos}'

edited .bash_profile, .xinitrc and .Xresources in similar way. After all of that I rebooted, logged-in as that user, but all my edits were gone... no folders, .bash_profile and the rest were like if they were copied from some default location. Also during login I noticed that the last login was mentioned as pts/0, so I assume for the first login of a user these files are copied from somewhere to make defaults?.. At some point I'm going to make an installation script and I need to figure out this user creation step to properly finish the install.


Last edited by etnull on Thu Oct 15, 2020 9:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
sabayonino
l33t
l33t


Joined: 03 Jan 2012
Posts: 828

PostPosted: Thu Oct 15, 2020 9:20 pm    Post subject: Reply with quote

You can run "chroot" commands inside your script without any prompt

Code:


#/bin/bash
<your script part>

# Entering in your chroot environment without any prompt : just execute all commands between EOF strings
cat << EOF | chroot ${ROOT} /bin/bash
<do anything as gentoo wiki explain or according your needs>
EOF

<continue your script>


Where ${ROOT} is your gentoo mountpoint (/mnt/gentoo or something else)

so :
Code:


#/bin/bash
<start your script here>

# Now you can run commands inside your chroot
# Entering in your chroot environment without any prompt : just execute all commands between EOF string
cat << EOF | chroot ${ROOT} /bin/bash
mkdir -p /home/<user>/{Desktop,Downloads,...}
# change the <user> permisisions
# <do something else : emerge , install a program , remove directories and so on>
EOF
# The script exit from chroot after last comm.

<continue your script>


Cheers
_________________
BOINC ed il calcolo distribuito

My LRecoverySystem Repo
Back to top
View user's profile Send private message
etnull
Guru
Guru


Joined: 26 Mar 2019
Posts: 464
Location: Russia

PostPosted: Thu Oct 15, 2020 9:44 pm    Post subject: Reply with quote

Using "su - *USER*" to swith to that user and execute everything uder it was the proper way, or at least it was persistent after I logged in properly with that user. I don't know what was wrong with runuser commands, but those were my findings. I'm not yet writing the script, not sure if it gonna work in that case, but that's for later to discover.
Back to top
View user's profile Send private message
sabayonino
l33t
l33t


Joined: 03 Jan 2012
Posts: 828

PostPosted: Fri Oct 16, 2020 6:39 pm    Post subject: Reply with quote

I think you cannot run "runuser" or similar ìcause many services are not running in chroot enviroment
_________________
BOINC ed il calcolo distribuito

My LRecoverySystem Repo
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum