-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflashy
executable file
·198 lines (177 loc) · 5.72 KB
/
flashy
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#! /bin/bash
# Copyright (C) 2023 Ed Beroset <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# 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.
VERSION="1.2"
function showVersion {
echo "flashy v${VERSION}"
}
declare -a devices=("anthias" "bass" "beluga" "catfish" "dory" "firefish" "harmony" "hoki" "koi" "inharmony" "lenok" "minnow" "mooneye" "narwhal" "nemo" "pike" "ray" "smelt" "sparrow" "sparrow-mainline" "sprat" "sturgeon" "sawfish" "skipjack" "swift" "tetra" "triggerfish" "wren")
# point to where the images get built
defaultbuilddir="${ASTEROIDROOT}/build/tmp-glibc/deploy/images"
# assume we're not already in fastboot mode
fastboot=false
# assume we're not in dryrun mode
condecho=''
# do permanent install unless told otherwise
temp=false
# assume the watch is currently in SSH mode
useadb=false
# set empty builddir to start
builddir=''
# nightly url base directory
nightlyurl="https://release.asteroidos.org/nightlies"
function showHelp {
showVersion
cat << EOF
./flashy codename [option]
Deploy AsteroidOS binary image to a watch.
Available options:
-h or --help prints this help screen and quits
-a or --adb use ADB mode to reboot to fastboot
-b or --bootonly only push the boot image (implies temp; image already pushed)
-f or --fastboot watch is already in fastboot mode
-l or --local image files are in current working directory
-t or --temp perform a temporary install (watch is running WearOS)
-n or --nightly download image file(s) from nightly builds
-N or --dryrun don't actually flash, just show what would happen
-v or --version displays the version of this program
EOF
}
function warnIfNoBackup {
backupfile="original-${codename}.img"
if [ ! -f "${backupfile}" ] ; then
echo "Warning: permanent install being attempted without backup file ${backupfile} present"
echo "It is STRONGLY advised to make a backup before attempting a permanent install as with this command:"
echo "watch-util ${codename} save"
read -p "Continue anyway? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]] ; then
return
else
echo "Cancelling operation."
exit 1
fi
fi
}
if [ -z "$ASTEROIDROOT" ] ; then
echo "WARNING: ASTEROIDROOT environment variable not set"
fi
while [[ $# -gt 0 ]] ; do
case $1 in
-a|--adb)
useadb=true
shift
;;
-b|--bootonly)
bootonly=true
temp=true
shift
;;
-f|--fastboot)
fastboot=true
shift
;;
-h|--help)
showHelp
exit 1
;;
-l|--local)
builddir=$(pwd)
shift
;;
-n|--nightly)
nightly=true
builddir=$(pwd)
shift
;;
-N|--dryrun)
condecho="echo"
shift
;;
-t|--temp)
temp=true
shift
;;
-v|--version)
showVersion
shift
;;
*)
valid=false
for device in "${devices[@]}"; do
[[ "$1" == "${device}" ]] && valid=true
done
if [[ "${valid}" = true ]]; then
codename=$1
else
echo "Ignoring unknown option $1"
fi
shift
;;
esac
done
if [ "${valid}" = "false" ] ; then
echo "You must specify a valid device name."
showHelp
exit 0
fi
if [ "${builddir}" = "" ] ; then
builddir="${defaultbuilddir}/${codename}"
fi
bootfilename=zImage-dtb-${codename}.fastboot
imgfilename=asteroid-image-${codename}.rootfs.ext4
bootfile="${builddir}/${bootfilename}"
imgfile="${builddir}/${imgfilename}"
if [ "${nightly}" = "true" ] ; then
${condecho} wget -nc "${nightlyurl}/${codename}/${bootfilename}" -O "${bootfile}"
${condecho} wget -nc "${nightlyurl}/${codename}/${imgfilename}" -O "${imgfile}"
${condecho} wget -nc "${nightlyurl}/${codename}/SHA512SUMS" -O "SHA512SUMS"
${condecho} sha512sum --check SHA512SUMS || exit 1
fi
if [[ ! -f ${bootfile} ]] ; then
echo "Error: ${bootfile} does not exist"
exit 2
fi
if [[ ! -f ${imgfile} ]] ; then
echo "Error: ${imgfile} does not exist"
exit 2
fi
if [ "${temp}" != true ] ; then
${condecho} warnIfNoBackup
fi
if [ "${fastboot}" != "true" ] ; then
if [ "${temp}" = true ] ; then
if [ "${bootonly}" != true ] ; then
${condecho} adb push -p "${imgfile}" /sdcard/asteroidos.ext4 || exit 1
fi
${condecho} adb reboot bootloader || exit 1
else
if [ "${useadb}" = true ] ; then
${condecho} adb reboot bootloader || exit 1
else
${condecho} ssh [email protected] "reboot bootloader"
fi
fi
fi
if [ "${temp}" != true ] ; then
${condecho} fastboot oem unlock
${condecho} fastboot flash userdata "${imgfile}" || exit 1
${condecho} fastboot flash boot "${bootfile}" || exit 1
${condecho} fastboot continue
else
${condecho} fastboot boot "${bootfile}" || exit 1
fi
${condecho} ssh-keygen -R watch
${condecho} ssh-keygen -R 192.168.2.15