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:
parent
ee04b0449b
commit
7803699e66
5 changed files with 36 additions and 7 deletions
|
@ -14,7 +14,27 @@ free_firmware_packages="firmware-ath9k-htc"
|
|||
|
||||
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()
|
||||
|
|
|
@ -27,7 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path)
|
|||
#=================================================
|
||||
|
||||
get__no_antenna() {
|
||||
if [[ $(iw_devices) == "" ]]
|
||||
if [[ $(unused_iw_devices) == "" ]]
|
||||
then
|
||||
echo "value: true"
|
||||
else
|
||||
|
@ -76,14 +76,15 @@ EOF
|
|||
}
|
||||
|
||||
get__wifi_device() {
|
||||
if [[ $(iw_devices) == "" ]]
|
||||
local unused_wifi_devices=$(unused_iw_devices)
|
||||
if [[ -z ${unused_wifi_devices} ]]
|
||||
then
|
||||
echo "choices: []"
|
||||
else
|
||||
cat << EOF
|
||||
choices:
|
||||
EOF
|
||||
for device in $(iw_devices | sed "s/|/ /g")
|
||||
for device in $unused_wifi_devices
|
||||
do
|
||||
echo " $device: $device"
|
||||
done
|
||||
|
|
|
@ -138,7 +138,7 @@ ip4_nat_prefix="10.${ip4_nat_prefix_index}.242"
|
|||
ip4_dns="${ip4_nat_prefix}.1"
|
||||
|
||||
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_channel=6
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
|
||||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
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
|
||||
|
@ -106,7 +107,10 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point"
|
|||
ynh_script_progression --message="Starting a systemd service..."
|
||||
|
||||
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
|
||||
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
||||
|
|
|
@ -19,6 +19,7 @@ app=$YNH_APP_INSTANCE_NAME
|
|||
firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree)
|
||||
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_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure)
|
||||
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..."
|
||||
|
||||
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/
|
||||
chown root: /etc/hostapd/$app/
|
||||
|
|
Loading…
Reference in a new issue