Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to desktop environments #315

Merged
merged 13 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion completions/pengwin-setup
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ function _pengwin_setup() { # By convention, the function name
mapfile -t COMPREPLY < <(compgen -W 'CODE EMACS NEOVIM' -- "${cur}")
;;
GUI)
mapfile -t COMPREPLY < <(compgen -W 'NLI GUILIB HIDPI STARTMENU TERMINAL SYNAPTIC VCXSRV WINTHEME X410' -- "${cur}")
mapfile -t COMPREPLY < <(compgen -W 'DESKTOP NLI GUILIB HIDPI STARTMENU TERMINAL SYNAPTIC VCXSRV WINTHEME X410' -- "${cur}")
;;
DESKTOP)
mapfile -t COMPREPLY < <(compgen -W 'XFCE' -- "${cur}")
;;
TERMINAL)
mapfile -t COMPREPLY < <(compgen -W 'WINTERM WSLTTY TILIX GTERM XFTERM TERMINATOR KONSO' -- "${cur}")
Expand Down
155 changes: 155 additions & 0 deletions pengwin-setup.d/desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/bin/bash

# shellcheck source=common.sh
source "$(dirname "$0")/common.sh" "$@"

#Imported from common.h
declare SetupDir

function create_shortcut() {
local cmdName="$1"
local cmdToExec="$2"
local cmdIcon="$3"
# shellcheck disable=SC2155
local DEST_PATH=$(wslpath "$(wslvar -l Programs)")/Pengwin\ Applications

# shellcheck disable=SC2086
echo wslusc --name "${cmdName}" --icon "${cmdIcon}" --gui "${cmdToExec}"
# shellcheck disable=SC2086
bash "${SetupDir}"/generate-shortcut.sh --gui --name "${cmdName}" --icon "${cmdIcon}" "${cmdToExec}"

mkdir -p "${DEST_PATH}"
mv "$(wslpath "$(wslvar -l Desktop)")/${cmdName}.lnk" "${DEST_PATH}"
}

function package_installed() {

# shellcheck disable=SC2155
local result=$(apt -qq list $1 2>/dev/null | grep -c "\[install") # so it matches english "install" and also german "installiert"

if [[ $result == 0 ]]; then
return 1
else
return 0
fi
}


function install_dependencies() {
local dependencies_instaled
echo "Installing dependencies"
bash "${SetupDir}"/guilib.sh --yes "$@"
if [[ -f /etc/profile.d/dbus.sh ]]; then
bash "${SetupDir}"/hidpi.sh --yes --quiet "$@"
if [[ -f /etc/profile.d/hidpi.sh ]]; then
dependencies_instaled=0
else
dependencies_instaled=1
echo "There is a problem installing hidpi"
fi
else
dependencies_instaled=1
echo "There is a problem installing guilib utilities"
fi
return $dependencies_instaled
}

