From 79b1ef9892e9b61c747895336111ae3be2651626 Mon Sep 17 00:00:00 2001 From: hmk Date: Wed, 26 Oct 2022 20:42:59 +0200 Subject: [PATCH] Updated remoteoffice.sh and unlock_adb_device.sh --- remoteoffice.sh | 13 +++++++----- unlock_adb_device.sh | 48 +++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/remoteoffice.sh b/remoteoffice.sh index 7553ed9..d165417 100755 --- a/remoteoffice.sh +++ b/remoteoffice.sh @@ -6,24 +6,26 @@ set -x NMCONN="49088a1e-18c2-48aa-a664-f212eb83a727" # RDP DEF_RESOLUTION="1920x1080" -DRIVE="work,${HOME}/Documents/Work" +DRIVE="`xdg-user-dir DOCUMENTS`/Work" DOMAIN="$(pass show Work/AD-LOGIN | awk '/domain:/ {print $2}')" USER="$(pass show Work/AD-LOGIN | awk '/user:/ {print $2}')" REMOTE="$(pass show Work/AD-LOGIN | awk '/remote:/ {print $2}')" PASSWORD="$(pass show Work/AD-LOGIN | head -1)" +[[ ! -d "${DRIVE}" ]] && mkdir -p ${DRIVE} + rdp() { # resolve REMOTE to IPv4 before connecting in order to avoid IPv6 usage REMOTE=$(dig ${REMOTE} A +short) - # alternative to "dynamic-resolution" is "smart-sizing" if [ -z ${PASSWORD} ]; then PASWORD=$(zenity --entry --title="Password" \ --text="Enter your _password:" --hide-text) fi - xfreerdp /network:lan /gdi:hw +glyph-cache +fonts +aero \ + # alternative to "dynamic-resolution" is "smart-sizing" + xfreerdp /network:lan /gdi:hw /rfx +glyph-cache +fonts +aero \ /bpp:32 /size:${DEF_RESOLUTION} /dynamic-resolution \ - /audio-mode:0 /sound:sys:pulse /microphone:sys:pulse \ - /kbd:German /drive:${DRIVE} \ + /audio-mode:2 /sound:sys:pulse /microphone:sys:pulse \ + /kbd:German /drive:"`basename ${DRIVE}`,${DRIVE}" \ +auto-reconnect /auto-reconnect-max-retries:5 \ /d:${DOMAIN} /u:${USER} /v:${REMOTE} /p:${PASSWORD} zenity --question --title="Disconnect?" \ @@ -39,6 +41,7 @@ else while [ $(nmcli con show ${NMCONN} | awk '/GENERAL.STATE/ {print $2}') != "activated" ]; do sleep 1 done + sleep 3 rdp fi diff --git a/unlock_adb_device.sh b/unlock_adb_device.sh index 2f7544b..5800cf1 100755 --- a/unlock_adb_device.sh +++ b/unlock_adb_device.sh @@ -1,10 +1,6 @@ -#!/bin/bash +#!/bin/sh -#RESOLUTION="1280x720" -RESOLUTION="1920x1080" -VIDEODEV="/dev/video10" - -function unlock { +unlock() { ### Activates the screen and unlocks the phone # Reads the current screen state eturns any combination of ON/OFF and # LOCKED/UNLOCKED (i.e. OFF_LOCKED). @@ -12,23 +8,47 @@ function unlock { IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \ '/mScreenState/ {print $2}') # Emulate Power-Button press if screen is OFF. - [[ ${screenstate[0]} == "OFF" ]] && adb shell input keyevent 26 && \ + [ "${screenstate[0]}" == "OFF" ] && adb shell input keyevent 26 && \ echo Screen activated # Emulate Menu-button press if phone is locked. Requires the phone to # unlock without PIN or password. - [[ ${screenstate[1]} == "LOCKED" ]] && adb shell input keyevent 82 && \ + [ "${screenstate[1]}" == "LOCKED" ] && adb shell input keyevent 82 && \ echo Device unlocked } -function blank { - ### Blanks the screen after X seconds - sleep ${1} +blank() { + ### Blanks the screen (optionally wait X seconds) + [ -z "${1}" ] && sleep "${1}" IFS='_' read -ra screenstate <<< $(adb shell dumpsys nfc | awk -F'=' \ '/mScreenState/ {print $2}') - [[ ${screenstate[0]} == "ON" ]] && adb shell input keyevent 26 && \ + [ "${screenstate[0]}" == "ON" ] && adb shell input keyevent 26 && \ echo Screen deactivated } -# Unlock phone -unlock +run() { + # Unlock phone + unlock + # Start intent + [ -z "${1}" ] && APP="com.dev47apps.obsdroidcam" || APP="${1}" + adb shell am start -n "${APP}/.MainActivity" + blank 5 +} + +usage() { + echo "Usage: ${0} [-u|b] [-r INTENT] + + -u unlock device (default if no option is given) + -b blank device screen + -r INTENT unlock device, run given intent and blank device screen + -h this help" +} +while getopts ":ubr:h" opt; do + case "${opt}" in + u) unlock ;; + b) blank ;; + r) run "${OPTARG}" ;; + h) usage ;; + *) unlock ;; + esac +done