Here is a script you can all use which selects a desktop environment,
installs it if necessary, and configures a (eg. your) user's X session
so that it starts when he, she or you log in, facilitating further
user-centric configuration.
Perhaps if you ask really nicely the devs will install it into the base
system somewhere for you and maintain the map of packages to
descriptions because even the densest among you must be aware by now
that you're never getting anything more complicated than this.
Now will you all please stop this and go and do something useful?
Matthew
src/gui-selector.sh:
#!/bin/ksh
default="fvwm"
builtin="cwm fvwm twm"
bloaty="kde gnome xfce"
gnome="gnome" # Is there something for this?
gnome_full=$gnome
gnome_bloat="gnome-extras"
gnome_bin=/usr/local/bin/gnome
kde="kde4-minimal"
kde_full="kde4"
kde_bloat="kde4-extras"
kde_bin=/usr/local/bin/kde4
xfce="xfce"
xfce_full="xfce-extras"
xfce_bloat=$xfce_full
xfce_bin=/usr/local/bin/xfce
cwm_desc="?"
fvwm_desc="Simple, effective, default"
twm_desc="Theo likes it so it must be good"
gnome_desc="We know what you want, except not correctly like Apple"
kde_desc="The only DE ever to kill my X server"
xfce_desc="I heard of this once"
error() {
if [[ $# != 0 ]]; then
echo "$@" >&2
else
cat >&2
fi
}
abort() {
error "$@"
exit 1
}
msg() {
if [[ $# != 0 ]]; then
echo "$@"
else
cat
fi
}
prompt() {
answer= # NOT local
echo -n "$@" ''
read answer
echo
}
root=
if [[ `id -u` -ne 0 ]]; then
root=doas
error <<ROOT
Before this script can continue root access required.
Either stop this script with Ctrl-C and execute it in a root shell or
ensure this line exists in /etc/doas.conf:
permit nopass $USER as root cmd pkg_add
Note that there are more secure ways to achieve this but it should be
acceptable for a desktop computer; see doas.conf(5) for more
information.
When your user account's root privileges are enabled, press enter to
continue.
ROOT
prompt Root privileges?
fi
# TODO: layouts and shit
list_ui() {
unset list # NOT local
local this=0
for cat in builtin bloaty; do
msg DE category: $cat
msg ''
eval _all=\$$cat
for de in $_all; do
eval msg $this: $de -- \$${de}_desc
list[$this]=$de
((this++))
done
msg ''
done
}
find_de() {
de= # NOT local
local _c=$1 _i=
if [[ " $builtin $bloaty " = *" $_C "* ]]; then
de=$_c
return 0
fi
if [[ $_c = *[0-9]* && $_c -lt ${#list[@]} ]]; then
de=${list[$_c]}
return 0
fi
_i=0
while [[ $_i -lt ${#list[@]} ]]; do
if [[ ${list[$_i]} = $_c ]]; then
de=$_c
return 0
fi
((_i++))
done
return 1
}
list_ui
msg You may identify a desktop environment by its number or its short name.
while prompt Which desktop environment would you like to use? && ! find_de
"$answer"; do
error Invalid selection.
done
if ! [[ " $builtin " = *" $de "* ]]; then
msg <<BLOAT
Desktop environments other than those which are built into the base
system come in up to three flavours, Regular, Full and Bloaty. Not all
environments provide all three flavours. If you select a flavour which
is not available the next-smallest flavour will be chosen in its place.
BLOAT
while prompt Which flavour would you like to install [Regular]: && [[ -n
"$answer" && "$answer" != [BbFfRr]* ]]; do
error Invalid selection.
done
case "$answer" in
[Bb]*) bloat=${de}_bloat;;
[Ff]*) bloat=${de}_full;;
[Rr]*|'') bloat=$de;;
esac
eval \$root pkg_add \$$bloat
fi
if [[ `id -u` -eq 0 ]]; then
_g=
while prompt Which user account to you want to set the desktop environment
for? && ! _g=$(getent passwd "$answer"); do
error Invalid user.
done
userhome=$(echo "$_g" | cut -d: -f6)
whose="the user's"
else
userhome=$HOME
whose="your"
fi
if [[ -e $userhome/.xsession ]]; then
bak=$(date +%F:%T)
msg Backing up previous xsession file to "$userhome/.xsession~$bak"
cp "$userhome/.xsession" "$userhome/.xsession~$bak" || abort cp .xsession
fi
if [[ " $builtin " = *" $de "* ]]; then
echo exec /usr/X11R6/bin/$de > $userhome/.xsession
else
eval echo exec \$${de}_bin > $userhome/.xsession
fi || abort Could not write to $userhome/.xsession
msg << COMPLETE
$de has been installed and configured as $whose default desktop
environment. You may log out or reboot to enter it.
To install another environment and change $whose default, simply
run this script again.
COMPLETE