function install_xrdp() {
local port

if [[ -z "${NON_INTERACTIVE}" ]]; then
port=$(whiptail --title "Enter the desired RDP Port" --inputbox "RDP Port: " 8 50 "3395" 3>&1 1>&2 2>&3)
if [[ -z ${port} ]] ; then
echo "Cancelled"
return 1
fi
else
port="3395"
fi

install_packages xrdp xorgxrdp

sudo sed -i "s/^\(port=\)\([0-9]*\)$/\1${port}/" /etc/xrdp/xrdp.ini

# Fix the thinclient_drives error, also not needed in WSL
sudo sed -i "s/^\(FuseMountName=\)\(thinclient_drives\)$/\1\/tmp\/%u\/\2/" /etc/xrdp/sesman.ini

sudo /etc/init.d/xrdp start

sudo tee '/usr/local/bin/remote_desktop.sh' << EOF
#!/bin/bash

function execute_remote_desktop() {
host_ip=\$(ip -o -f inet addr show | grep -v 127.0.0 | awk '{printf "%s", \$4}' | cut -f1 -d/)
user_name=\$(whoami)
echo -e "username:s:\$user_name\nsession bpp:i:32\nallow desktop composition:i:1\nconnection type:i:6\n" > /tmp/remote_desktop_config.rdp
echo -e "networkautodetect:i:0\nbandwidthautodetect:i:1\n" >> /tmp/remote_desktop_config.rdp
cd /tmp
mstsc.exe remote_desktop_config.rdp /v:\$host_ip:$port "\$@"
}

execute_remote_desktop "\$@"
EOF

sudo tee '/usr/local/bin/start-xrdp' << EOF
#!/bin/bash

sudo service xrdp start >/dev/null 2>&1
EOF

sudo tee '/etc/profile.d/start-xrdp.sh' << EOF
#!/bin/sh

sudo /usr/local/bin/start-xrdp
EOF

sudo chmod +x /usr/local/bin/start-xrdp
sudo chmod +x /usr/local/bin/remote_desktop.sh
echo '%sudo ALL=NOPASSWD: /usr/local/bin/start-xrdp' | sudo EDITOR='tee ' visudo --quiet --file=/etc/sudoers.d/start-xrdp

}
xrdp

function install_xfce() {
if install_dependencies "$@" ; then
install_xrdp
local exit_status=$?

if [[ ${exit_status} != 0 ]]; then
return ${exit_status}
fi

install_packages xfce4 xfce4-terminal

if package_installed "xfce4-terminal" && package_installed "xfce4"; then
create_shortcut "Xfce desktop - Full Screen" "'/usr/local/bin/remote_desktop.sh /f'" "/usr/share/pixmaps/xfce4_xicon.png"
create_shortcut "Xfce desktop - 1024x768" "'/usr/local/bin/remote_desktop.sh /w:1024 /h:768'" "/usr/share/pixmaps/xfce4_xicon.png"
create_shortcut "Xfce desktop - 1366x768" "'/usr/local/bin/remote_desktop.sh /w:1366 /h:768'" "/usr/share/pixmaps/xfce4_xicon.png"
create_shortcut "Xfce desktop - 1920x1080" "'/usr/local/bin/remote_desktop.sh /w:1920 /h:1080'" "/usr/share/pixmaps/xfce4_xicon.png"
else
echo "There is a problem with xfce4 installation"
fi
fi

}

function main() {
local menu_choice=$(

menu --title "Desktop Menu" --checklist --separate-output "Install Desktop environments\n[SPACE to select, ENTER to confirm]:" 10 55 1 \
"XFCE" "Install XFCE Desktop environment" on \


3>&1 1>&2 2>&3)

if [[ ${menu_choice} == "CANCELLED" ]]; then
return 1
fi

if [[ ${menu_choice} == *"XFCE"* ]]; then
install_xfce "$@"
fi

}

