Hi ogra,
I want to toggle the states of wifi and Bluetooth. so i prepared script
wlan="$(grep -l “phy” /sys/class/rfkill/rfkill*/name)"
if [[ -f “$wlan” ]]; then
wlan_state="$(echo “$wlan” | sed ‘s/name$/state/’)"
fi
bt="$(grep -l “hci” /sys/class/rfkill/rfkill*/name)"
if [[ -f “$bt” ]]; then
bt_state="$(echo “$bt” | sed ‘s/name$/state/’)"
fi
rfkill_curr_state="$(cat $wlan_state)"
if [ “$rfkill_curr_state” == “1” ]; then
rfkill_new_state=0
else
rfkill_new_state=1
fi
Now i wanted to run this as a script or command/daemon which should continuously monitor the states of wlan and BT.
my question is how to write a snapcraft.yaml for it.
i went through snapcraft.io documentation and read all the info but im very much confused what to mention in apps and parts section since i’m very new to this.
kindly help me on this
First of all make it clean shell and drop the double [ and double ] as well as the == … It is good practice to make your code POSIX compatible instead of using bash specifics (especially since /bin/sh is not necessarily bash on all systems out there and since bash uses several megabytes of extra ram over most other shells (like /bin/dash as used in ubuntu))
should theoretically work (after manually connecting the network-control interface).
Practically, when i tried to test it i noticed bug 1707612 which actually prevents you from using this interface … (lets see what @jdstrand has to say …)
Hi ogra,
i built snap and installed it manually. But i didnt find any change in rfkill state before and after installing the snap.
how to validate the installed snap or script?
well, even if it worked you’d most likely hit the same bug as i did … when you call your snapped command (indeed after manually connecting the network-control interface), are there any “DENIED” messages in syslog ?
Hi,
when i try to run using
laxman1234@localhost:~$ snap run toggle-rf-states
error: cannot find app “toggle-rf-states” in “toggle-rf-states”
snap info returned
commands:
toggle-rf-states.toggle
if i run toggle-rf-states.toggle im getting error as below
/snap/toggle-rf-states/x1/command-toggle.wrapper: 4: exec: /snap/toggle-rf-states/x1/…/toggle.sh: not found.
is anything wrong with my snapcraft.yaml?
apps:
toggle:
command: …/toggle.sh
plugs: [network, network-control]
Hi,
i made the above change then if i run
$sudo toggle-rf-states.toggle
grep: /sys/class/rfkill/rfkill0/name: Permission denied
grep: /sys/class/rfkill/rfkill1/name: Permission denied
/snap/toggle-rf-states/x1/toggle: 3: /snap/toggle-rf-states/x1/toggle.sh: [[: not found
grep: /sys/class/rfkill/rfkill0/name: Permission denied
grep: /sys/class/rfkill/rfkill1/name: Permission denied
/snap/toggle-rf-states/x1/toggle: 8: /snap/toggle-rf-states/x1/toggle.sh: [[: not found