From bdd0e2e138024eb9ed311af60d265a92bea7d15a Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Mon, 9 Nov 2020 10:06:39 -0500 Subject: [PATCH] Add debug feature --- README.md | 3 +++ bin/winapps | 48 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 08f3738..4843a81 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,12 @@ You will need to create a `~/.config/winapps/winapps.conf` configuration file wi RDP_USER="MyWindowsUser" RDP_PASS="MyWindowsPassword" #RDP_IP="192.168.123.111" +#DEBUG="true" ``` If you are using Option 2 below with a pre-existing non-KVM RDP server, you can use the `RDP_IP` to specify it's location. If you are running a VM in KVM with NAT enabled, leave `RDP_IP` commented out and WinApps will auto-detect the right local IP. +If you enable `DEBUG`, a log will be created on each application start in `~/.local/share/winapps/winapps.log`. + ### Option 1 - Running KVM You can refer to the [KVM](https://www.linux-kvm.org) documentation for specifics, but the first thing you need to do is set up a Virtual Machine running Windows 10 Professional (or any version that supports RDP). Fist, clone WinApps and install KVM and FreeRDP: ``` bash diff --git a/bin/winapps b/bin/winapps index 0066d08..29ac77c 100755 --- a/bin/winapps +++ b/bin/winapps @@ -1,16 +1,37 @@ #!/usr/bin/env bash DIR="$(dirname "$(readlink -f "$0")")" +RUN="$(date)-${RANDOM}" -if [ -f /tmp/winapps ]; then - LAST_RAN=$(stat -t -c %Y /tmp/winapps) - touch /tmp/winapps - THIS_RUN=$(stat -t -c %Y /tmp/winapps) +if [ ! -d "${HOME}/.local/share/winapps" ]; then + mkdir -p "${HOME}/.local/share/winapps" +fi + +if [ -f "${HOME}/.config/winapps/winapps.conf" ]; then + . "${HOME}/.config/winapps/winapps.conf" +else + . "${HOME}/.winapps" +fi + +function dprint() { + if [ "${DEBUG}" = "true" ]; then + echo "[${RUN}] ${1}" >> "${HOME}/.local/share/winapps/winapps.log" + fi +} + +dprint "START" + +if [ -f "${HOME}/.local/share/winapps/run" ]; then + LAST_RAN=$(stat -t -c %Y "${HOME}/.local/share/winapps/run") + dprint "LAST_RAN:${LAST_RAN}" + touch "${HOME}/.local/share/winapps/run" + THIS_RUN=$(stat -t -c %Y "${HOME}/.local/share/winapps/run") + dprint "THIS_RUN:${THIS_RUN}" if (( $THIS_RUN - $LAST_RAN < 2 )); then exit fi else - touch /tmp/winapps + touch "${HOME}/.local/share/winapps/run" fi if [ -z "$(which xfreerdp)" ]; then @@ -24,12 +45,6 @@ if [ ! -f "${HOME}/.config/winapps/winapps.conf" ] && [ ! -f "${HOME}/.winapps" exit fi -if [ -f "${HOME}/.config/winapps/winapps.conf" ]; then - . "${HOME}/.config/winapps/winapps.conf" -else - . "${HOME}/.winapps" -fi - if [ -z "${RDP_IP}" ]; then if [ -z "$(groups |grep libvirt)" ]; then echo "You are not a member of the libvirt group. Run the below then reboot." @@ -46,14 +61,23 @@ if [ -z "${RDP_IP}" ]; then RDP_IP=${RDP_IP%%\/*} fi +dprint "1:${1}" +dprint "2:${2}" +dprint "@:${@}" + if [ "${1}" = "windows" ]; then xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} /dynamic-resolution +auto-reconnect +home-drive /wm-class:"Microsoft Windows" 1> /dev/null 2>&1 & elif [ "${1}" != "install" ]; then + dprint "DIR:${DIR}" . "${DIR}/../apps/${1}/info" if [ -n "${2}" ]; then + dprint "HOME:${HOME}" FILE=$(echo "${2}" | sed 's|'"${HOME}"'|\\\\tsclient\\home|;s|/|\\|g;s|\\|\\\\|g') + dprint "FILE:${HOME}" xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} +auto-reconnect +home-drive -wallpaper /span /wm-class:"${FULL_NAME}" /app:"${WIN_EXECUTABLE}" /app-icon:"${DIR}/../apps/${1}/icon.svg" /app-cmd:"\"${FILE}\"" 1> /dev/null 2>&1 & else xfreerdp /u:"${RDP_USER}" /p:"${RDP_PASS}" /v:${RDP_IP} +auto-reconnect +home-drive -wallpaper /span /wm-class:"${FULL_NAME}" /app:"${WIN_EXECUTABLE}" /app-icon:"${DIR}/../apps/${1}/icon.svg" 1> /dev/null 2>&1 & fi -fi \ No newline at end of file +fi + +dprint "END"