Jump to content

different profiles on boot


iphitus
 Share

Recommended Posts

With this laptop I run all sorts of different configurations depending where I am.

 

The irritating thing is i have to login and run scripts manually.

 

eg: At school i have to manually run a script i made to start wireless.

 

I cant put this in init because the keyboard locks up or the kernel oopses when i set the WEP key.

 

I would like it to come up, just before I start X with a menu

 

- Home Configuration

 

- School Config

 

- Home 2 (no X)

 

And each of these runs a shell script. (third is optional)

 

I tried writing a python script to do this, but it's output never makes the screen and if i leave it it locks up init.

 

Are there any programs that i can use that will do this?

 

Aru? Do you know of any cool shell scripts that will do this?

 

I am running Arch linux -- but if you find anything, let me know.

 

iphitus

Link to comment
Share on other sites

ok, thanks!

 

Quickswitch wont work because i have a shell script i need to run to get wireless working and it doesnt offer a chance to do that.

 

shortly after i posted that, i found something

 

It lets me pass an option to the kernel, eg: profilename=home

 

And i can call it from a shell script within linux and it will put that option into a environment variable with export (still listening? lol)

 

So im hacking a bash script to do what i want, wish me luck :D

Edited by iphitus
Link to comment
Share on other sites

You can change profiles from console as root with

# /sbin/set-netprofile "profile"

You might try this in your script.

 

In regard to passing an option to a kernel... If so, you can create two/more kernel stanza in the lilo.conf with different profilename=profile... My impression however is that you want change profiles right before X starts...

Link to comment
Share on other sites

In regard to passing an option to a kernel... If so, you can create two/more kernel stanza in the lilo.conf  with different  profilename=profile... My impression however is that you want change profiles right before X starts...

Thats what i am doing.

 

Ill post it when I finish it, although it will only really be useful for arch users

Link to comment
Share on other sites

Ok, here it is,

Don't try and use this script on another distro -- It will ONLY work on arch.

 

You can use the attatched program, cmdinfo to pass stuff to the kernel and then include it in scripts and stuff using ' export profilename=`/sbin/cmdinfo profilename` ' replacing profilename with whatever you passed to the kernel.

 

Have fun

 

#
# /etc/lilo.conf
#
                                                                                      
boot=/dev/discs/disc0/disc                                                                                   
default=Linux-LAN
timeout=50
lba32
prompt
                                                                                      
image=/boot/bzImage265
       label=Linux-LAN
       root=/dev/discs/disc0/part5
       read-only
                                                                                      
image=/boot/bzImage265
       label=Linux-Wireless
       root=/dev/discs/disc0/part5
# this is where i pass the parameter to the kernel.
       append="profilename=school"
       read-only

other=/dev/discs/disc0/part1
       label=dos
                                                                   

 

The startup script

#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

export profilename=`/sbin/cmdinfo profilename`

ifup()
{
 varname="\$${1}"
 eval new_ifline=$varname
 if [ "$new_ifline" = "dhcp" ]; then
   # remove the .pid file if it exists
   rm -f /etc/dhcpc/dhcpcd-${1}.{pid,cache} >/dev/null 2>&1
   /usr/sbin/dhcpcd -t 10 -h $HOSTNAME $1
 else
   /sbin/ifconfig $new_ifline
 fi
 return $?
}

ifdown()
{
 varname="\$${1}"
 eval new_ifline=$varname
 if [ "$new_ifline" = "dhcp" ]; then
   [ -f /etc/dhcpc/dhcpcd-${1}.pid ] && \
     /bin/kill `cat /etc/dhcpc/dhcpcd-${1}.pid`
 else
   /sbin/ifconfig $new_ifline down
 fi
 return $?
}

rtup()
{
 varname="\$${1}"
 eval new_rtline=$varname
 /sbin/route add $new_rtline
 return $?
}

rtdown()
{
 varname="\$${1}"
 eval new_rtline=$varname
 /sbin/route del $new_rtline
 return $?
}

# finished boring crap
# am I at school?
if [ "$profilename" = "school" ]; then
 stat_busy "Starting Wireless LAN"
 error=0
  iwconfig wlan0 mode Managed
  iwconfig wlan0 key restricted 1111111111
  iwconfig wlan0 essid XXXXXX
  ifconfig wlan0 up
  dhcpcd wlan0
 stat_done
else

# im not at school
case "$1" in
 start)
   if ! ck_daemon network; then
     echo "Network is already running.  Try 'network restart'"
     exit
   fi
   stat_busy "Starting Network"
   error=0
   for ifline in ${INTERFACES[@]}; do
     if echo $ifline | grep '^[^\!]' >/dev/null 2>&1; then
       ifup $ifline || error=1
     fi
   done
   for rtline in "${ROUTES[@]}"; do
     if echo $rtline | grep '^[^\!]' 2>&1 >/dev/null; then
       rtup $rtline || error=1
     fi
   done
   if [ $error -eq 0 ]; then
     add_daemon network
     stat_done
   else
     stat_fail
   fi
  ;;
 stop)
   if ck_daemon network; then
     echo "Network is not running.  Try 'network start'"
     exit
   fi
   stat_busy "Stopping Network"
   rm_daemon network
   error=0
   for rtline in "${ROUTES[@]}"; do
     if echo $rtline | grep '^[^\!]' 2>&1 >/dev/null; then
       rtdown $rtline || error=1
     fi
   done
   for ifline in ${INTERFACES[@]}; do
     if echo $ifline | grep '^[^\!]' 2>&1 >/dev/null; then
       ifdown $ifline || error=1
     fi
   done
   if [ $error -eq 0 ]; then
     stat_done
   else
     stat_fail
   fi
  ;;
 restart)
   $0 stop
   sleep 2
   $0 start
  ;;
 *)
   echo "usage: $0 {start|stop|restart}"  
esac
fi

cmdinfo.tar.gz

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...