Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[ebuild] Wirelessctl - save & restore BT/WLAN state
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
rem5
n00b
n00b


Joined: 12 Oct 2005
Posts: 71
Location: Lille - France

PostPosted: Sun Dec 09, 2007 6:10 pm    Post subject: [ebuild] Wirelessctl - save & restore BT/WLAN state Reply with quote

I wrote a little script to save the states of the bluetooth and wlan interface at shutdown and to restore theses states at boot.

It's made for my asus laptop but I try to make it generic.

If you find mistakes or things like that...please let me know

wirelessctl-0.0.1.ebuild
Code:

# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

DESCRIPTION="Wirelessctl"
HOMEPAGE=""
SRC_URI=""

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

DEPEND=""


src_install() {
   newconfd "${FILESDIR}/wirelessctl.conf" wirelessctl
   newinitd "${FILESDIR}/wirelessctl.rc" wirelessctl
}

pkg_postinst() {
   echo
   elog "To take advantage of the init script, and automate the process of"
   elog "storing and restoring bluetooth and wlan interface you should"
   elog "add wirelessctl to the boot runlevel. You can do this as"
   elog "root like so:"
   elog "   # rc-update add wirelessctl boot"
   echo
}


wirelessctl.conf
Code:

# RESTORE_ON_START:
# Do you want to restore your wireless settings ?
# no - Do not restore state
# yes - Restore state

RESTORE_ON_START="no"

# SAVE_ON_STOP:
# Do you want to save changes made to your wireless settings ?
# no - Do not save state
# yes - Save state

SAVE_ON_STOP="no"


# BLUETOOTH

# Do you have a bluetooth adapter ?
# no - no bluetooth adapter present
# yes - bluetooth adapter present
BT="no"

# Path where we can test if bluetooth adapter is active (test if : 0 or 1)
BT_TEST_PATH=""

# Command(s) to start the bluetooth adapter
BT_START_CMD=""

# Command(s) to stop the bluetooth adapter
BT_STOP_CMD=""


# WLAN

# Do you have a wlan adapter ?
# no - no wlan adapter present
# yes - wlan adapter present
WLAN="no"

# Path where we can test if wlan adapter is active (test if : 0 or 1)
WLAN_TEST_PATH=""

# Command(s) to start the wlan adapter
WLAN_START_CMD=""

# Command(s) to stop the wlan adapter
WLAN_STOP_CMD=""


wirelessctl.rc
Code:

#!/sbin/runscript
# Copyright 2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

wirelessstatedir=/var/lib/wirelessctl/

opts="save restore start_bt stop_bt start_wlan stop_wlan"

depend() {
   need localmount
}

restore() {
   if [ "$BT" = "yes" ] && [ -e "$wirelessstatedir/bt.state" ] ; then
      if [ "$(cat $wirelessstatedir/bt.state)" = "0" ]; then
         stop_bt
      else
         if [ "$(cat $wirelessstatedir/bt.state)" = "1" ]; then
            start_bt
         fi
      fi
   fi

   if [ "$WLAN" = "yes" ] && [ -e "$wirelessstatedir/wlan.state" ] ; then
      if [ "$(cat $wirelessstatedir/wlan.state)" = "0" ]; then
         stop_wlan
      else
         if [ "$(cat $wirelessstatedir/wlan.state)" = "1" ]; then
            start_wlan
         fi
      fi
   fi
}

save() {
   if [ ! -d "${wirelessstatedir}" ] ; then
      mkdir -p "${wirelessstatedir}"
   fi

   if [ "$BT" = "yes" ] ; then
      if [ ! -e "$wirelessstatedir/bt.state" ] ; then
         touch "$wirelessstatedir/bt.state"
      fi

      if [ "$(cat "$BT_TEST_PATH")" = "0" ]; then
         echo "0" > "$wirelessstatedir/bt.state"
      else
         if [ "$(cat "$BT_TEST_PATH")" = "1" ]; then
            echo "1" > "$wirelessstatedir/bt.state"
         fi
      fi
   fi

   if [ "$WLAN" = "yes" ] ; then
      if [ ! -e "$wirelessstatedir/wlan.state" ] ; then
         touch "$wirelessstatedir/wlan.state"
      fi

      if [ "$(cat "$WLAN_TEST_PATH")" = "0" ]; then
         echo "0" > "$wirelessstatedir/wlan.state"
      else
         if [ "$(cat "$WLAN_TEST_PATH")" = "1" ]; then
            echo "1" > "$wirelessstatedir/wlan.state"
         fi
      fi
   fi
}   

start_bt () {
   su -c "$BT_START_CMD"
}

stop_bt () {
   su -c "$BT_STOP_CMD"
}

start_wlan () {
   su -c "$WLAN_START_CMD"
}

stop_wlan () {
   su -c "$WLAN_STOP_CMD"
}


start() {
   if [ "$RESTORE_ON_START" = "yes" ] ; then
      restore
   fi
   eend 0
}

stop() {
   if [ "$SAVE_ON_STOP" = "yes" ] ; then
      save
   fi
}





For example here is my conf for my ASUS laptop.

Code:

/# RESTORE_ON_START:
# Do you want to restore your wireless settings ?
# no - Do not restore state
# yes - Restore state

RESTORE_ON_START="yes"

# SAVE_ON_STOP:
# Do you want to save changes made to your wireless settings ?
# no - Do not save state
# yes - Save state

SAVE_ON_STOP="yes"


# BLUETOOTH

# Do you have a bluetooth adapter ?
# no - no bluetooth adapter present
# yes - bluetooth adapter present
BT="yes"

# Path where we can test if bluetooth adapter is active (test if : 0 or 1)
BT_TEST_PATH="/sys/devices/platform/asus-laptop/bluetooth"

# Command(s) to start the bluetooth adapter
BT_START_CMD="echo "1" > "/sys/devices/platform/asus-laptop/bluetooth""

# Command(s) to stop the bluetooth adapter
BT_STOP_CMD="echo "0" > "/sys/devices/platform/asus-laptop/bluetooth""


# WLAN

# Do you have a wlan adapter ?
# no - no wlan adapter present
# yes - wlan adapter present
WLAN="yes"

# Path where we can test if wlan adapter is active (test if : 0 or 1)
WLAN_TEST_PATH="/sys/devices/platform/asus-laptop/wlan"

# Command(s) to start the wlan adapter
WLAN_START_CMD="echo "1" > "/sys/devices/platform/asus-laptop/wlan" && modprobe iwl3945"

# Command(s) to stop the wlan adapter
WLAN_STOP_CMD="echo "0" > "/sys/devices/platform/asus-laptop/wlan" && modprobe -r iwl3945"



It is poorly tested for now.....


edit : [12/24/2007] corrected copy/paste mistake :evil:
edit : [10/13/2008] works perfectly as far as I know, you shouldn't experience too many weird effect :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum