diff --git a/bin/oref0-setup.sh b/bin/oref0-setup.sh index 71d9d4921..f3823a178 100755 --- a/bin/oref0-setup.sh +++ b/bin/oref0-setup.sh @@ -114,6 +114,9 @@ case $i in ;; -npm=*|--npm_install=*) npm_option="${i#*=}" + ;; + --hotspot=*) + hotspot_option="${i#*=}" shift ;; *) @@ -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 @@ -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 @@ -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