Skip to content

Commit

Permalink
add check for autohotspot setup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Nov 19, 2023
1 parent 05123a3 commit d57c98f
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions installation/routines/setup_autohotspot.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/usr/bin/env bash

AUTOHOTSPOT_HOSTAPD_CONF_FILE="/etc/hostapd/hostapd.conf"
AUTOHOTSPOT_HOSTAPD_DAEMON_CONF_FILE="/etc/default/hostapd"
AUTOHOTSPOT_DNSMASQ_CONF_FILE="/etc/dnsmasq.conf"
AUTOHOTSPOT_DHCPD_CONF_FILE="/etc/dhcpcd.conf"

AUTOHOTSPOT_TARGET_PATH="/usr/bin/autohotspot"

_get_interface() {
# interfaces may vary
WIFI_INTERFACE=$(iw dev | grep "Interface"| awk '{ print $2 }')
WIFI_REGION=$(iw reg get | grep country | awk '{ print $2}' | cut -d: -f1)
}


_install_packages() {
sudo apt-get -y install hostapd dnsmasq

Expand All @@ -17,18 +23,18 @@ _install_packages() {
}

_configure_hostapd() {
HOSTAPD_CUSTOM_FILE="${INSTALLATION_PATH}"/resources/autohotspot/hostapd.conf
HOSTAPD_CONF_FILE="/etc/hostapd/hostapd.conf"
local HOSTAPD_CUSTOM_FILE="${INSTALLATION_PATH}"/resources/autohotspot/hostapd.conf

sed -i "s/WIFI_INTERFACE/${WIFI_INTERFACE}/g" "${HOSTAPD_CUSTOM_FILE}"
sed -i "s/AUTOHOTSPOT_PASSWORD/${AUTOHOTSPOT_PASSWORD}/g" "${HOSTAPD_CUSTOM_FILE}"
sed -i "s/WIFI_REGION/${WIFI_REGION}/g" "${HOSTAPD_CUSTOM_FILE}"
sudo cp "${HOSTAPD_CUSTOM_FILE}" "${HOSTAPD_CONF_FILE}"
sudo cp "${HOSTAPD_CUSTOM_FILE}" "${AUTOHOTSPOT_HOSTAPD_CONF_FILE}"

sudo sed -i "s@^#DAEMON_CONF=.*@DAEMON_CONF=\"${HOSTAPD_CONF_FILE}\"@g" /etc/default/hostapd
sudo sed -i "s@^#DAEMON_CONF=.*@DAEMON_CONF=\"${AUTOHOTSPOT_HOSTAPD_CONF_FILE}\"@g" "${AUTOHOTSPOT_HOSTAPD_DAEMON_CONF_FILE}"
}

_configure_dnsmasq() {
sudo tee -a /etc/dnsmasq.conf <<-EOF
sudo tee -a "${AUTOHOTSPOT_DNSMASQ_CONF_FILE}" <<-EOF
#AutoHotspot Config
#stop DNSmasq from using resolv.conf
no-resolv
Expand All @@ -42,7 +48,7 @@ EOF
_other_configuration() {
sudo mv /etc/network/interfaces /etc/network/interfaces.bak
sudo touch /etc/network/interfaces
echo nohook wpa_supplicant | sudo tee -a /etc/dhcpcd.conf
echo nohook wpa_supplicant | sudo tee -a "${AUTOHOTSPOT_DHCPD_CONF_FILE}"
}

_install_service_and_timer() {
Expand All @@ -52,9 +58,30 @@ _install_service_and_timer() {
}

_install_autohotspot_script() {
TARGET_PATH="/usr/bin/autohotspot"
sudo cp "${INSTALLATION_PATH}"/resources/autohotspot/autohotspot "${TARGET_PATH}"
sudo chmod +x "${TARGET_PATH}"
sudo cp "${INSTALLATION_PATH}"/resources/autohotspot/autohotspot "${AUTOHOTSPOT_TARGET_PATH}"
sudo chmod +x "${AUTOHOTSPOT_TARGET_PATH}"
}


_autohotspot_check () {
echo "Check AutoHotspot Installation" | tee /dev/fd/3

verify_apt_packages hostapd dnsmasq

check_service_enablement hostapd.service disabled
check_service_enablement dnsmasq.service disabled
check_service_enablement autohotspot.service enabled

verify_files_exists "/etc/cron.d/autohotspot"
verify_files_exists "${AUTOHOTSPOT_TARGET_PATH}"

verify_file_contains_string "${WIFI_INTERFACE}" "${AUTOHOTSPOT_HOSTAPD_CONF_FILE}"
verify_file_contains_string "${AUTOHOTSPOT_PASSWORD}" "${AUTOHOTSPOT_HOSTAPD_CONF_FILE}"
verify_file_contains_string "${WIFI_REGION}" "${AUTOHOTSPOT_HOSTAPD_CONF_FILE}"
verify_file_contains_string "${AUTOHOTSPOT_HOSTAPD_CONF_FILE}" "${AUTOHOTSPOT_HOSTAPD_DAEMON_CONF_FILE}"

verify_file_contains_string "${WIFI_INTERFACE}" "${AUTOHOTSPOT_DNSMASQ_CONF_FILE}"
verify_file_contains_string "nohook wpa_supplicant" "${AUTOHOTSPOT_DHCPD_CONF_FILE}"
}

setup_autohotspot() {
Expand All @@ -69,6 +96,7 @@ setup_autohotspot() {
_other_configuration
_install_autohotspot_script
_install_service_and_timer
_autohotspot_check

echo "DONE: setup_autohotspot"
}

0 comments on commit d57c98f

Please sign in to comment.