Commit | Line | Data |
---|---|---|
59f0d218 FF |
1 | #!/system/bin/sh |
2 | ||
3 | set -e -u | |
4 | ||
5 | SCRIPTNAME=$0 | |
6 | show_usage () { | |
7 | echo "usage: $SCRIPTNAME [OPTIONS] <output-file>" | |
8 | echo "" | |
9 | echo "Take a photo and save it in a file. Valid options:" | |
10 | echo " -c, --camera <camera-id> the id of the camera to use" | |
11 | echo "See the termux-camera-info for getting information about available cameras" | |
12 | } | |
13 | ||
14 | PARAM_CAMERA="" | |
15 | PARAM_SIZE="" | |
16 | O=`getopt -l camera: -l help -l size -- c:hs: "$@"` | |
17 | eval set -- "$O" | |
18 | while true; do | |
19 | case "$1" in | |
20 | -c|--camera) PARAM_CAMERA="--ei camera $2"; shift 2;; | |
21 | -h|--help) show_usage; exit 0;; | |
22 | -s|--size) PARAM_SIZE="--ei size_index $2"; shift 2;; | |
23 | --) shift; break;; | |
24 | *) echo Error; exit 1;; | |
25 | esac | |
26 | done | |
27 | ||
28 | touch $1 | |
29 | FILE=`realpath $1` | |
30 | ||
31 | # Output is like: | |
32 | # Broadcasting: Intent { cmp=com.termux.extras/.SmsLister } | |
33 | # Broadcast completed: result=13, data="http://fornwall.net" | |
34 | OUTPUT=`LD_LIBRARY_PATH= am start --user 0 $PARAM_CAMERA $PARAM_SIZE --es file $FILE -n com.termux.extras/.PhotoActivity | grep result=1 | cut -d ' ' -f 4` | |
35 | ||
36 | if [ $? != "0" ]; then | |
37 | echo "ERROR: Failed, see logs" | |
38 | exit 1 | |
39 | fi |