Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # simple script to ease XFCE installation on a WSL (Windows Subsystem for Linux)
  4. # environment:
  5. #
  6. # This will install essential Xorg packages (without install server side as WSL
  7. # currently don't have the ability of starting a native Xserver)
  8. #
  9. # You'll have to rely on a Windows native Xserver such like vcxsrv or Xming
  10. #
  11. # 2019-02-16 - Eric Belhomme
  12.  
  13.  
  14. if [ $UID != 0 ]; then
  15. echo "Fatal: run run as root user"
  16. exit 1
  17. fi
  18.  
  19. function install_locales() {
  20. # sudo dpkg-reconfigure locales
  21. BAKIFS=$IFS
  22. IFS=$'\n'
  23. LOCALES=('en_US ISO-8859-1' \
  24. 'en_US.ISO-8859-15 ISO-8859-15' \
  25. 'en_US.UTF-8 UTF-8' \
  26. 'fr_FR ISO-8859-1' \
  27. 'fr_FR.UTF-8 UTF-8' \
  28. 'fr_FR@euro ISO-8859-15')
  29.  
  30. for ITEM in ${LOCALES[@]}; do
  31. sed -i -e "s/^# .*$ITEM/$ITEM/" /etc/locale.gen
  32. done
  33. IFS=$BAKIFS
  34. dpkg-reconfigure --frontend=noninteractive locales && update-locale LANG=en_US.UTF-8
  35. cat > /etc/default/locale <<EOF
  36. LANGUAGE=en_US.UTF-8
  37. LC_ALL=C
  38. LANG=en_US.UTF-8
  39. EOF
  40. }
  41.  
  42. function install_xcore() {
  43. apt-get install -y xserver-xorg-video-dummy xserver-xorg-input-void xserver-xorg-core
  44. apt-get install -y xorg
  45. apt-get install -y x11-xkb-utils xfonts-base xfonts-encodings xfonts-scalable \
  46. xfonts-utils x11-session-utils dbus-x11 desktop-base desktop-file-utils gconf* \
  47. gnome-mime-data gnome-themes-standard*
  48. }
  49.  
  50. function install_xfce4() {
  51. apt-get install -y xfce4-session xfce4-settings xfdesktop4* xfce4-appfinder \
  52. xfce4-panel xfce4-notifyd xfce4-xkb-plugin notification-daemon thunar
  53. }
  54.  
  55. function install_gutils() {
  56. apt-get install -y terminator
  57. apt-get install -y --no-install-recommends meld firefox-esr firefox-esr-l10n-fr
  58. update-alternatives --set x-terminal-emulator /usr/bin/terminator
  59. update-alternatives --set x-www-browser /usr/bin/firefox-esr
  60. }
  61.  
  62. function configure_xstart() {
  63. WINHOME=$(wslpath $(cmd.exe /C "echo %USERPROFILE%"))
  64. if [ ! -e ${HOME}/winhome ]; then
  65. ln -s $WINHOME ${HOME}/winhome
  66. fi
  67.  
  68. if [ ! -e ${HOME}/startxfce4 ]; then
  69. cat > ${HOME}/startxfce4 <<EOF
  70. #!/bin/bash
  71. cd $HOME
  72. #eval "$(ssh-agent -s)" &> /dev/null
  73. export DISPLAY="localhost:0.0"
  74.  
  75. exec dbus-run-session -- bash -l -c startxfce4 &> $HOME/xfce-session.log
  76. EOF
  77. fi
  78. chmod 0750 ${HOME}/startxfce4
  79.  
  80. if [ "$(grep -c "export DISPLAY")" == "0" ]; then
  81. echo 'export DISPLAY="localhost:0.0"' >> ${HOME}.bashrc
  82. fi
  83. if [ "$(grep -c "export LD_PRELOAD")" == "0" ]; then
  84. echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGL.so.1' >> ${HOME}.bashrc
  85. fi
  86. if [ "$(grep -c "export NO_AT_BRIDGE")" == "0" ]; then
  87. echo 'export NO_AT_BRIDGE=1' >> ${HOME}.bashrc
  88. fi
  89. if [ "$(grep -c "export WINHOME")" == "0" ]; then
  90. echo "export WINHOME=$WINHOME" >> ${HOME}.bashrc
  91. fi
  92.  
  93. if [ ! -e $WINHOME/Desktop/Xfce4.xlaunch ]; then
  94. cat > $WINHOME/Desktop/Xfce4.xlaunch << EOF
  95. <?xml version="1.0" encoding="UTF-8"?>
  96. <XLaunch WindowMode="Windowed" ClientMode="StartProgram" LocalClient="True" Display="-1" LocalProgram="C:\Windows\System32\wsl.exe -u $USER ${HOME}/startxfce4" RemoteProgram="xterm" RemotePassword="" PrivateKey="" RemoteHost="" RemoteUser="" XDMCPHost="" XDMCPBroadcast="False" XDMCPIndirect="False" Clipboard="True" ClipboardPrimary="True" ExtraParams="" Wgl="True" DisableAC="False" XDMCPTerminate="False"/>
  97. EOF
  98. fi
  99. }
  100.  
  101. ###
  102.  
  103.  
  104. function exit_help() {
  105. cat <<EOF
  106. $0 - installs XFCE4 graphical on WSL env
  107.  
  108. usage : $0 -h -a -l -c -x -g
  109.  
  110. -h : this help
  111. -l : set locales
  112. -c : installs Xorg core
  113. -x : installs Xfce4 Window Manager
  114. -g : installs some GUI tools (terminator, meld, Firefox)
  115. -i : configure Linux and Windows env to start Xfce4 with vcXsrv
  116. -a : do all of the above
  117.  
  118. EOF
  119. exit 1
  120. }
  121.  
  122. if [ "$#" -eq 0 ]; then exit_help; fi
  123.  
  124. loca=0
  125. xcor=0
  126. xfce=0
  127. guti=0
  128. vcxs=0
  129. while getopts "halcxgi" option; do
  130. case "$1" in
  131. -a)
  132. loca=1
  133. xcor=1
  134. xfce=1
  135. guti=1
  136. vcxs=1
  137. shift; ;;
  138. -l)
  139. loca=1; shift; ;;
  140. -c)
  141. xcor=1; shift; ;;
  142. -x)
  143. xfce=1; shift; ;;
  144. -g)
  145. guti=1; shift; ;;
  146. -i)
  147. vcxs=1; shift; ;;
  148. *)
  149. exit_help
  150. shift
  151. ;;
  152. esac
  153. done
  154.  
  155. # do this anytime
  156. if [ -z "$(find /var/cache/apt/pkgcache.bin -mmin -60)" ]; then
  157. apt-get update
  158. fi
  159. apt-get install -y locales bash-completion git vim
  160. update-alternatives --set editor /usr/bin/vim.basic
  161.  
  162. if [ $loca -eq 1 ]; then install_locales; fi
  163. if [ $xcor -eq 1 ]; then install_xcore; fi
  164. if [ $xfce -eq 1 ]; then install_xfce4; fi
  165. if [ $guti -eq 1 ]; then install_gutils; fi
  166. if [ $vcxs -eq 1 ]; then configure_xstart; fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement