Guest User

Untitled

a guest
Nov 4th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.74 KB | None | 0 0
  1. #!/bin/sh
  2. # Copyright 1999, 2002, 2012  Patrick Volkerding, Moorhead, Minnesota USA
  3. # All rights reserved.
  4. #
  5. # Redistribution and use of this script, with or without modification, is
  6. # permitted provided that the following conditions are met:
  7. #
  8. # 1. Redistributions of this script must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. #
  11. #  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  12. #  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  13. #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  14. #  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  15. #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  16. #  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  17. #  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  18. #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  19. #  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  20. #  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. #
  22.  
  23. # First, let's bail if our being here doesn't make sense:
  24. if [ ! -d /etc/X11/xinit ]; then
  25.   exit
  26. fi
  27. if [ "`cd /etc/X11/xinit ; echo *.*`" = '*.*' ]; then
  28.   exit
  29. fi
  30.  
  31. if [ "$USER" = "root" ]; then
  32.   TMP=/var/log/setup/tmp
  33. else
  34.   TMP=$HOME/.xwmconfig
  35. fi
  36.  
  37. if [ ! -d $TMP ]; then
  38.  mkdir -p $TMP
  39.  chmod 700 $TMP
  40. fi
  41.  
  42. # Do we already have an existing default?
  43. unset PRESELECT
  44. if [ -L /etc/X11/xinit/xinitrc ]; then
  45.   CURRENT="`/bin/ls -l /etc/X11/xinit/xinitrc | cut -f 2 -d '>' | cut -b2-`"
  46.   PRESELECT=" --default-item $CURRENT "
  47. fi
  48.  
  49. # Figure out who we are and set up some background information:
  50. if [ "$USER" = "root" ]; then
  51.   BACKTITLE="--backtitle \"Setting system-wide default window manager in /etc/X11/xinit/\""
  52. else
  53.   BACKTITLE="--backtitle \"Setting default window manager in $HOME/.xinitrc and $HOME/.xsession\""
  54. fi
  55.  
  56. # This stops --backtitle from cluttering the initial install:
  57. if [ ! -r /proc/kcore ]; then
  58.   BACKTITLE=""
  59. fi
  60.  
  61. # Remove any previous script:
  62. rm -f $TMP/tmpscript.sh
  63.  
  64. # Add the top of the script:
  65. if [ -r /etc/X11/xinit/xinitrc.gnome -a -r /etc/X11/xinit/xinitrc.kde ]; then
  66. cat << EOF > $TMP/tmpscript.sh
  67. #!/bin/sh
  68. dialog $BACKTITLE --title "SELECT DEFAULT WINDOW MANAGER FOR X" $PRESELECT --menu \\
  69. "Please select the default window manager to use with the X Window \\
  70. System.  This will define the style of graphical user interface \\
  71. the computer uses.  KDE and GNOME provide the most features. People \\
  72. with Windows or MacOS experience will find either one easy to use.  \\
  73. Other window managers are easier on system \\
  74. resources, or provide other unique features." 12 74 0 \\
  75. EOF
  76. elif [ -r /etc/X11/xinit/xinitrc.kde ]; then
  77. cat << EOF > $TMP/tmpscript.sh
  78. #!/bin/sh
  79. dialog $BACKTITLE --title "SELECT DEFAULT WINDOW MANAGER FOR X" $PRESELECT --menu \\
  80. "Please select the default window manager to use with the X Window \\
  81. System.  This will define the style of graphical user interface \\
  82. the computer uses.  KDE provides the most features, and people \\
  83. with Windows or MacOS experience will find it easy to use.  \\
  84. Other window managers are easier on system \\
  85. resources, or provide other unique features." 12 74 0 \\
  86. EOF
  87. elif [ -r /etc/X11/xinit/xinitrc.xfce ]; then
  88. cat << EOF > $TMP/tmpscript.sh
  89. #!/bin/sh
  90. dialog $BACKTITLE --title "SELECT DEFAULT WINDOW MANAGER FOR X" $PRESELECT --menu \\
  91. "Please select the default window manager to use with the X Window \\
  92. System.  This will define the style of graphical user interface \\
  93. the computer uses.  XFce provides the most features, and people \\
  94. with Windows or MacOS experience will find it easy to use.  \\
  95. Other window managers are easier on system \\
  96. resources, or provide other unique features." 12 74 0 \\
  97. EOF
  98. else
  99. cat << EOF > $TMP/tmpscript.sh
  100. dialog $BACKTITLE --title "SELECT DEFAULT WINDOW MANAGER FOR X" $PRESELECT --menu \\
  101. "Please select the default window manager to use with the X Window \\
  102. System.  This will define the style of graphical user interface \\
  103. the computer uses." 12 74 0 \\
  104. EOF
  105. fi
  106.  
  107. # Add KDE as the first and default entry:
  108. if [ -r /etc/X11/xinit/xinitrc.kde ]; then
  109.   echo "\"xinitrc.kde\" \"KDE: K Desktop Environment\" \\" >> $TMP/tmpscript.sh
  110. fi
  111.  
  112. # Then, we add GNOME:
  113. if [ -r /etc/X11/xinit/xinitrc.gnome ]; then
  114.  echo "\"xinitrc.gnome\" \"GNU Network Object Model Environment\" \\" >> $TMP/tmpscript.sh
  115. fi
  116.  
  117. # Add XFce:
  118. if [ -r /etc/X11/xinit/xinitrc.xfce ]; then
  119.   echo "\"xinitrc.xfce\" \"The Cholesterol Free Desktop Environment\" \\" >> $TMP/tmpscript.sh
  120. fi
  121.  
  122. # Add Enlightenment:
  123. if [ -r /etc/X11/xinit/xinitrc.e ]; then
  124.  echo "\"xinitrc.e\" \"Enlightenment\" \\" >> $TMP/tmpscript.sh
  125. fi
  126.  
  127. # Add Fluxbox:
  128. if [ -r /etc/X11/xinit/xinitrc.fluxbox ]; then
  129.   echo "\"xinitrc.fluxbox\" \"The fluxbox window manager\" \\" >> $TMP/tmpscript.sh
  130. fi
  131.  
  132. # Add Blackbox:
  133. if [ -r /etc/X11/xinit/xinitrc.blackbox ]; then
  134.  echo "\"xinitrc.blackbox\" \"The blackbox window manager\" \\" >> $TMP/tmpscript.sh
  135. fi
  136.  
  137. # Add WindowMaker:
  138. if [ -r /etc/X11/xinit/xinitrc.wmaker ]; then
  139.   echo "\"xinitrc.wmaker\" \"WindowMaker\" \\" >> $TMP/tmpscript.sh
  140. fi
  141.  
  142. # Add FVWM2:
  143. if [ -r /etc/X11/xinit/xinitrc.fvwm2 ]; then
  144.  echo "\"xinitrc.fvwm2\" \"F(?) Virtual Window Manager (version 2.xx)\" \\" >> $TMP/tmpscript.sh
  145. fi
  146.  
  147. # Add FVWM95:
  148. if [ -r /etc/X11/xinit/xinitrc.fvwm95 ]; then
  149.   echo "\"xinitrc.fvwm95\" \"FVWM2 with a Windows look and feel\" \\" >> $TMP/tmpscript.sh
  150. fi
  151.  
  152. # Add icewm:
  153. if [ -r /etc/X11/xinit/xinitrc.icewm ]; then
  154.  echo "\"xinitrc.icewm\" \"ICE Window Manager\" \\" >> $TMP/tmpscript.sh
  155. fi
  156.  
  157. # Add sawfish:
  158. if [ -r /etc/X11/xinit/xinitrc.sawfish ]; then
  159.   echo "\"xinitrc.sawfish\" \"Sawfish without GNOME\" \\" >> $TMP/tmpscript.sh
  160. fi
  161.  
  162. # Add twm:
  163. if [ -r /etc/X11/xinit/xinitrc.twm ]; then
  164.  echo "\"xinitrc.twm\" \"Tab Window Manager (very basic)\" \\" >> $TMP/tmpscript.sh
  165. fi
  166.  
  167. # Add mwm:
  168. if [ -r /etc/X11/xinit/xinitrc.mwm ]; then
  169.   echo "\"xinitrc.mwm\" \"Motif WM\" \\" >> $TMP/tmpscript.sh
  170. fi
  171.  
  172. # Now, add support for the other window managers:
  173. ( cd /etc/X11/xinit
  174.  for file in xinitrc.* ; do
  175.    if [ ! "$file" = "xinitrc.kde" -a ! "$file" = "xinitrc.gnome" \
  176.      -a ! "$file" = "xinitrc.e" -a ! "$file" = "xinitrc.wmaker" \
  177.      -a ! "$file" = "xinitrc.fvwm2" -a ! "$file" = "xinitrc.fvwm95" \
  178.      -a ! "$file" = "xinitrc.icewm" -a ! "$file" = "xinitrc.twm" \
  179.      -a ! "$file" = "xinitrc.mwm" -a ! "$file" = "xinitrc.xfce" \
  180.      -a ! "$file" = "xinitrc.blackbox" -a ! "$file" = "xinitrc.fluxbox" \
  181.      -a ! "$file" = "xinitrc.sawfish" ]; then
  182.      echo "\"$file\" \"$file\" \\" >> $TMP/tmpscript.sh
  183.     fi
  184.   done
  185. )
  186.  
  187. # Then, the tail end:
  188. cat << EOF >> $TMP/tmpscript.sh
  189. 2> $TMP/output
  190. if [ ! \$? = 0 ]; then
  191.   rm -f $TMP/output
  192.   echo "Canceled."
  193.   exit
  194. fi
  195. EOF
  196.  
  197. sh $TMP/tmpscript.sh
  198.  
  199. if [ ! -r $TMP/output ]; then
  200.   rm -f $TMP/tmpscript.sh
  201.   exit
  202. fi
  203.  
  204. OUTPUT=`cat $TMP/output`
  205.  
  206. # If xwmconfig is run by root, it changes the system-wide default for users
  207. # that do not have a $HOME/.xinitrc:
  208. if [ "$USER" = "root" ]; then
  209.   if [ -r /etc/X11/xinit/$OUTPUT ]; then
  210.     ( cd /etc/X11/xinit ; rm -f xinitrc ; ln -sf $OUTPUT xinitrc )
  211.   fi
  212. fi
  213.  
  214. # Also set up a new $HOME/.xinitrc and $HOME/.xinitrc:
  215. if [ -r /etc/X11/xinit/$OUTPUT -a ! "$HOME" = "/" ]; then
  216.   if [ -r $HOME/.xinitrc ]; then
  217.     rm -f $HOME/.xinitrc-backup
  218.     mv $HOME/.xinitrc $HOME/.xinitrc-backup
  219.   fi
  220.   cat /etc/X11/xinit/$OUTPUT > $HOME/.xinitrc
  221.   if [ -r $HOME/.xsession ]; then
  222.     rm -f $HOME/.xsession-backup
  223.     mv $HOME/.xsession $HOME/.xsession-backup
  224.   fi
  225.   cat /etc/X11/xinit/$OUTPUT > $HOME/.xsession
  226.   chmod 755 $HOME/.xsession
  227. fi
  228.  
  229. rm -f $TMP/tmpscript.sh $TMP/output
  230.  
Advertisement
Add Comment
Please, Sign In to add comment