-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_to_voxl.sh
executable file
·165 lines (140 loc) · 4.65 KB
/
deploy_to_voxl.sh
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
#!/bin/bash
################################################################################
# Copyright (c) 2022 ModalAI, Inc. All rights reserved.
#
# Installs the ipk or deb package on target.
# Requires the package to be built and an adb connection.
################################################################################
set -e
SSH_PWD="oelinux123"
print_usage(){
echo ""
echo " Deploy an ipk or deb package to VOXL over adb or ssh"
echo " You must run ./make_package.sh first to build the package."
echo ""
echo " Usage to push over adb:"
echo " ./deploy_to_voxl.sh"
echo " ./deploy_to_voxl.sh adb"
echo ""
echo " Usage to push over ssh:"
echo " if VOXL_IP env variable is set:"
echo " ./deploy_to_voxl.sh ssh"
echo ""
echo " manually specifying a full IP address:"
echo " ./deploy_to_voxl.sh ssh 192.168.1.123"
echo ""
echo " manually specifying last block of the IP"
echo " ./deploy_to_voxl.sh ssh 123"
echo ""
}
#check adb (default) or ssh or print help text
if [ "$#" -lt 1 ]; then
#no options = default adb
DEPLOY_MODE="ADB"
else
#Parse arg
case $1 in
"adb")
DEPLOY_MODE="adb"
;;
"ssh")
DEPLOY_MODE="ssh"
#check command line for push ip
if [ "$#" -gt 1 ]; then
if echo $2 | grep -xq "[0-9]*" ; then
#echo "Number"
SEND_IP=192.168.1.$2
elif echo $2 | grep -xq "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" ; then
#echo "Full IP"
SEND_IP=$2
else
echo "Invalid IP address: $2"
exit 1
fi
elif ! [ -z ${VOXL_IP+x} ]; then
SEND_IP="${VOXL_IP}"
else
echo "Did not find a VOXL_IP env variable,"
echo ""
echo "If you would like to push over ssh automatically,"
echo "please export VOXL_IP in your bashrc"
echo ""
read -p "Please enter an IP to push to:" SEND_IP
fi
;;
"h"|"-h"|"help"|"--help")
print_usage
exit 0
;;
*)
print_usage
exit 1
;;
esac
fi
# count package files in current directory
NUM_IPK=$(ls -1q *.ipk 2>/dev/null | wc -l)
NUM_DEB=$(ls -1q *.deb 2>/dev/null | wc -l)
if [[ $NUM_IPK -eq "0" && $NUM_DEB -eq "0" ]]; then
echo "ERROR: missing ipk and/or deb"
echo "run make_package.sh first"
exit 1
elif [[ $NUM_IPK -gt "1" || $NUM_DEB -gt "1" ]]; then
echo "ERROR: more than 1 ipk or deb file found"
echo "make sure there is at most one of each in the current directory"
exit 1
fi
DPKG_CHECK_STRING='command -v dpkg &> /dev/null; echo -n $?'
OPKG_CHECK_STRING='command -v opkg &> /dev/null; echo -n $?'
if [ "$DEPLOY_MODE" == "ssh" ]; then
if ! command -v sshpass &> /dev/null ;then
echo ""
echo "You do not have sshpass installed"
echo "Please install sshpass to use the install via ssh feature"
echo ""
exit 1
fi
echo "searching for ssh device"
until ping -c1 $SEND_IP &>/dev/null; do :; done
echo "checking VOXL for dpkg/opkg"
if sshpass -p oelinux123 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$SEND_IP "$DPKG_CHECK_STRING" 2>/dev/null | grep -q 0 ; then
echo "dpkg detected";
FILE=$(ls -1q $PACKAGE*.deb)
sshpass -p oelinux123 scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $FILE root@$SEND_IP:/data/$FILE &>/dev/null
sshpass -p oelinux123 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$SEND_IP "dpkg -i --force-downgrade --force-depends /data/$FILE" 2>/dev/null
elif sshpass -p oelinux123 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$SEND_IP "$OPKG_CHECK_STRING" 2>/dev/null | grep -q 0 ; then
echo "opkg detected";
FILE=$(ls -1q $PACKAGE*.ipk)
sshpass -p oelinux123 scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $FILE root@$SEND_IP:/data/$FILE &>/dev/null
sshpass -p oelinux123 ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$SEND_IP "opkg install --force-reinstall --force-downgrade --force-depends --force-overwrite /data/$FILE" 2>/dev/null
else
echo "ERROR neither dpkg nor opkg found on VOXL"
exit 1
fi
else
if ! command -v adb &> /dev/null ;then
echo ""
echo "You do not have adb installed"
echo "Please install adb to use the install via adb feature"
echo ""
exit 1
fi
echo "searching for ADB device"
adb wait-for-device
echo "checking VOXL for dpkg/opkg"
if adb shell "$DPKG_CHECK_STRING" | grep -q 0 ; then
echo "dpkg detected";
FILE=(*.deb)
adb push $FILE /data/$FILE
adb shell "dpkg -i --force-downgrade --force-depends /data/$FILE"
elif adb shell "$OPKG_CHECK_STRING" | grep -q 0 ; then
echo "opkg detected";
FILE=(*.ipk)
adb push $FILE /data/$FILE
adb shell "opkg install --force-reinstall --force-downgrade --force-depends --force-overwrite /data/$FILE"
else
echo "ERROR neither dpkg nor opkg found on VOXL"
exit 1
fi
fi
echo "DONE"