2
# This program is free software: you can redistribute it and/or modify it
3
# under the terms of the the GNU General Public License version 3, as
4
# published by the Free Software Foundation.
6
# This program is distributed in the hope that it will be useful, but
7
# WITHOUT ANY WARRANTY; without even the implied warranties of
8
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
9
# PURPOSE. See the applicable version of the GNU Lesser General Public
10
# License for more details.
12
# You should have received a copy of the GNU General Public License
13
# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
# Copyright (C) 2012 Canonical, Ltd.
25
Copies ACTIVE network manager connection into device
29
-s Specify the serial of the device to install (see adb $ADBOPTS devices)
30
-i Install openssh-server in chroot
31
-n Select network file
38
OPTION_NETWORK_FILE=""
40
while getopts "hin:s:" OPTION
48
OPTION_NETWORK_FILE="$OPTARG"
62
shift $(($OPTIND - 1))
64
NETWORK_MANAGER=/etc/NetworkManager/system-connections
66
find_active_network() {
67
wireless_adapter="$(nmcli -t -f device,type dev | egrep wireless | cut -d: -f1)"
68
network_active="$(nmcli -t -f name,devices,vpn con status | egrep $wireless_adapter | egrep ":no$"| cut -d: -f1)"
69
network_file=$(sudo grep "$network_active" $NETWORK_MANAGER/* |grep ssid | cut -d: -f1)
71
if [ -z "$network_active" ]
73
echo "No active wifi network connection, exiting"
79
if [ -z $OPTION_NETWORK_FILE ]; then
80
network_file=$(find_active_network)
82
network_file=$OPTION_NETWORK_FILE
85
if [ ! -f "$network_file" ]
87
echo "Network connection file \"$network_file\" cannot be read"
91
echo Network file is $network_file
94
sudo grep -v mac-address "$network_file" > $TMP_FILE
96
echo Provisioning network file to device
99
target_network_file=/data/ubuntu/$NETWORK_MANAGER/active_ws_connection.conf
100
adb $ADBOPTS push $TMP_FILE $target_network_file
101
adb $ADBOPTS shell "/system/bin/chmod 600 $target_network_file"
106
echo Network setup complete
108
if [ $OPTION_SSH -eq 1 ]; then
110
# Indentation is going to be ugly here
111
cat > $TMP_FILE << 'EOF'
113
export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
115
apt-get install --yes openssh-server
119
UBUNTU_ROOT="/data/ubuntu"
120
adb $ADBOPTS push $TMP_FILE $UBUNTU_ROOT/$TMP_FILE
121
adb $ADBOPTS shell chmod 755 $UBUNTU_ROOT/$TMP_FILE
122
adb $ADBOPTS shell chroot $UBUNTU_ROOT $UBUNTU_ROOT/$TMP_FILE
127
echo openssh-server install complete, to connect execute
128
echo adb $ADBOPTS forward tcp:PORT tcp:22
129
echo with a proper PORT, e.g.\; 8888