?TableOfContents

System wide Profile

The Plan9 shell rc(1), when used as 'login' shell, reads first the file /rc/lib/rcmain and then the file ~/lib/profile if it exists. '~' stands for /usr/userid.

In the default Plan9 installation rcmain sets the home variable, ifs and the prompt. ~/lib/profile is created by the /sys/lib/newuser script and essentially sets up the namespace, font, mail client and the prompt again.

The following approach introduces a system wide profile, similar to the behaviour of the POSIX sh command.

To install it copy or modify the following files:
/rc/lib/rcmain:
extended to include /rc/lib/profile if it exists and if rc is called as "login" shell (with the -l option). If neither the system wide profile nor the user profile has set up a prompt a minimal prompt is configured.
/rc/lib/profile:
sets up the default namespace for a user. The prompt is set to fancy values if working remotely.
/sys/lib/newuser:
this is used to set up a useraccount, ~/lib/profile is generated here with a </magma/lib instead of /sys/lib/, although you might want to put it there for simplicity: /magma/lib/newuser:
set up a new user account
/magma/lib/profile:
default ~/lib/profile file, sets up the terminal, mail client and starts initial user programs

/rc/lib/rcmain

cat > /rc/lib/rcmain <<EOF
# /rc/lib/rcmain
# LEG20061130
#
# derived from : Plan 9 version
# added global profile
#

if(~ $#home 0) home=/
if(~ $#ifs 0) ifs='     
'

if(~ $rcname ?.out) prompt=('broken! ' '        ')
if(flag p) path=/bin
if not{
        finit
        if(~ $#path 0) path=(. /bin)
}
fn sigexit
if(! ~ $#cflag 0){
        if(flag l){
                if(/bin/test -r /rc/lib/profile) . /rc/lib/profile
                if(/bin/test -r $home/lib/profile) . $home/lib/profile
        }
        status=''
        eval $cflag
}
if not if(flag i){
        if(flag l){
                if(/bin/test -r /rc/lib/profile) . /rc/lib/profile
                if(/bin/test -r $home/lib/profile) . $home/lib/profile
        }
        status=''
        if(! ~ $#* 0) . $*
        . -i '#d/0'
}
if not if(~ $#* 0) . '#d/0'
if not{
        status=''
        . $*
}

switch($#prompt){
case 0
        prompt=('% ' '  ')
case 1
        prompt=($prompt '       ')
}
exit $status
EOF

/rc/lib/profile

cat > /rc/lib/profile <<EOF
# /rc/lib/profile
# LEG20061130
#
# system wide profile for rc(1)

bind -a $home/bin/rc /bin
bind -a $home/bin/$cputype /bin
bind -c tmp /tmp
if(! syscall create /tmp/xxx 1 0666 >[2]/dev/null)
        ramfs   # in case we're running off a cd
font = /lib/font/bit/pelm/euro.9.font

fn cd { builtin cd $* && awd }  # for acme
switch($service){
case terminal
        prompt=($sysname'% ' '  ')
case cpu
        prompt=('cpu:'$user@$sysname'% ' '      ')
case con
        prompt=($user@$sysname'% ' '    ')
}

if(/bin/test -r /magma/bin) bind -a /magma/bin /bin
EOF

newuser

Be careful to change the line: cp /magma/lib/profile lib/profile, if you install the default user profile in another location.

#!/bin/rc
# /magma/lib/newuser
# LEG20061130: derived from Plan9 /sys/lib/newuser
#

user=`{cat /dev/user}
home=/usr/$user
if(test -f $home/lib/profile){
        echo user directories already made
        exit no
}
cd $home
x='$'
mkdir bin bin/rc bin/mips bin/386
mkdir lib tmp
chmod +t tmp
bind -c $home/tmp /tmp

mail -c
auth/cron -c

cp /magma/lib/profile lib/profile

cat > lib/plumbing <<!
# to update: cp /usr/$user/lib/plumbing /mnt/plumb/rules

editor = acme

include basic

!

. lib/profile

How do you create the /magma directory, ... or any directory inside / at all? You need to connect to the fossil fileserver via fscons and issue something like:

fsys main
create /active/magma glenda none d755

user profile

# $home/lib/profile
# LEG20061130
#
# default user profile for rc(1)

upas/fs
fn cd { builtin cd $* && awd }  # for acme
switch($service){
case terminal
        plumber
        echo -n accelerated > '#m/mousectl'
        echo -n 'res 3' > '#m/mousectl'
        exec rio -i riostart
case cpu
        if (test -e /mnt/term/mnt/wsys) { # rio already running
                bind -a /mnt/term/mnt/wsys /dev
                if(test -w /dev/label)
                        echo -n $sysname > /dev/label
        }
        bind /mnt/term/dev/cons /dev/cons
        bind /mnt/term/dev/consctl /dev/consctl
        bind -a /mnt/term/dev /dev
        news
        if (! test -e /mnt/term/mnt/wsys) {     # cpu call from drawterm
                font=/lib/font/bit/pelm/latin1.8.font
                exec rio
        }
case con
        news
}