Skip to content

Commit

Permalink
added test for autohotsppt installation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Oct 31, 2023
1 parent c13907a commit ce0e2e4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/installscripts/buster-install-default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,8 @@ autohotspot() {
sudo cp "${jukebox_dir}"/scripts/helperscripts/autohotspot.sh "${autohotspot_script}"
sudo sed -i "s|10.0.0.5|${AUTOHOTSPOTip}|g" "${autohotspot_script}"
sudo chmod +x "${autohotspot_script}"
sudo chown root:root "${autohotspot_script}"
sudo chmod 644 "${autohotspot_script}"

sudo cp "${jukebox_dir}"/misc/sampleconfigs/autohotspot.service.stretch-default2-Hotspot.sample "${autohotspot_service_path}"
sudo sed -i "s|%AUTOHOTSPOT_SCRIPT%|${autohotspot_script}|g" "${autohotspot_service_path}"
Expand Down
50 changes: 50 additions & 0 deletions scripts/installscripts/tests/test_installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,50 @@ verify_wifi_settings() {
check_service_enablement dhcpcd enabled
}

verify_autohotspot_settings() {
if [[ "$AUTOHOTSPOTconfig" == "YES" ]]; then
printf "\nTESTING autohotspot settings...\n\n"

local autohotspot_service="autohotspot.service"
local autohotspot_script="/usr/bin/autohotspot"

local dnsmasq_conf=/etc/dnsmasq.conf
local hostapd_conf=/etc/hostapd/hostapd.conf
local hostapd_deamon=/etc/default/hostapd
local dhcpcd_conf=/etc/dhcpcd.conf

check_file_contains_string "${AUTOHOTSPOTip}" "${autohotspot_script}"
local ip_without_last_segment=$(echo $AUTOHOTSPOTip | cut -d'.' -f1-3)
check_file_contains_string "dhcp-range=${ip_without_last_segment}.100,${ip_without_last_segment}.200,12h" "${dnsmasq_conf}"
check_file_contains_string "ssid=${AUTOHOTSPOTssid}" "${hostapd_conf}"
check_file_contains_string "wpa_passphrase=${AUTOHOTSPOTpass}" "${hostapd_conf}"
check_file_contains_string "country_code=${AUTOHOTSPOTcountryCode}" "${hostapd_conf}"
check_file_contains_string "DAEMON_CONF=\"${hostapd_conf}\"" "${hostapd_deamon}"
check_file_contains_string "nohook wpa_supplicant" "${dhcpcd_conf}"
check_file_contains_string "ExecStart=${AUTOHOTSPOT_SCRIPT}" "/etc/systemd/system/${autohotspot_service}"

local crontab_user=$(crontab -l 2>/dev/null)
if [[ ! $(echo "${crontab_user}" | grep -w "${autohotspot_script}") ]]; then
echo " ERROR: crontab for user not installed"
((failed_tests++))
fi
((tests++))

# check owner and permissions
check_chmod_chown 644 root root "/etc" "bin/autohotspot"
check_chmod_chown 644 root root "/etc" "dhcpcd.conf"
check_chmod_chown 644 root root "/etc" "hostapd/hostapd.conf"
check_chmod_chown 644 root root "/etc" "default/hostapd"
check_chmod_chown 664 root netdev "/etc" "dhcpcd.conf"
check_chmod_chown 644 root root "/etc/systemd/system" "${autohotspot_service} hostadp.service dnsmasq.service"

# check that the services are activ
check_service_enablement "${autohotspot_service}" enabled
check_service_enablement hostadp.service disabled
check_service_enablement dnsmasq.service disabled
fi
}

verify_apt_packages(){
local phpver="$(ls -1 /etc/php)"
local packages="samba
Expand All @@ -176,6 +220,7 @@ python3-spidev netcat alsa-utils"
local packages_raspberrypi="raspberrypi-kernel-headers"
local packages_spotify="libspotify-dev mopidy mopidy-mpd mopidy-local mopidy-spotify libspotify12
python3-cffi python3-ply python3-pycparser python3-spotify"
local packages_autohotspot="dnsmasq hostapd iw"

printf "\nTESTING installed packages...\n\n"

Expand All @@ -184,6 +229,10 @@ python3-cffi python3-ply python3-pycparser python3-spotify"
packages="${packages} ${packages_spotify}"
fi

if [[ "$AUTOHOTSPOTconfig" == "YES" ]]; then
packages="${packages} ${packages_autohotspot}"
fi

# check for raspberry pi packages only on raspberry pi's but not on test docker containers running on x86_64 machines
if [[ $(uname -m) =~ ^armv.+$ ]]; then
packages="${packages} ${packages_raspberrypi}"
Expand Down Expand Up @@ -337,6 +386,7 @@ main() {
if [[ "$WIFIconfig" == "YES" ]]; then
verify_wifi_settings
fi
verify_autohotspot_settings
verify_apt_packages
verify_pip_packages
verify_samba_config
Expand Down

0 comments on commit ce0e2e4

Please sign in to comment.