-
Notifications
You must be signed in to change notification settings - Fork 4
/
gf
executable file
·156 lines (127 loc) · 3.63 KB
/
gf
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
#!/bin/bash
# Julien Wajsberg <jwajsberg@mozilla.com>
# gf aka "gaia flash"
# easily flash your gaia applications
# show all run commands
#set -x
# stop at the first error
set -e
# some things to put text in bold
bold=`tput smso`
offbold=`tput rmso`
# saving where we are
initialpwd=$(pwd)
make_command="install-gaia"
#nit_dir="$(dirname /home/julien/bin/gf)"; target_dir="" finding where I am installed
# can't use readlink -f to stay compatible with MacOS X
init_dir="$(dirname "$0")"
target_dir="$(dirname "$(readlink "$0")")"
basedir="$(cd $init_dir && cd $target_dir && pwd -P)"
# parsing options
while getopts aopeh opt ; do
case $opt in
a)
flash_all=1
;;
o)
export GAIA_OPTIMIZE=1
;;
p)
production=1
;;
e)
production=0
;;
h)
echo "$(basename $0) [-a] [-o] [-h] [-e | -p] [appName]..."
echo " -a force flashing all gaia"
echo " -o optimize the build"
echo " -p force pushing to /system (production mode)"
echo " -e force pushing to /data (eng mode)"
echo " -h shows this help screen"
echo " appName the app(s) to flash"
echo "Without any appName, this script tries to figure in which directory you are to flash this app"
exit
;;
esac
done
# getting the other parameters
shift $(( OPTIND-1 ))
echo "Finding gaia base directory..."
while test ! -d .git -a ! $(pwd) == "/" ; do
cd ..
done
gaiabasepwd=$(pwd)
gaiabasedir=$(basename $gaiabasepwd)
if test "${gaiabasedir#gaia}" == "$gaiabasedir" ; then
echo "ERROR : please be inside your gaia directory"
exit 1
fi
echo Found $gaiabasepwd
echo "Checking for device..."
adb wait-for-device
if [ -z "$production" ] ; then
echo "Trying to find the device image mode"
if adb shell cat /data/local/webapps/webapps.json | grep -qs '"basePath": "/system' ; then
production=1
fi
fi
echo "Trying to find the device's name"
# note: adb shell getprop seems to end lines with \r which is not trimmed by bash
device_name=$(adb shell getprop ro.product.device | sed 's/\s*$//')
dpi_file="$basedir/devices/dpi/__default"
if [ -n "$device_name" ] ; then
echo "Found $device_name"
device_dpi_file="$basedir/devices/dpi/$device_name"
if [ -r "$device_dpi_file" ] ; then
dpi_file="$device_dpi_file"
fi
fi
dpi=$(cat "$dpi_file")
export GAIA_DEV_PIXELS_PER_PX=$dpi
if [ "$production" = "1" ] ; then
export GAIA_INSTALL_PARENT=/system/b2g
adb remount
else
export GAIA_INSTALL_PARENT=/data/local
fi
do_flash() {
appname="$1";
if [ -n "$appname" ] ; then
echo -n "Flashing ${bold}${appname}${offbold} only"
export BUILD_APP_NAME="$appname"
else
echo -n "Flashing ${bold}all${offbold} gaia"
fi
if [ "$production" = "1" ] ; then
echo -n ", in ${bold}production${offbold} mode"
else
echo -n ", in ${bold}eng${offbold} mode"
fi
if [ -n "$GAIA_OPTIMIZE" ] ; then
echo -n ", ${bold}optimizing${offbold}"
fi
if [ "$dpi" != "1" ] ; then
echo -n ", with ${bold}@${dpi}x${offbold} assets"
fi
echo
if [ -z "$appname" ] ; then
read -p "Is this correct ? Press Ctrl-C to abort"
fi
make ${make_command}
}
# In case the adb daemon was not started in root
adb root
echo "Trying to find what you want to flash"
if test -z "$flash_all" ; then
if test -n "$1" ; then
echo "Was defined on the command line: $*"
while test -n "$1" ; do
do_flash $1
shift
done
elif [[ ( "$initialpwd" == */$gaiabasedir/apps/* ) || ( "$initialpwd" == */$gaiabasedir/test_apps/* ) ]] ; then
gaia_subdir=${initialpwd##$gaiabasepwd}
do_flash $(echo $gaia_subdir | awk -F/ '{ print $3 }')
fi
fi