Setup adhoc mode:

First revert Yun back to factory default (AP mode)

nano /root/setadhoc.sh
#!/bin/ash
uci set wireless.@wifi-iface[0].mode=adhoc
/sbin/uci commit wireless
wifi down; wifi up
chmod 755 /root/setadhoc.sh
/root/setadhoc.sh

backup system wide setting:

uci export > /root/adhoc.conf

whenever you need restore it:

uci import </root/adhoc.conf
reboot