|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# WSL onboarding script |
| 4 | +# Does the initial setup for wsl using VcXsrv as a XServer. |
| 5 | +# Install Ubuntu using the windows store and enable WSL in "Windows optional features" |
| 6 | +# As an alternative to enable the WSL manually you can start this script with the |
| 7 | +# bundeled powershell script. Consult the README for more information. |
| 8 | + |
| 9 | +# AUTHOR: Jonas Erbe |
| 10 | +# GITHUB: https://github.com/jason076 |
| 11 | +# REPOSITORY: https://github.com/jason076/wsl-onboarding |
| 12 | + |
| 13 | +# throw error if an unset variable is used |
| 14 | +set -u |
| 15 | + |
| 16 | +# constants |
| 17 | + |
| 18 | +# Global variables |
| 19 | +LANGUAGE="de" |
| 20 | +export LANGUAGE |
| 21 | + |
| 22 | + |
| 23 | +####################################### |
| 24 | +# Load language file |
| 25 | +# Globals: |
| 26 | +# LANGUAGE |
| 27 | +# Arguments: |
| 28 | +# none |
| 29 | +# Returns: |
| 30 | +# 0: language loaded successfully |
| 31 | +# 1: language does not exist |
| 32 | +####################################### |
| 33 | +load_language() { |
| 34 | + |
| 35 | + # TODO(jonas): choose language dialog |
| 36 | + |
| 37 | + # load language file |
| 38 | + lang_file=share/language/"${LANGUAGE}".sh |
| 39 | + if [ -f "${lang_file}" ]; then |
| 40 | + . "${lang_file}" |
| 41 | + return 0 |
| 42 | + else |
| 43 | + return 1 |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +####################################### |
| 48 | +# Install default WSL config files |
| 49 | +# Globals: |
| 50 | +# None |
| 51 | +# Arguments: |
| 52 | +# None |
| 53 | +# Returns: |
| 54 | +# None |
| 55 | +####################################### |
| 56 | + |
| 57 | +install_default_config() { |
| 58 | + # TODO(jason076): Check for errors and return appropriate value |
| 59 | + cp -b ./share/default-config/xinitrc ~/.xinitrc |
| 60 | + |
| 61 | + # TODO(jason076): Check Ubuntu standard files and include them |
| 62 | + cp -b ./share/default-config/profile ~/.profile |
| 63 | + |
| 64 | + # TODO(jason076): Add wsl.conf to message |
| 65 | + sudo cp -b ./share/default-config/wsl.conf /etc/wsl.conf |
| 66 | + |
| 67 | + # binaries |
| 68 | + if [ ! -d ~/.local/bin ]; then |
| 69 | + mkdir -p ~/.local/bin |
| 70 | + fi |
| 71 | + |
| 72 | + cp -b ./share/default-config/startX.sh ~/.local/bin/startX.sh |
| 73 | +} |
| 74 | + |
| 75 | +####################################### |
| 76 | +# Create scaleable fonts according to Xming Documentation: |
| 77 | +# http://www.straightrunning.com/XmingNotes/fonts.php |
| 78 | +# Globals: |
| 79 | +# None |
| 80 | +# Arguments: |
| 81 | +# None |
| 82 | +# Returns: |
| 83 | +# None |
| 84 | +####################################### |
| 85 | + |
| 86 | +# TODO(jason076): Useless remove in future |
| 87 | +create_scalable_fonts() { |
| 88 | + # assuming that 64-bit Xming is installed |
| 89 | + # index fonts for XServer |
| 90 | + cd "/mnt/c/Program Files/Xming" |
| 91 | + ./mkfontscale.exe 'C:\Windows\Fonts' 2>/dev/null |
| 92 | + ./mkfontscale.exe -b -f -l 'C:\Windows\Fonts' 2>/dev/null |
| 93 | + |
| 94 | + # Add windows fonts to the font dirs of xming |
| 95 | + if grep -i 'C:\\Windows\\Fonts' "/mnt/c/Program Files/Xming/font-dirs"; then |
| 96 | + return 0 |
| 97 | + else |
| 98 | + if echo 'C:\Windows\Fonts' >> "/mnt/c/Program Files/Xming/font-dirs"; then |
| 99 | + return 0 |
| 100 | + else |
| 101 | + return 1 |
| 102 | + fi |
| 103 | + fi |
| 104 | + |
| 105 | + # TODO(jason076) Add additonal fonts |
| 106 | + |
| 107 | + # Will be removed |
| 108 | + #if depmgmt__need "fontconfig"; then |
| 109 | + # make fonts available to applications |
| 110 | + #if [ ! -L /usr/local/share/fonts/windows ]; then |
| 111 | + # sudo ln -s /mnt/c/Windows/Fonts /usr/local/share/fonts/windows |
| 112 | + #fi |
| 113 | + #echo "Indexing fonts may take a while. Please wait ..." |
| 114 | + #fc-cache -rf |
| 115 | + #else |
| 116 | + # return 1 |
| 117 | + #fi |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +main() { |
| 122 | + |
| 123 | + PATH="${PATH}:`pwd`/bin" |
| 124 | + |
| 125 | + . `pwd`/lib/libmgmt.sh |
| 126 | + |
| 127 | + # load language |
| 128 | + load_language |
| 129 | + if [ $? -ne 0 ]; then |
| 130 | + echo "Failed loading language file! Exit!" |
| 131 | + exit 1 |
| 132 | + fi |
| 133 | + |
| 134 | + echo "${WSL_DIALOG}" |
| 135 | + |
| 136 | + # load script libraries |
| 137 | + libmgmt__load "io" |
| 138 | + libmgmt__load "wsl" |
| 139 | + libmgmt__load "depmgmt" |
| 140 | + |
| 141 | + |
| 142 | + io__init 'TRUE' 0 0 |
| 143 | + io__message "${WSL_WELCOME}" |
| 144 | + io__message "${WSL_INFO}" |
| 145 | + |
| 146 | + # upgrade system |
| 147 | + io__message "${WSL_SYS_UPGRADE}" |
| 148 | + sudo apt update |
| 149 | + sudo apt full-upgrade |
| 150 | + io__message "${WSL_SYS_UPGRADE_FINISHED}" |
| 151 | + |
| 152 | + # only continue if ubuntu is running in admin mode |
| 153 | + if wsl__is_winadmin; then |
| 154 | + : |
| 155 | + else |
| 156 | + io__message "${WSL_NO_ADMIN}" |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | + |
| 160 | + # install default config files |
| 161 | + io__message "${WSL_INSTALL_CONFIG}" |
| 162 | + install_default_config |
| 163 | + |
| 164 | + # install VcXsrv |
| 165 | + # TODO(jason076): Change message to VcXsrc |
| 166 | + io__message "${WSL_INSTALL_XMING}" |
| 167 | + ./bin/vcxsrv-installer.exe |
| 168 | + |
| 169 | + #io__message "${WSL_CREATE_SCALEABLE_FONT}" |
| 170 | + # |
| 171 | + #if create_scalable_fonts; then |
| 172 | + # : |
| 173 | + #else |
| 174 | + # io__message "${WSL_SCALEABLE_FAILED}" |
| 175 | + # exit 1 |
| 176 | + #fi |
| 177 | + |
| 178 | + # TODO(jason076): Add a fix for blurry fonts caused by dpi scaling |
| 179 | + # Dialog for choosing a gdk_scale factor |
| 180 | + |
| 181 | + # TODO(jason076): Add message |
| 182 | + # Install dbus-x11 |
| 183 | + if depmgmt__need dbus-x11; then |
| 184 | + : |
| 185 | + else |
| 186 | + exit 1 |
| 187 | + fi |
| 188 | + |
| 189 | + # TODO(jason076): Add message |
| 190 | + # Install gtk2-engines-pixbuf |
| 191 | + if depmgmt__need gtk2-engines-pixbuf; then |
| 192 | + : |
| 193 | + else |
| 194 | + exit 1 |
| 195 | + fi |
| 196 | + |
| 197 | + # Install terminator |
| 198 | + io__message "${WSL_INSTALL_TERMINATOR}" |
| 199 | + if depmgmt__need terminator; then |
| 200 | + : |
| 201 | + else |
| 202 | + io__message "${WSL_INSTALL_TERMINATOR_FAILED}" |
| 203 | + exit 1 |
| 204 | + fi |
| 205 | + |
| 206 | + # TODO(jason076): Add message |
| 207 | + # Install firefox |
| 208 | + if depmgmt__need firefox; then |
| 209 | + : |
| 210 | + else |
| 211 | + exit 1; |
| 212 | + fi |
| 213 | + |
| 214 | + # Setup succesfull |
| 215 | + io__message "${WSL_SUCCESSFULL}" |
| 216 | + exit 0 |
| 217 | +} |
| 218 | + |
| 219 | +main "$@" |
0 commit comments