-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi-wifi-config-pull
executable file
·109 lines (98 loc) · 3.28 KB
/
rpi-wifi-config-pull
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
#!/bin/bash
set -e # fail on error
###
# #%L
# **********************************************************************
# PROJECT : rpi-scripts
# FILENAME : rpi-wifi-config-pull
# **********************************************************************
#
# Copyright (C) 2015 Robert Savage
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###
echo
echo "******************************************************"
echo "******************************************************"
echo "** **"
echo "** THIS IS A CUSTOM SHELL SCRIPT FOR PULLING **"
echo "** A REMOTE COPY OF THE 'wpa_supplicant.conf' **"
echo "** WIFI CONFIGURATION FILE FROM A RASPBERRY PI. **"
echo "** TO THE LOCAL FILESYSTEM **"
echo "** **"
echo "******************************************************"
echo "******************************************************"
echo
# set Raspberry Pi host address
USERNAME=pi
HOST=$1
PORT=$2
# validate that a host argument was provided
if [ -z $HOST ]; then
echo "-------------------------------"
echo " MISSING RASPBERRY PI HOST ARG"
echo "-------------------------------"
echo "SYNTAX: ./rpi-auth {pi-host-address}"
echo
exit
fi
# allow custom port argument
if [ -z $PORT ]
then
PORT=22
fi
# display host information to user
echo "------------------------------"
echo " TARGET RASPBERRY PI HOST: "
echo "------------------------------"
echo " ADDRESS : $HOST"
echo " PORT : $PORT"
# SSH to the Raspberry Pi to stage the wifi config file to a location that we can SCP to
echo
echo "------------------------------"
echo " STAGING WIFI CONFIG FILE "
echo "------------------------------"
echo "(Note: You may need to enter the default Raspberry Pi password below if prompted)"
set -x
ssh -p $PORT $USERNAME@$HOST bash -c "'
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf ~/wpa_supplicant.conf
sudo chmod +rw ~/wpa_supplicant.conf
'"
set +x
# copy the remote 'wpa_supplicant.conf file to the local filesystem
echo
echo "------------------------------"
echo " FETCHING WIFI CONFIG FILE "
echo "------------------------------"
echo "(Note: You may need to enter the default Raspberry Pi password below if prompted)"
set -x
scp -P $PORT $USERNAME@$HOST:wpa_supplicant.conf wpa_supplicant.conf
set +x
# SSH to the Raspberry Pi to remove the staging file
echo
echo "------------------------------"
echo " COMPLETE WIFI CONFIG "
echo "------------------------------"
echo "(Note: You may need to enter the default Raspberry Pi password below if prompted)"
set -x
ssh -p $PORT $USERNAME@$HOST bash -c "'
rm ~/wpa_supplicant.conf
'"
set +x
# ... all done ...
echo
echo "------------------------------"
echo " FINISHED "
echo "------------------------------"
echo