HowTo SimpleToggles

'''*** Important note: This article is no longer up to date with 2.2006 'scirocco' *****

All *.desktop placed under /usr/share/applications/hildon Menu structure moved into xml file /home/user/.osso/menus/applications.menu

***** end of important note *****

**Updated for 2.2006 Scirocco:'''

I've managed to add some .sh menu items, but they are not toggle-like, since /usr/share/applications/hildon not writable for user by default, and I don't want to lower local security level by setting access rights to 777. I see no point in such switches since they preserve it's state after reboot regardless of real device state.

This one is used to switch between USB Networking and USB Mass Storage modes.

/usr/share/applications/hildon/usbnetoff.desktop
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Deactivate USB net
Comment=Turn off USB net
Exec=/usr/local/bin/usbnet_deactivate.sh
Icon=terminal
Terminal=false
Type=Application
Categories=System;
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
/usr/share/applications/hildon/usbneton.desktop

{{{Entry Encoding=UTF-8 Version=1.0 Name=Activate USB net Comment=Turn on USB net Exec=/usr/local/bin/usbnet_activate.sh Icon=terminal Terminal=false Type=Application Categories=System; X-HildonDesk-ShowInToolbar=true X-Osso-Type=application/x-executable}}}

/usr/local/bin/usbnet_deactivate.sh

{{{#!/bin/sh sudo /etc/init.d/usbnet stop echo USB Networking Disabled}}}

/usr/local/bin/usbnet_activate.sh

{{{#!/bin/sh sudo /etc/init.d/usbnet start echo USB Networking Enabled}}}

Additions to /etc/sudoers

/!\ Warning! Be very careful editing the /etc/sudoers file. Any typo will make you unable to log in as root again, and will break a lot of functionality in your device. Use great caution here!

user ALL = NOPASSWD: /etc/init.d/usbnet start
user ALL = NOPASSWD: /etc/init.d/usbnet stop
/etc/init.d/usbnet

Taken from original "[USBnetworkingWinXP"] article

#! /bin/sh
#
# Startup script for USBnet (networking, instead of USB Mass Storage behaviour)
# Author: Michael Mlivoncic

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=usbnet
DESC="USB Networking for Nokia 770"
INITFILE=/etc/init.d/$NAME

case "$1" in
start)
        USBNET="`lsmod | grep g_ether`"
        if [ "$USBNET" = "" ]
        then
           echo "entering Ethernet via USB mode (g_ether)..."
           insmod /mnt/initfs/lib/modules/current/g_ether.ko
           echo "waiting, then starting up the usb0.."
           sleep 1
           /sbin/ifup usb0
        else
          echo "already in Ethernet-via-USB mode..."
          echo "try ping 192.168.2.15"
        fi
        ;;
stop)
         echo "switching back to USB Mass Storage mode..."
         echo "removing module g_ether"
         /sbin/ifdown usb0
         sleep 2
         rmmod g_ether
        ;;
*)
        printf "Usage: $INITFILE {start|stop}\n" >&2
        exit 1
        ;;
esac

exit 0

Use Control Panel -> Task Navigator -> Organize to place this items to desirable menu.

Attention: Use USB mode toggles when USB cable switched off!

Here goes original OS2005 article:

I'm making a number of assumptions in this document, and you will of course need root, though parts of this may be done without root.

Add the following to /etc/sudoers (this assumes your swapfile is /media/mmc1/swapfile and you linked dropbear-server in /sbin/)

user ALL = NOPASSWD: /sbin/dropbear-server start
user ALL = NOPASSWD: /sbin/dropbear-server stop
user ALL = NOPASSWD: /sbin/swapon /media/mmc1/swapfile
user ALL = NOPASSWD: /sbin/swapoff /media/mmc1/swapfile

/!\ Warning! Be very careful editing the /etc/sudoers file. Any typo will make you unable to log in as root again, and will break a lot of functionality in your device. Use great caution here!

You will need to create most of these directories and files as root. You must chown the files to user when done.

/usr/local/bin/ssh_activate.sh

{{{

!/bin/sh

sudo dropbear-server start echo SSH Enabled mv /etc/others-menu/1370_System/0001_sshoff.hidden /etc/others-menu/1370_System/0001_sshoff.desktop mv /etc/others-menu/1370_System/0001_sshon.desktop /etc/others-menu/1370_System/0001_sshon.hidden }}}

/usr/local/bin/ssh_deactivate.sh

{{{

!/bin/sh

sudo dropbear-server stop echo SSH Disabled mv /etc/others-menu/1370_System/0001_sshon.hidden /etc/others-menu/1370_System/0001_sshon.desktop mv /etc/others-menu/1370_System/0001_sshoff.desktop /etc/others-menu/1370_System/0001_sshoff.hidden }}}

/usr/local/bin/swap_activate.sh

{{{

!/bin/sh

if |-f /media/mmc1/swapfile then

if |!sudo swapon /media/mmc1/swapfile/h1>

then

            sudo swapon /media/mmc1/swapfile
            echo Swap Enabled
            mv /etc/others-menu/1370_System/0000_swapoff.hidden /etc/others-menu/1370_System/0000_swapoff.desktop
            mv /etc/others-menu/1370_System/0000_swapon.desktop /etc/others-menu/1370_System/0000_swapon.hidden

fi

fi }}}

/usr/local/bin/swap_deactivate.sh

{{{

!/bin/sh

if |-f /media/mmc1/swapfile then

if |!sudo swapoff /media/mmc1/swapfile/h1>

then

            sudo swapoff /media/mmc1/swapfile
            echo Swap Disabled
            mv /etc/others-menu/1370_System/0000_swapon.hidden /etc/others-menu/1370_System/0000_swapon.desktop
            mv /etc/others-menu/1370_System/0000_swapoff.desktop /etc/others-menu/1370_System/0000_swapoff.hidden

fi

fi }}}

Create the following in /etc/others-menu/1370_System

0000_swapon.desktop

{{{ Entry Encoding=UTF-8 Version=1.0 Name=Activate swap Comment=Turn on swap Exec=/usr/local/bin/swap_activate.sh Icon=terminal Terminal=false Type=Application Categories=System; X-HildonDesk-ShowInToolbar=true X-Osso-Type=application/x-executable }}}

0000_swapoff.hidden

{{{ Entry Encoding=UTF-8 Version=1.0 Name=Deactivate Swap Comment=Turn off swap Exec=/usr/local/bin/swap_deactivate.sh Icon=terminal Terminal=false Type=Application Categories=System; X-HildonDesk-ShowInToolbar=true X-Osso-Type=application/x-executable }}}

0001_sshon.desktop

{{{ Entry Encoding=UTF-8 Version=1.0 Name=Activate Dropbear Comment=Turn on Dropbear Exec=/usr/local/bin/ssh_activate.sh Icon=terminal Terminal=false Type=Application Categories=System; X-HildonDesk-ShowInToolbar=true X-Osso-Type=application/x-executable }}}

0001_sshoff.hidden

{{{ Entry Encoding=UTF-8 Version=1.0 Name=Deactivate Dropbear Comment=Turn off Dropbear Exec=/usr/local/bin/ssh_deactivate.sh Icon=terminal Terminal=false Type=Application Categories=System; X-HildonDesk-ShowInToolbar=true X-Osso-Type=application/x-executable }}}

Again, be certain to chown user all files created!

What this does?

By creating 1370_System in /etc/others-menu, a new System folder is available. In it will be two items: Activate Swap and Activate Dropbear. When you select either, it will change to Deactivate Swap/Dropbear. In either case it will function as advertised.

Originally I had the swap icon not change if the command returned an error: however, the error could mean swap was already disabled or already enabled, and was therefore somewhat problematic. I didn't quite feel like adding intelligent detection to this as I intend to write a control panel applet that will replace this hack.

Obviously, if you change the status of dropbear or ssh manually, including by rebooting, the icons will not be updated. This merely means you might have to deactivate again before activating, or activate again before deactivating.

Either way it saves me from having to type out the commands every time, and saves a bit of clutter as well: posted in the hopes it will be found useful.

(Feel free to bother AlexanderLash with questions and such.)