1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00

display unused wifi devices

This commit is contained in:
HgO 2023-08-23 10:24:43 +02:00
parent ee04b0449b
commit 7803699e66
5 changed files with 36 additions and 7 deletions

View file

@ -14,7 +14,27 @@ free_firmware_packages="firmware-ath9k-htc"
function iw_devices() function iw_devices()
{ {
echo -n $(/sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }') | tr ' ' '|' /sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }'
}
function used_iw_devices()
{
local app_shortname="${app%%__*}"
local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname)
# Remove this app from hotspot apps list
local other_hotspot_apps=$(grep -F -x -v $app <<< ${hotspot_apps})
for hotspot_app in ${other_hotspot_apps}; do
hotspot_wifi_device=$(ynh_app_setting_get --app=$hotspot_app --key=wifi_device)
if [[ -n ${hotspot_wifi_device} ]]; then
echo "${hotspot_wifi_device}"
fi
done
}
function unused_iw_devices()
{
# Only prints devices that are not in the list of used devices
iw_devices | grep -F -v -f <(used_iw_devices)
} }
function check_armbian_nonfree_conflict() function check_armbian_nonfree_conflict()

View file

@ -27,7 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
get__no_antenna() { get__no_antenna() {
if [[ $(iw_devices) == "" ]] if [[ $(unused_iw_devices) == "" ]]
then then
echo "value: true" echo "value: true"
else else
@ -76,14 +76,15 @@ EOF
} }
get__wifi_device() { get__wifi_device() {
if [[ $(iw_devices) == "" ]] local unused_wifi_devices=$(unused_iw_devices)
if [[ -z ${unused_wifi_devices} ]]
then then
echo "choices: []" echo "choices: []"
else else
cat << EOF cat << EOF
choices: choices:
EOF EOF
for device in $(iw_devices | sed "s/|/ /g") for device in $unused_wifi_devices
do do
echo " $device: $device" echo " $device: $device"
done done

View file

@ -138,7 +138,7 @@ ip4_nat_prefix="10.${ip4_nat_prefix_index}.242"
ip4_dns="${ip4_nat_prefix}.1" ip4_dns="${ip4_nat_prefix}.1"
hot_reload_usb_wifi_cards hot_reload_usb_wifi_cards
wifi_device=$(iw_devices | awk -F\| '{ print $1 }') wifi_device=$(unused_iw_devices | head -n 1)
wifi_secure=1 wifi_secure=1
wifi_channel=6 wifi_channel=6

View file

@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
service_name=$(ynh_app_setting_get --app=$app --key=service_name) service_name=$(ynh_app_setting_get --app=$app --key=service_name)
wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -106,7 +107,10 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point"
ynh_script_progression --message="Starting a systemd service..." ynh_script_progression --message="Starting a systemd service..."
hot_reload_usb_wifi_cards hot_reload_usb_wifi_cards
wifi_device=$(iw_devices | awk -F\| '{ print $1 }') if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then
wifi_device=$(unused_iw_devices | head -n 1)
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
fi
if [[ -z $wifi_device ]]; then if [[ -z $wifi_device ]]; then
ynh_app_setting_set --app=$app --key=service_enabled --value=0 ynh_app_setting_set --app=$app --key=service_enabled --value=0

View file

@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
service_name=$(ynh_app_setting_get --app=$app --key=service_name) service_name=$(ynh_app_setting_get --app=$app --key=service_name)
wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device)
wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid)
wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure)
wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase)
@ -201,7 +202,10 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Copying configuration..." ynh_script_progression --message="Copying configuration..."
hot_reload_usb_wifi_cards hot_reload_usb_wifi_cards
wifi_device=$(iw_devices | awk -F\| '{ print $1 }') if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then
wifi_device=$(unused_iw_devices | head -n 1)
ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
fi
mkdir -pm 0755 /etc/hostapd/$app/ mkdir -pm 0755 /etc/hostapd/$app/
chown root: /etc/hostapd/$app/ chown root: /etc/hostapd/$app/