1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#!/bin/sh
#
# Screen capture of Mir devices
#
# Copyright (C) 2013 Canonical
#
# Authors: Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>
#
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# # details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301 USA
# TODO:
# - detect that it is running Mir and fallback to screencap if it is SF
set -eu
PICDIR=$(mktemp -d /tmp/$(basename $0).XXXXXX)
FBDEV=fb0
ADBOPTS=""
#CONVERTOPTS="-alpha off -resize 50%"
CONVERTOPTS="-alpha off"
SUPPORTED="maguro mako manta grouper"
LOCALPATH=$HOME"/Pictures"
FILENAME="device-`date +%Y-%m-%d-%H%M%S`.png"
FULLSIZE=$LOCALPATH/$FILENAME
THUMBNAIL=$LOCALPATH/thumb-$FILENAME
SVR="popey.com"
SVRPATH="~/public_html/phablet"
PROTO="http://"
PUBPATH="~alan/phablet"
WEBADDR=$PROTO$SVR/$PUBPATH/$FILENAME
cleanup() {
#
# Cleanup temporary files
#
[ -d "$PICDIR" ] && rm -Rf "$PICDIR"
}
trap cleanup EXIT INT QUIT ABRT PIPE TERM
usage() {
#
# Print usage and exit
#
cat <<EOF
Usage: $(basename $0) [OPTIONS...]
Dump /dev/$FBDEV from a touch device and write it to file
Options
-d Enable debug
-h This help
-s SERIAL Serial number of the device
EOF
exit 1
}
check_prerequisites() {
# Check list of required packages
cmds="adb convert"
okay=1
for cmd in $cmds; do
if ! type $cmd >/dev/null 2>&1; then
okay=0
pkg="$(dpkg -S usr/bin/$cmd|cut -d: -f1)"
echo "E: Command '$cmd' not found in path. Please install package '$pkg'."
fi
done
if [ $okay -ne 1 ]; then
echo "E: pre-requisites are not met. Exiting!"
exit 1
fi
}
get_device() {
# Get device name
device=$(adb $ADBOPTS shell getprop ro.cm.device)
echo "$device"|tr -d '\r'
}
get_mode() {
# Find graphics mode
size=$(adb $ADBOPTS shell head -1 /sys/devices/virtual/graphics/$FBDEV/modes| cut -d: -f2|cut -d 'p' -f1)
# Fallback to hardcoded values
#if ! echo "$size"|grep -qE '^\[0-9\]+x\[0-9\]+$' >/dev/null 2>&1; then
if ! echo "$size"|grep -qE '^[0-9]+x[0-9]+$' >/dev/null 2>&1; then
device="$(get_device)"
case "$device" in
maguro)
size=720x1280
;;
mako)
size=768x1280
;;
manta)
size=1600x2560
;;
grouper)
size=800x1280
;;
*)
size=""
echo "E: Device '$device' is not supported. Supported devives are: $SUPPORTED"
;;
esac
fi
echo $size
}
SHORTOPTS="hds:"
LONGOPTS="help,debug,serial:"
TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -- "$@")
eval set -- "$TEMP"
while true ; do
case "$1" in
-h|--help)
usage;;
-d|--debug)
set -x
shift;;
-s|--serial)
ADBOPTS="$ADBOPTS -s $2"
shift 2;;
--) shift;
break;;
*) usage;;
esac
done
check_prerequisites
# Set resolution and depth for device
depth=8
size="$(get_mode)"
if [ -z "$size" ]; then
device="$(get_device)"
echo "E: Device '$device' is not supported. Supported devives are: $SUPPORTED"
exit 1
fi
CONVERTOPTS="$CONVERTOPTS -depth $depth -size $size"
echo "I: Dumping $FBDEV ..."
adb $ADBOPTS shell "kill -SIGSTOP \$(pidof unity8)"
adb $ADBOPTS pull /dev/$FBDEV ${PICDIR}/fb
adb $ADBOPTS shell "kill -SIGCONT \$(pidof unity8)"
convert $CONVERTOPTS rgba:${PICDIR}/fb[0] $FULLSIZE
echo $FULLSIZE
#xdg-open $FULLSIZE 2>&1 > /dev/null &
scp $FULLSIZE $SVR:$SVRPATH
echo $WEBADDR
convert $FULLSIZE -resize 192x230 $THUMBNAIL
scp $THUMBNAIL $SVR:$SVRPATH
#xdg-open $WEBADDR
echo "I: Done"
|