Changeset 1038

Show
Ignore:
Timestamp:
07/27/06 21:52:05 (2 years ago)
Author:
archaic
Message:

Updated: starting-and-stopping-dbus-with-kdm.txt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/starting-and-stopping-dbus-with-kdm.txt

    r1017 r1038  
    11AUTHOR: Stef Bon <stef at bononline dot nl> 
    22 
    3 DATE: 2006-01-16 
     3DATE: 2006-07-18 
    44 
    55LICENSE: GNU Free Documentation License Version 1.2 
     
    4646 
    4747The construction with kdm I'm using here is ideal for this. One script in the startup directory to 
    48 start the sessiondaemon for a user, running with the privileges of that user, and one in the reset directory an other script has to stop that daemon. 
     48start the sessiondaemon for a user, running with the privileges of that user, and one in the reset  
     49directory an other script has to stop that daemon. 
    4950 
    5051But is not so simple as that. Some variables (DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID) have to  
     
    6566Bash is also started by "kdm", and the files /etc/profile and ~/.bash_profile are sourced. 
    6667 
    67 How should the dbus environmentvariables should be made available, or where should the file containing 
    68 the dbusvariables be sourced? Let's call this file dbus-bash.sh. 
    69  
    70 The dbus-bash.sh can't go in the /etc/profile.d directory and the /etc/profile file, because it differs for every user. 
    71 It should go in the ~/.bash_profile file, by appending or something simular. That is not only  
    72 complicated at startup, but also at reset. Then it has to be removed again. 
    73  
    74 There is no other place in BLFS/LFS at this moment to put this file. 
    75 That's why I suggest the creating of a new directory (~/.profile.d) containing files which are  
    76 sourced when a BASH session is starts for that user. 
    77 These files are exactly equivalent to those in /etc/profile.d, but contain variables that are not the same  
    78 for every user. 
    79  
    80  
    81                      global             user 
    82                  ------------------------------ 
    83  
    84                  /etc/bashrc          ~/.bashrc 
    85                  /etc/profile         ~/.bash_profile 
    86                  /etc/profile.d       ~/.profile.d 
    87  
    88  
    89 By adding the following code to the $HOME/.bash_profile at the end of it any script with the .sh extension 
    90 will be sourced for this user only: 
    91  
    92 -- snip -- 
    93  
    94 for script in $HOME/.profile.d/*.sh ; do 
    95         if [ -x $script ]; then 
    96                 . $script 
    97         fi 
    98 done 
    99  
    100 -- snip -- 
    101  
    102 Now create as a user in his/her homedirectory: 
    103  
    104 mkdir $HOME/.profile.d 
    105  
     68My idea is to store the output of the command 
     69 
     70dbus-launch --auto-syntax  
     71 
     72in the file 
     73 
     74$HOME/.dbus-session 
     75 
     76This file is "sourced" when bash start. This happens not automatically, but you will have to add the following script to /etc/profile.d : 
     77 
     78cat >> dbus-session.sh << "EOF" 
     79 
     80if [ -f $HOME/.dbus-session ]; then 
     81 
     82        . $HOME/.dbus-session 
     83 
     84fi; 
     85EOF 
     86 
     87This way, the environment variables are made available when Bash starts. 
    10688 
    10789 
     
    124106 
    125107userid=$1 
    126 userproperties=$(getent passwd | grep -E "^$userid") 
     108userproperties=$(getent passwd | grep -m 1 -E "^$userid") 
    127109homedir=$(echo $userproperties | cut -d ":" -f 6); 
    128110gidnr=$(echo $userproperties | cut -d ":" -f 4); 
     
    130112 
    131113 
    132 if [ -d $homedir/.profile.d ]; then 
    133          
     114if [ -d $homedir ]; then 
     115         
     116        # should there be a check dbus-launch is already running for this user? 
     117 
    134118        if [ $(id -u) -eq 0 ]; then 
    135             sudo -u $userid -H /bin/sh -c "dbus-launch --auto-syntax > $homedir/.profile.d/dbus-bash.sh
     119            sudo -u $userid -H /bin/sh -c "dbus-launch --auto-syntax > $homedir/.dbus-session
    136120            retcode=$? 
    137             chown $uidnr:$gidnr $homedir/.profile.d/dbus-bash.sh 
    138             chmod u+x $homedir/.profile.d/dbus-bash.sh 
     121            chown $uidnr:$gidnr $homedir/.dbus-session 
     122            chmod u+x $homedir/.dbus-session 
    139123        elif [ $(id -u) -eq $uidnr ]; then  
    140             dbus-launch --auto-syntax > $homedir/.profile.d/dbus-bash.sh 
     124            dbus-launch --auto-syntax > $homedir/.dbus-session 
    141125            retcode=$? 
    142             chmod u+x $homedir/.profile.d/dbus-bash.sh 
     126            chmod u+x $homedir/.dbus-session 
    143127        fi 
    144128 
     
    153137 
    154138This script, executed by KDM at startup will start the dbus session daemon for this user,  
    155 and will create a dbus-bash.sh script in the .profile.d directory of this user containing  
     139and will create the .dbus-session file in the homedirectory of this user, containing 
    156140all the dbusvariables. 
    157141 
     
    160144As you can see, I've split the start of dbus up into two parts: 
    161145- dbus-kdm.sh, started when a (kdm)session starts, should be run once 
    162 - dbus-bash.sh, sourced when a (bash)session starts, could be sourced multiple times 
     146- .dbus-session, sourced when a (bash)session starts, could be sourced multiple times 
    163147 
    164148Futher, I use the --auto-syntax parameter, where I assume Bash is used. So I could 
     
    187171 
    188172userid=$1 
    189 userproperties=$(getent passwd | grep -E "^$userid") 
     173userproperties=$(getent passwd | grep -m 1 -E "^$userid") 
    190174homedir=$(echo $userproperties | cut -d ":" -f 6); 
    191175gidnr=$(echo $userproperties | cut -d ":" -f 4); 
    192176uidnr=$(echo $userproperties | cut -d ":" -f 3); 
    193177         
    194 if [ -f $homedir/.profile.d/dbus-bash.sh ]; then 
    195          
    196         . $homedir/.profile.d/dbus-bash.sh 
     178if [ -f $homedir/.dbus-session ]; then 
     179         
     180        . $homedir/.dbus-session 
    197181         
    198182        if [ -n "$DBUS_SESSION_BUS_PID" ]; then 
     
    200184                    sudo -u $userid -H /bin/sh -c "kill $DBUS_SESSION_BUS_PID" 
    201185                    retcode=$? 
    202                     rm $homedir/.profile.d/dbus-bash.sh 
     186                    rm $homedir/.dbus-session 
    203187                elif [ $(id -u) -eq $uidnr ]; then 
    204188                    kill $DBUS_SESSION_BUS_PID 
    205189                    retcode=$? 
    206                     rm $homedir/.profile.d/dbus-bash.sh 
     190                    rm $homedir/.dbus-session 
    207191                fi 
    208192         
     
    223207 
    224208 
    225 1.4 Installation of Sudo 1.6.8p7 
    226 -------------------------------- 
     2091.4 Installation of Sudo 1.6.8p12 
     210--------------------------------- 
    227211 
    228212With sudo it's possible to execute a script or command as a normal user, 
    229 being root. I use version 1.6.8p7. You can get a recent version from: 
    230  
    231 http://www.sudo.ws/sudo 
    232  
    233 Unpack and change to the source: 
    234  
    235 tar -xvzf sudo-1.6.8p7.tar.gz 
    236 cd sudo-1.6.8p7 
    237  
    238 ./configure --prefix=/usr --libexecdir=/usr/sbin --mandir=/usr/share/man --sysconfdir=/etc 
    239 make 
    240 make install 
    241  
     213being root.  
     214 
     215Since some time now sudo is in the BLFS book. Install it as described there. 
    242216Notes: 
    243217 
     
    246220If you want you can copy this to the usual directory in: 
    247221 
    248 /usr/share/doc/sudo-1.6.8p7 
     222/usr/share/doc/sudo-1.6.8p12 
    249223 
    250224- Authentication can be done via PAM. This is not needed here, because the default 
     
    275249[2006-01-18] 
    276250  * Initial hint. 
     251[2006-07-18] 
     252  * Changed the bash scripts 
     253  * changed from sudo-1.6.8p7 to sudo-1.6.8p12 
     254