| 1 | #!/bin/bash +x |
|---|
| 2 | # restartx - restart desktop in KNOPPIX |
|---|
| 3 | # (C) Klaus Knopper Mar 2004 |
|---|
| 4 | |
|---|
| 5 | PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin" |
|---|
| 6 | export PATH |
|---|
| 7 | |
|---|
| 8 | XDIALOG_HIGH_DIALOG_COMPAT=1 |
|---|
| 9 | export XDIALOG_HIGH_DIALOG_COMPAT |
|---|
| 10 | |
|---|
| 11 | # Get root |
|---|
| 12 | [ "`id -u`" != "0" ] && exec sudo "$0" "$@" |
|---|
| 13 | |
|---|
| 14 | TMP="/tmp/restartx.tmp$$" |
|---|
| 15 | |
|---|
| 16 | bailout(){ |
|---|
| 17 | rm -f "$TMP" |
|---|
| 18 | exit 0 |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | DIALOG="dialog" |
|---|
| 22 | [ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog" |
|---|
| 23 | |
|---|
| 24 | trap bailout 1 2 3 15 |
|---|
| 25 | |
|---|
| 26 | # LANGUAGE etc. |
|---|
| 27 | [ -f /etc/sysconfig/parsix ] && . /etc/sysconfig/parsix |
|---|
| 28 | [ -z "$LANG" ] && export LANG |
|---|
| 29 | [ -z "$LANGUAGE" ] && export LANGUAGE |
|---|
| 30 | [ -z "$CHARSET" ] && export CHARSET |
|---|
| 31 | [ -f /etc/sysconfig/desktop ] && . /etc/sysconfig/desktop |
|---|
| 32 | |
|---|
| 33 | # Shortcut desktop description selected |
|---|
| 34 | DESKTOPS=(kde "KDE - The K Desktop Environment" on \ |
|---|
| 35 | gnome "GNOME - The object-oriented desktop" off \ |
|---|
| 36 | wmaker "Window Maker" off \ |
|---|
| 37 | icewm "Ice WM" off \ |
|---|
| 38 | xfce "XFCE 3" off \ |
|---|
| 39 | xfce4 "XFCE 4" off \ |
|---|
| 40 | fluxbox "FluxBox" off \ |
|---|
| 41 | larswm "LarsWM" off \ |
|---|
| 42 | lg3d "Looking Glass" off \ |
|---|
| 43 | openbox "OpenBox" off \ |
|---|
| 44 | ratpoison "RatPoison" off \ |
|---|
| 45 | twm "TWM" off) |
|---|
| 46 | # Corresponding commands for "which" |
|---|
| 47 | COMMANDS=(startkde gnome-session wmaker icewm-session xfce xfce4-session fluxbox larswm lg3d openbox ratpoison twm) |
|---|
| 48 | |
|---|
| 49 | # Language-dependent Messages |
|---|
| 50 | case "$LANGUAGE" in |
|---|
| 51 | de*|at*|ch*) |
|---|
| 52 | TITLE1="Parsix X-Restart" |
|---|
| 53 | MESSAGE1="Bitte gewünschten Desktop/Windowmanager auswählen:" |
|---|
| 54 | MESSAGE2=" |
|---|
| 55 | Wollen Sie jetzt wirklich den X-Server neu starten? Alle laufenden Programme mit Grafikausgabe werden beendet!" |
|---|
| 56 | ;; |
|---|
| 57 | *) |
|---|
| 58 | TITLE1="Parsix X-Restart" |
|---|
| 59 | MESSAGE1="Please chose Desktop/Windowmanager" |
|---|
| 60 | MESSAGE2=" |
|---|
| 61 | Do you REALLY want to restart the X-Server now? All running programs with graphics output will be terminated!" |
|---|
| 62 | ;; |
|---|
| 63 | esac |
|---|
| 64 | |
|---|
| 65 | num=${#COMMANDS[@]} |
|---|
| 66 | for ((i=0; i<$num; i++)); do |
|---|
| 67 | # Remove non-existing desktops/descriptions from list |
|---|
| 68 | d0="$(($i * 3))" |
|---|
| 69 | d1="$(($i * 3 + 1))" |
|---|
| 70 | d2="$(($i * 3 + 2))" |
|---|
| 71 | if type "${COMMANDS[$i]}" >/dev/null 2>&1; then |
|---|
| 72 | [ "$DESKTOP" = "${DESKTOPS[$(($i * 3))]}" ] && DESKTOPS[$(($i * 3 + 2))]="on" || DESKTOPS[$(($i * 3 + 2))]="off" |
|---|
| 73 | else |
|---|
| 74 | unset DESKTOPS[$d0] |
|---|
| 75 | unset DESKTOPS[$d1] |
|---|
| 76 | unset DESKTOPS[$d2] |
|---|
| 77 | unset COMMANDS[$i] |
|---|
| 78 | fi |
|---|
| 79 | done |
|---|
| 80 | |
|---|
| 81 | rm -f "$TMP" |
|---|
| 82 | $DIALOG --clear --title "$TITLE1" --radiolist "$MESSAGE1" 18 75 9 "${DESKTOPS[@]}" 2>"$TMP" || bailout |
|---|
| 83 | |
|---|
| 84 | echo "DESKTOP=\"$(<$TMP)\"" >>/etc/sysconfig/desktop |
|---|
| 85 | echo "DESKTOP=\"$(<$TMP)\"" >>/etc/sysconfig/parsix |
|---|
| 86 | |
|---|
| 87 | rm -f "$TMP" |
|---|
| 88 | |
|---|
| 89 | $DIALOG --title "$TITLE1" --yesno "$MESSAGE2" 8 65 || bailout |
|---|
| 90 | |
|---|
| 91 | /etc/init.d/xsession restart |
|---|
| 92 | |
|---|
| 93 | exit $? |
|---|