main "$@"
12 changes: 6 additions & 6 deletions pengwin-setup.d/generate-shortcut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ if [[ "$cname" != "" ]]; then
script_location="$(wslpath "$(wslvar -s USERPROFILE)")/wslu" # Windows wslu, Linux WSL Sty.
localfile_path="/usr/share/wslu" # WSL wslu source file location, Linux Sty.
script_location_win="%USERPROFILE%\\wslu" # Windows wslu, Win Double Sty.
distro_location_win="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\pengwin.exe" # Distro Location, Win Double Sty.
if [[ "$is_gui" == "1" ]]; then
distro_location_win="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\pengwinw.exe" # Distro Location, Win Double Sty.
else
distro_location_win="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\pengwin.exe" # Distro Location, Win Double Sty.
fi
# change param according to the exec.
distro_param="run"
if [[ "$distro_location_win" == *wsl.exe ]]; then
Expand Down Expand Up @@ -256,11 +260,7 @@ if [[ "$cname" != "" ]]; then
if [[ "$customenv" != "" ]]; then
echo "${info} the following custom variable/command will be applied: $customenv"
fi
if [[ "$is_gui" == "1" ]]; then
winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='wscript.exe';\$s.Arguments='$script_location_win\\runHidden.vbs \"$distro_location_win\" $distro_param \"cd ~;$customenv bash -l -c $cname\"';\$s.IconLocation='$iconpath';\$s.Save();"
else
winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments='$distro_param cd ~;$customenv bash -l -c $cname';\$s.IconLocation='$iconpath';\$s.Save();"
fi
winps_exec "Import-Module 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\Microsoft.PowerShell.Utility\\Microsoft.PowerShell.Utility.psd1';\$s=(New-Object -COM WScript.Shell).CreateShortcut('$tpath\\$new_cname.lnk');\$s.TargetPath='\"$distro_location_win\"';\$s.Arguments=\"$distro_param cd ~;$customenv bash -l -c $cname\";\$s.IconLocation='$iconpath';\$s.Save();"
tpath="$(wslpath "$(wslvar -s TMP)")/$new_cname.lnk"
mv "$tpath" "$dpath"
echo "${info} Create shortcut ${new_cname}.lnk successful"
Expand Down
20 changes: 19 additions & 1 deletion pengwin-setup.d/gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function main() {
local menu_choice=$(

menu --title "GUI Menu" --checklist --separate-output "Install an X server or various other GUI applications\n[SPACE to select, ENTER to confirm]:" 17 99 9 \
"DESKTOP" "Install Desktop environments" off \
"NLI" "Install fcitx or iBus for improved non-Latin input support" off \
"GUILIB" "Install a base set of libraries for GUI applications" off \
"HIDPI" "Configure Qt and GTK for HiDPI displays" off \
Expand Down Expand Up @@ -43,6 +44,20 @@ function main() {
bash "${SetupDir}"/guilib.sh "$@"
fi

if [[ ${menu_choice} == *"DESKTOP"* ]]; then
local desktop_exit_status
echo "DESKTOP"
bash "${SetupDir}"/desktop.sh "$@"
desktop_exit_status=$?

if [[ ${desktop_exit_status} != 0 ]]; then
local gui_exit_status
main "$@"
gui_exit_status=$?
return $gui_exit_status
fi
fi

if [[ ${menu_choice} == *"NLI"* ]]; then
echo "NLI"
# shellcheck disable=SC2155,SC2188
Expand All @@ -66,7 +81,10 @@ function main() {

if [[ ${nli_choice} == "CANCELLED" ]]; then
echo "skip NLI"
return 1
local NLI_exit_status
main "$@"
NLI_exit_status=$?
return $NLI_exit_status
fi
fi

Expand Down
19 changes: 19 additions & 0 deletions tests/desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
source commons.sh

function disable_test_install_xfce() {
run_pengwinsetup autoinstall GUI DESKTOP XFCE

package_installed "xfce4"
assertTrue "package xfce4 is not installed" "$?"
}

function disable_test_install_mate() {
run_pengwinsetup autoinstall GUI DESKTOP MATE

package_installed "mate-desktop-environment"
assertTrue "package mate is not installed" "$?"
}


source shunit2
2 changes: 2 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ if [ -z "${CIRCLE_NODE_TOTAL}" ]; then
run_test ./dotnet.sh
run_test ./brew.sh
run_test ./guilib.sh
run_test ./desktop.sh
run_test ./lamp.sh "10.6"
elif [[ ${CIRCLE_NODE_INDEX} == $((i++)) ]]; then
run_test ./pythonpi.sh
elif [[ ${CIRCLE_NODE_INDEX} == $((i++)) ]]; then
run_test ./desktop.sh
run_test ./lamp.sh "BUILTIN"
elif [[ ${CIRCLE_NODE_INDEX} == $((i++)) ]]; then
run_test ./fish.sh
Expand Down