Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
s-martin committed Nov 8, 2023
2 parents 0924bfe + 093cc61 commit 145ba20
Show file tree
Hide file tree
Showing 30 changed files with 659 additions and 2,593 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/components/controls/buttons_usb_encoder/ @jeripeierSBB
/components/synchronisation/sync-shared @AlvinSchiller
/scripts/installscripts/buster-install-default.sh @jeripeierSBB
/scripts/installscripts/buster-install-default-with-autohotspot.sh @jeripeierSBB
/scripts/helperscripts/setup_autohotspot.sh @Groovylein
14 changes: 11 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ jobs:
run: |
pip install -r requirements.txt
pytest --cov --cov-report xml
- name: Report to Coveralls
- name: Report to Coveralls (parallel)
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./components/gpio_control/coverage.xml
format: cobertura
parallel: true



finish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v1
with:
parallel-finished: true
#carryforward: "run-1,run-2"
2 changes: 1 addition & 1 deletion .github/workflows/test_docker_debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
debian_version_name: ['bullseye', 'buster']
debian_version_name: ['bullseye', 'buster', 'bookworm']
uses: ./.github/workflows/test_docker_debian_versionname_sub.yml
with:
runs_on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion ci/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install \
alsa-utils \
build-essential \
git \
iw \
locales \
sudo \
systemd \
wireless-tools \
wget \
wpasupplicant \
# install internally used packages here to speed up GitHub Action
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ After=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/autohotspot
ExecStart=%AUTOHOTSPOT_SCRIPT%
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
219 changes: 219 additions & 0 deletions misc/sampleconfigs/autohotspot.sh.stretch-default2-Hotspot.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
#!/bin/bash
#version 0.962-N/HS

#You may share this script on the condition all references to RaspberryConnect.com
#must be included in copies or derivatives of this script.

#A script to switch between a wifi network and a non internet routed Hotspot
#Works at startup or with a seperate timer or manually without a reboot
#Other setup required find out more at
#http://www.raspberryconnect.com

#Additions where made for the Phoniebox project
#https://github.com/MiczFlor/RPi-Jukebox-RFID

