Skip to content

Commit

Permalink
Only install local hostspot if selected (#1323)
Browse files Browse the repository at this point in the history
* don't loop on CGM data changing less than 1 mg/dL/5m for 45m

* typofix

* fix merge conflict error

* update tests to not be too flat

* continue to low-temp normally on too-flat readings <= 60 mg/dL

* only install/setup hostapd/dnsmasq if desired (to avoid breaking wifi)

* typofix

* treat hotspot_option as a string that must be "true"

* set up xdrip-js with DEXCOM_CGM_TX_ID

* whitespace
  • Loading branch information
scottleibrand committed Feb 14, 2020
1 parent 38732f8 commit 236b82e
Showing 1 changed file with 42 additions and 27 deletions.
69 changes: 42 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

0 comments on commit 236b82e

Please sign in to comment.