2016-02-05 20:47:41 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# Install the proper hostapd package and adjust the hostapd configuration
|
|
|
|
# accordingly.
|
|
|
|
|
2017-03-15 23:00:15 +01:00
|
|
|
## Default
|
|
|
|
WIFI_DEVICE="wlan0"
|
|
|
|
|
|
|
|
WIFI_CONFIG_PATH="/boot/wifi_card.conf"
|
|
|
|
|
2016-02-05 20:47:41 +01:00
|
|
|
PACKAGE_PATH="/prebuild/hostapd"
|
|
|
|
CONFIG_PATH="/opt/piratebox/conf/hostapd.conf"
|
2017-03-17 07:34:32 +01:00
|
|
|
PIRATEBOX_CONFIG_PATH="/opt/piratebox/conf/piratebox.conf"
|
2016-02-05 20:47:41 +01:00
|
|
|
|
2017-03-15 23:00:15 +01:00
|
|
|
## Only use if it is set
|
|
|
|
if test -e "${WIFI_CONFIG_PATH}" ; then
|
|
|
|
echo "Found wifi card config"
|
|
|
|
WIFI_DEVICE=$( head -n 1 "${WIFI_CONFIG_PATH}" | tr -d '\n' )
|
|
|
|
fi
|
|
|
|
|
|
|
|
hostap_interface=$( grep -e '^interface' "${CONFIG_PATH}" | sed -e 's|interface=||' )
|
2017-03-17 07:34:32 +01:00
|
|
|
piratebox_interface=$( grep -e '^INTERFACE' "${PIRATEBOX_CONFIG_PATH}" | \
|
|
|
|
sed -e 's|INTERFACE=||' -e 's|"||g' )
|
|
|
|
dnsmasq_interface=$( grep -e '^DNSMASQ_INTERFACE' "${PIRATEBOX_CONFIG_PATH}" | \
|
|
|
|
sed -e 's|DNSMASQ_INTERFACE=||' -e 's|"||g' )
|
|
|
|
|
|
|
|
sed -i -e "s|interface=$hostap_interface|interface=$WIFI_DEVICE|" "${CONFIG_PATH}"
|
2017-03-17 07:38:11 +01:00
|
|
|
|
|
|
|
#Only change piratebox interface if it is a wifi interface
|
|
|
|
if echo "$piratebox_interface" | grep -q "wlan" ; then
|
|
|
|
sed -i -e "s|INTERFACE=\"$piratebox_interface\"|INTERFACE=\"$WIFI_DEVICE\"|" \
|
|
|
|
"${PIRATEBOX_CONFIG_PATH}"
|
|
|
|
fi
|
|
|
|
if echo "$dnsmasq_interface" | grep -q "wlan" ; then
|
|
|
|
sed -i -e "s|DNSMASQ_INTERFACE=\"$dnsmasq_interface\"|DNSMASQ_INTERFACE=\"$WIFI_DEVICE\"|" \
|
|
|
|
"${PIRATEBOX_CONFIG_PATH}"
|
|
|
|
fi
|
2017-03-17 07:34:32 +01:00
|
|
|
|
2017-03-15 23:00:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Get pyhX device node
|
|
|
|
CARD_ID=$( cat /sys/class/net/"${WIFI_DEVICE}"/phy80211/index )
|
|
|
|
|
|
|
|
|
2016-02-05 20:47:41 +01:00
|
|
|
# Check if we have an nl80211 enabled device with AP mode, then we are done
|
2017-03-17 07:34:32 +01:00
|
|
|
if iw phy phy"${CARD_ID}" info | grep -q "* AP$"; then
|
2016-02-05 20:47:41 +01:00
|
|
|
echo "Found nl80211 device capable of AP mode..."
|
2017-03-15 23:00:15 +01:00
|
|
|
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-2"* > /dev/null
|
2016-02-05 20:47:41 +01:00
|
|
|
sed -i 's/^#driver=nl80211/driver=nl80211/' "${CONFIG_PATH}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-03-15 23:00:15 +01:00
|
|
|
#Get driver name
|
|
|
|
DRIVER_NAME=$( ls -1 /sys/class/net/"${WIFI_DEVICE}"/device/driver/module/drivers/ )
|
|
|
|
|
2016-02-05 20:47:41 +01:00
|
|
|
# Check for r8188eu enabled device
|
2017-03-15 23:00:15 +01:00
|
|
|
if echo "$DRIVER_NAME" | grep -q "r8188eu:"; then
|
2016-02-05 20:47:41 +01:00
|
|
|
echo "Found r8188eu enabled device..."
|
2017-03-15 23:00:15 +01:00
|
|
|
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-8188eu-"* > /dev/null
|
2016-02-05 20:47:41 +01:00
|
|
|
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-03-15 23:00:15 +01:00
|
|
|
|
2016-02-05 20:47:41 +01:00
|
|
|
# Check for rtl8192cu enabled device
|
2017-03-15 23:00:15 +01:00
|
|
|
if echo "$DRIVER_NAME" | grep -q "rtl8192cu"; then
|
2016-02-05 20:47:41 +01:00
|
|
|
echo "Found rtl8192cu enabled device..."
|
2017-03-15 23:00:15 +01:00
|
|
|
pacman --noconfirm -U --needed "${PACKAGE_PATH}/hostapd-8192cu-"* > /dev/null
|
2016-02-05 20:47:41 +01:00
|
|
|
sed -i 's/^driver=nl80211/#driver=nl80211/' "${CONFIG_PATH}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Could not find an AP enabled WiFi card..."
|
|
|
|
|
|
|
|
# Try to connect to Wifi if wpa_supplicant.conf is available.
|
|
|
|
if [ -f /boot/wpa_supplicant.conf ]; then
|
2017-03-17 22:39:32 +01:00
|
|
|
/opt/piratebox/rpi/bin/run_client.sh
|
|
|
|
exit 1
|
|
|
|
# Exit =! 0 will result in not starting piratebox service
|
2016-02-05 20:47:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|