Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only install local hostspot if selected #1323

Merged
merged 12 commits into from
Feb 14, 2020
70 changes: 43 additions & 27 deletions bin/oref0-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ case $i in
;;
-npm=*|--npm_install=*)
npm_option="${i#*=}"
;;
--hotspot=*)
hotspot_option="${i#*=}"
shift
;;
*)
Expand Down Expand Up @@ -471,6 +474,11 @@ if [[ -z "$DIR" || -z "$serial" ]]; then
echo
fi

if prompt_yn "Do you want to be able to set up a local-only wifi hotspot for offline monitoring?" N; then
HOTSPOT=true
else
HOTSPOT=false
fi

if [[ ! -z $BT_PEB ]]; then
prompt_and_validate BT_PEB "For Pancreabble enter Pebble mac id (i.e. AA:BB:CC:DD:EE:FF) hit enter to skip" validate_bt_peb
Expand Down Expand Up @@ -626,6 +634,9 @@ fi
if [[ ! -z "$radiotags" ]]; then
echo -n " --radiotags='$radiotags'" | tee -a $OREF0_RUNAGAIN
fi
if [[ ! -z "$hotspot_option" ]]; then
echo -n " --hotspot='$hotspot_option'" | tee -a $OREF0_RUNAGAIN
fi
echo; echo | tee -a $OREF0_RUNAGAIN
chmod 755 $OREF0_RUNAGAIN

Expand Down Expand Up @@ -913,33 +924,37 @@ if prompt_yn "" N; then
else
echo bluez version ${bluetoothdversion} already installed
fi
echo Installing prerequisites and configs for local-only hotspot
apt-get install -y hostapd dnsmasq || die "Couldn't install hostapd dnsmasq"
test ! -f /etc/dnsmasq.conf.bak && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
cp $HOME/src/oref0/headless/dnsmasq.conf /etc/dnsmasq.conf || die "Couldn't copy dnsmasq.conf"
test ! -f /etc/hostapd/hostapd.conf.bak && mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.bak
cp $HOME/src/oref0/headless/hostapd.conf /etc/hostapd/hostapd.conf || die "Couldn't copy hostapd.conf"
sed -i.bak -e "s|DAEMON_CONF=$|DAEMON_CONF=/etc/hostapd/hostapd.conf|g" /etc/init.d/hostapd
cp $HOME/src/oref0/headless/interfaces.ap /etc/network/ || die "Couldn't copy interfaces.ap"
cp /etc/network/interfaces /etc/network/interfaces.client || die "Couldn't copy interfaces.client"
if [ ! -z "$BT_MAC" ]; then
printf 'Checking for the bnep0 interface in the interfaces.client file and adding if missing...'
# Make sure the bnep0 interface is in the /etc/networking/interface
(grep -qa bnep0 /etc/network/interfaces.client && printf 'skipped.\n') || (printf '\n%s\n\n' "iface bnep0 inet dhcp" >> /etc/network/interfaces.client && printf 'added.\n')
fi
#Stop automatic startup of hostapd & dnsmasq
update-rc.d -f hostapd remove
update-rc.d -f dnsmasq remove
# Edit /etc/hostapd/hostapd.conf for wifi using Hostname
sed -i.bak -e "s/ssid=OpenAPS/ssid=${HOSTNAME}/" /etc/hostapd/hostapd.conf
# Add Commands to /etc/rc.local
# Interrupt Kernel Messages
if ! grep -q 'sudo dmesg -n 1' /etc/rc.local; then
sed -i.bak -e '$ i sudo dmesg -n 1' /etc/rc.local
fi
# Add to /etc/rc.local to check if in hotspot mode and turn back to client mode during bootup
if ! grep -q 'cp /etc/network/interfaces.client /etc/network/interfaces' /etc/rc.local; then
sed -i.bak -e "$ i if [ -f /etc/network/interfaces.client ]; then\n\tif grep -q '#wpa-' /etc/network/interfaces; then\n\t\tsudo ifdown wlan0\n\t\tsudo cp /etc/network/interfaces.client /etc/network/interfaces\n\t\tsudo ifup wlan0\n\tfi\nfi" /etc/rc.local || die "Couldn't modify /etc/rc.local"
if [[ ${hotspot_option,,} =~ "true" ]]; then
echo Installing prerequisites and configs for local-only hotspot
apt-get install -y hostapd dnsmasq || die "Couldn't install hostapd dnsmasq"
test ! -f /etc/dnsmasq.conf.bak && mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
cp $HOME/src/oref0/headless/dnsmasq.conf /etc/dnsmasq.conf || die "Couldn't copy dnsmasq.conf"
test ! -f /etc/hostapd/hostapd.conf.bak && mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.bak
cp $HOME/src/oref0/headless/hostapd.conf /etc/hostapd/hostapd.conf || die "Couldn't copy hostapd.conf"
sed -i.bak -e "s|DAEMON_CONF=$|DAEMON_CONF=/etc/hostapd/hostapd.conf|g" /etc/init.d/hostapd
cp $HOME/src/oref0/headless/interfaces.ap /etc/network/ || die "Couldn't copy interfaces.ap"
cp /etc/network/interfaces /etc/network/interfaces.client || die "Couldn't copy interfaces.client"
if [ ! -z "$BT_MAC" ]; then
printf 'Checking for the bnep0 interface in the interfaces.client file and adding if missing...'
# Make sure the bnep0 interface is in the /etc/networking/interface
(grep -qa bnep0 /etc/network/interfaces.client && printf 'skipped.\n') || (printf '\n%s\n\n' "iface bnep0 inet dhcp" >> /etc/network/interfaces.client && printf 'added.\n')
fi
#Stop automatic startup of hostapd & dnsmasq
update-rc.d -f hostapd remove
update-rc.d -f dnsmasq remove
# Edit /etc/hostapd/hostapd.conf for wifi using Hostname
sed -i.bak -e "s/ssid=OpenAPS/ssid=${HOSTNAME}/" /etc/hostapd/hostapd.conf
# Add Commands to /etc/rc.local
# Interrupt Kernel Messages
if ! grep -q 'sudo dmesg -n 1' /etc/rc.local; then
sed -i.bak -e '$ i sudo dmesg -n 1' /etc/rc.local
fi
# Add to /etc/rc.local to check if in hotspot mode and turn back to client mode during bootup
if ! grep -q 'cp /etc/network/interfaces.client /etc/network/interfaces' /etc/rc.local; then
sed -i.bak -e "$ i if [ -f /etc/network/interfaces.client ]; then\n\tif grep -q '#wpa-' /etc/network/interfaces; then\n\t\tsudo ifdown wlan0\n\t\tsudo cp /etc/network/interfaces.client /etc/network/interfaces\n\t\tsudo ifup wlan0\n\tfi\nfi" /etc/rc.local || die "Couldn't modify /etc/rc.local"
fi
else
echo Skipping local-only hotspot
fi
fi

Expand Down Expand Up @@ -992,6 +1007,7 @@ if prompt_yn "" N; then
cd $HOME/src/Logger
sudo apt-get install -y bluez-tools
sudo npm run global-install
cgm-transmitter $DEXCOM_CGM_TX_ID
touch /tmp/reboot-required
fi

Expand Down