if [ $# -gt 0 ] ; then
if [ $# -eq 1 ] && [ "$1" == "--force-hotspot" ]; then
FORCE_HOTSPOT=1
else
echo "ignoring unrecognized parameter: $*"
fi
fi

NO_SSID='NoSSid'
ssidChk="$NO_SSID"

wifidev="wlan0" #device name to use. Default is wlan0.
#use the command: iw dev ,to see wifi interface name

IFSdef=$IFS
cnt=0
#These four lines capture the wifi networks the RPi is setup to use
wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=' '{ print $2 }' | sed 's/\r//g'| awk 'BEGIN{ORS=","} {print}' | sed 's/\"/''/g' | sed 's/,$//')
IFS=","
ssids=($wpassid)
IFS=$IFSdef #reset back to defaults


#Note:If you only want to check for certain SSIDs
#Remove the # in in front of ssids=('mySSID1'.... below and put a # infront of all four lines above
# separated by a space, eg ('mySSID1' 'mySSID2')
#ssids=('mySSID1' 'mySSID2' 'mySSID3')

#Enter the Routers Mac Addresses for hidden SSIDs, seperated by spaces ie
#( '11:22:33:44:55:66' 'aa:bb:cc:dd:ee:ff' )
mac=()

ssidsmac=("${ssids[@]}" "${mac[@]}") #combines ssid and MAC for checking

CreateAdHocNetwork()
{
echo "Creating Hotspot"
ip link set dev "$wifidev" down
ip a add %AUTOHOTSPOT_IP%/24 brd + dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -k "$wifidev" >/dev/null 2>&1
systemctl start dnsmasq
systemctl start hostapd
}

KillHotspot()
{
echo "Shutting Down Hotspot"
ip link set dev "$wifidev" down
systemctl stop hostapd
systemctl stop dnsmasq
ip addr flush dev "$wifidev"
ip link set dev "$wifidev" up
dhcpcd -n "$wifidev" >/dev/null 2>&1
}

CheckWifiUp()
{
echo "Checking WiFi connection ok"
sleep 20 #give time for connection to be completed to router
if ! wpa_cli -i "$wifidev" status | grep 'ip_address' >/dev/null 2>&1
then #Failed to connect to wifi (check your wifi settings, password etc)
echo 'Wifi failed to connect, falling back to Hotspot.'
wpa_cli terminate "$wifidev" >/dev/null 2>&1
CreateAdHocNetwork
fi
}

InitWPA() {
wpa_supplicant -B -i "$wifidev" -c /etc/wpa_supplicant/wpa_supplicant.conf >/dev/null 2>&1
}

CheckServices()
{
#After some system updates hostapd gets masked using Raspbian Buster, and above. This checks and fixes
#the issue and also checks dnsmasq is ok so the hotspot can be generated.
#Check Hostapd is unmasked and disabled
if (systemctl -all list-unit-files hostapd.service | grep "hostapd.service masked") >/dev/null 2>&1 ;then
systemctl unmask hostapd.service >/dev/null 2>&1
fi
if (systemctl -all list-unit-files hostapd.service | grep "hostapd.service enabled") >/dev/null 2>&1 ;then
systemctl disable hostapd.service >/dev/null 2>&1
systemctl stop hostapd >/dev/null 2>&1
fi
#Check dnsmasq is disabled
if (systemctl -all list-unit-files dnsmasq.service | grep "dnsmasq.service masked") >/dev/null 2>&1 ;then
systemctl unmask dnsmasq >/dev/null 2>&1
fi
if (systemctl -all list-unit-files dnsmasq.service | grep "dnsmasq.service enabled") >/dev/null 2>&1 ;then
systemctl disable dnsmasq >/dev/null 2>&1
systemctl stop dnsmasq >/dev/null 2>&1
fi
}

CheckDevice()
{
local j=0
while [ true ] #wait for wifi if busy, usb wifi is slower.
do
echo "Device availability check: try $j"
if [ $j -ge 5 ]; then
#if no wifi device,ie usb wifi removed, activate wifi so when it is
#reconnected wifi to a router will be available
echo "No wifi device connected"
InitWPA
exit 1
elif (iw dev "$wifidev" info 2>&1 >/dev/null) ; then
echo "wifi device available"
if (rfkill list wifi -rno HARD,SOFT | grep -i "unblocked.*unblocked") >/dev/null 2>&1 ; then
local wifidev_up=$(ip link show "$wifidev" up)
if [ -z "$wifidev_up" ]; then
echo "wifi is down. setting up"
ip link set dev "$wifidev" up
sleep 2
fi
return
else
echo "wifi is deactivated"
exit 0
fi
else
j=$((j + 1))
sleep 2
fi
done
}

FindSSID()
{
if [ -n "$FORCE_HOTSPOT" ]; then return; fi

#Check to see what SSID's and MAC addresses are in range
local i=0; j=0
while [ $i -eq 0 ]
do
scanreply=$(iw dev "$wifidev" scan ap-force 2>&1)
ssidreply=$(echo "$scanreply" | egrep "^BSS|SSID:")
echo "SSID availability check: try $j"
if [ $j -ge 5 ]; then
ssidreply=""
i=1
elif [ -z "$ssidreply" ] ; then
echo "Error scan SSID's: $scanreply"
j=$((j + 1))
sleep 2
else
echo "SSID's in range:"
echo "$ssidreply"
i=1
fi
done

for ssid in "${ssidsmac[@]}"
do
if (echo "$ssidreply" | grep "$ssid") >/dev/null 2>&1
then
#Valid SSid found, passing to script
echo "Valid SSID Detected, assesing Wifi status"
ssidChk=$ssid
return 0
fi
done
}

CheckSSID()
{
#Create Hotspot or connect to valid wifi networks
if [ "$ssidChk" != "$NO_SSID" ]
then
if systemctl status hostapd | grep "(running)" >/dev/null 2>&1
then #hotspot running and ssid in range
KillHotspot
echo "Hotspot Deactivated, Bringing Wifi Up"
InitWPA
CheckWifiUp
elif { wpa_cli -i "$wifidev" status | grep 'ip_address'; } >/dev/null 2>&1
then #Already connected
echo "Wifi already connected to a network"
else #ssid exists and no hotspot running connect to wifi network
echo "Connecting to the WiFi Network"
InitWPA
CheckWifiUp
fi
else #ssid or MAC address not in range
if systemctl status hostapd | grep "(running)" >/dev/null 2>&1
then
echo "Hostspot already active"
elif { wpa_cli status | grep "$wifidev"; } >/dev/null 2>&1
then
echo "Cleaning wifi files and Activating Hotspot"
wpa_cli terminate >/dev/null 2>&1
ip addr flush "$wifidev"
ip link set dev "$wifidev" down
rm -r /var/run/wpa_supplicant >/dev/null 2>&1
CreateAdHocNetwork
else #"No SSID, activating Hotspot"
CreateAdHocNetwork
fi
fi
}

CheckServices
CheckDevice
FindSSID
CheckSSID
Loading

0 comments on commit 145ba20

Please sign in to comment.