Advertisement
Guest User

Wearcap (v1) - CEnnis91

a guest
Nov 9th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.77 KB | None | 0 0
  1. #!/system/bin/sh
  2. # wearcap v1 - screencaps a Wear device from the phone
  3. # created by CEnnis91
  4.  
  5. VERSION=1
  6.  
  7. ADBKEY="/data/misc/adb/adb_keys"
  8. OUTDIR="/sdcard/Pictures/Screenshots"
  9. TSTAMP="+Screenshot_%Y-%m-%d-%H-%M-%S.png"
  10. TMPDIR="/data/local/tmp"
  11.  
  12. clear
  13. setprop service.adb.tcp.port 5555
  14. mkdir -p $OUTDIR $TMPDIR
  15.  
  16. echo "wearcap v$VERSION (screencap your Wear device) - created by CEnnis91"
  17. echo ""
  18.  
  19. if [ "$(whoami)" != "root" ]; then
  20.     echo "- You must be root to run wearcap."
  21.     exit 2
  22. fi
  23.  
  24. # take screenshots interactively
  25. wearcap() {
  26.     echo ""
  27.     echo "- Connection to your Wear device is complete!"
  28.     echo "- To screenshot press [SPACE], to exit press [X]."
  29.     echo "- Screenshots can be found in $OUTDIR."
  30.     echo ""
  31.  
  32.     while [ "$INPUT" != "x" ]; do
  33.         stty -echo
  34.         read -N 1 INPUT
  35.         stty echo
  36.  
  37.         # this will take a few seconds to take and send over
  38.         if [ "$INPUT" == "" ]; then
  39.             OUTPUT=$(date "$TSTAMP")
  40.             adb -s localhost:4444 shell screencap -p $TMPDIR/$OUTPUT > /dev/null 2>&1
  41.             adb -s localhost:4444 pull $TMPDIR/$OUTPUT $OUTDIR/$OUTPUT > /dev/null 2>&1
  42.             adb -s localhost:4444 shell rm -f $TMPDIR/$OUTPUT > /dev/null 2>&1
  43.  
  44.             if [ -e $OUTDIR/$OUTPUT ]; then
  45.                 echo "- Screenshot taken: $OUTPUT."
  46.             else
  47.                 echo "- It appears the screenshot was not created."
  48.                 echo "- Run $0 again to try to reconnect properly."
  49.                 exit 1
  50.             fi
  51.         fi
  52.     done
  53. }
  54.  
  55. if [ -e $TMPDIR/.android ]; then
  56.     localkey="$(cat $TMPDIR/.android/adbkey.pub)"
  57.     validkey=$(grep -s "$localkey" $ADBKEY)
  58. fi
  59.  
  60. if [ -n "$validkey" ]; then
  61.     echo "Preparing for screenshot..."
  62.     echo "- Make sure the screen is on during connection."
  63.     echo "- This will take a few seconds to connect."
  64.     echo "- Make sure the screen of your watch is on."
  65.  
  66.     adb kill-server > /dev/null 2>&1
  67.     HOME=$TMPDIR adb start-server > /dev/null 2>&1
  68.  
  69.     adb connect localhost > /dev/null 2>&1
  70.     sleep 2
  71.     adb forward tcp:4444 localabstract:/adb-hub > /dev/null 2>&1
  72.     adb connect localhost:4444 > /dev/null 2>&1
  73.     sleep 2
  74.  
  75.     wearcap
  76.     exit 0
  77. fi
  78.  
  79. # we need to give the user more time to authorize the RSA keys here
  80. echo "Initializing the environment first..."
  81. echo "- You will be asked to authorize two devices for ADB access."
  82. echo "- The first is this device, the second is your Wear device."
  83. echo "- Make sure the screen of your watch is on during this process."
  84. echo ""
  85.  
  86. adb kill-server
  87. HOME=$TMPDIR adb start-server
  88.  
  89. # authorize and connect to the phone
  90. adb connect localhost
  91. sleep 7
  92.  
  93. # authorize and connect to the watch
  94. adb forward tcp:4444 localabstract:/adb-hub
  95. adb connect localhost:4444
  96. sleep 7
  97.  
  98. devices=$(adb devices | grep "localhost.*device" | wc -l)
  99. if [ $devices -eq 2 ]; then
  100.     echo "- Success!"
  101.     wearcap
  102.     exit 0
  103. else
  104.     echo "- Failure!"
  105.     echo "- Run $0 again to try to reinitialize."
  106.     exit 1
  107. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement