DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 25th October 2008
Gabe_G23 Gabe_G23 is offline
New User
 
Join Date: Oct 2008
Posts: 5
Thanked 0 Times in 1 Post
Default Handy X11 script

Hello everyone,

New here.. but I'll jump right in..

If you have multiple X11 environments with *BSD, this script is very handy. Instead of having a log-in manager (which in some cases takes up a considerable amount of RAM) like XDM, KDM, GDM, etc.

I have tested this on FreeBSD only for now.

It can even play music if you want it to!

Here ya go (tell me what you think please):

--This script currently works with the GNOME and WindowMaker environments.
Code:
#!/usr/local/bin/bash

# You can also modify #!/usr/local/bin/bash to /bin/bash depending on your
# system. This script will allow you to start an environment without 
# having to go through a (RAM hogging) log-in manager like XDM, GDM,
# KDM, etc. Enjoy!


clear
echo Choose the environment to start:
OPTIONS="Gnome WindowMaker"
select opt in $OPTIONS; do
	if [ "$opt" = "Gnome" ]; then
	 echo "/usr/local/bin/gnome-session" > ~/.xinitrc && startx
	 exit
	elif [ "$opt" = "WindowMaker" ]; then
	 echo "exec wmaker" > ~/.xinitrc && startx
	 exit
	else
	 clear
	 echo Bad Option
	fi
done
If you were to want to play music (MUST HAVE mpg123 installed - /usr/ports/audio/mpg123 on FreeBSD):

Code:
if [ "$opt" = "Gnome" ]; then
	 echo "/usr/local/bin/gnome-session" > ~/.xinitrc && startx && sleep 5 && mpg123 /usr/home/gabe/Gabe_Folders/music/System/startup.mp3
	 exit
Adjust the sleep <variable> to tell the system how long to wait until playing the music. Also adjust the mpg123 <DIR> to the location of your start up music.

Should be easy enough to follow along. If you have any questions, feel free to ask!

EDIT:

Standard sh script (thanks to vermaden):

Code:
#! /bin/sh

clear
echo Choose the environment to start:
echo "1. gnome"
echo "2. wmaker"
echo -n "choice: "
read OPT

case $OPT in
  (1)
    echo "/usr/local/bin/gnome-session" > ~/.xinitrc && startx
    exit 0
    ;;
  (2)
    echo "exec wmaker" > ~/.xinitrc && startx
    exit 0
    ;;
  (*)
    echo "ERROR: wrong option"
    exit 1
    ;;
esac

Last edited by Gabe_G23; 25th October 2008 at 04:12 PM.
Reply With Quote
  #2   (View Single Post)  
Old 25th October 2008
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Why use bash(1) wne you can do the same with plain POSIX sh(1)

Code:
#! /bin/sh

clear
echo Choose the environment to start:
echo "1. gnome"
echo "2. wmaker"
echo -n "choice: "
read OPT

case $OPT in
  (1)
    echo "/usr/local/bin/gnome-session" > ~/.xinitrc && startx
    exit 0
    ;;
  (2)
    echo "exec wmaker" > ~/.xinitrc && startx
    exit 0
    ;;
  (*)
    echo "ERROR: wrong option"
    exit 1
    ;;
esac
Always use sh(1) for scripts, bash(1) provides some fancy out of standart syntax and arrays. but for 99% cases its useless and can be achieved in plain sh(1).

... and welcome to bsdforums.org ... I mean daemonforums.org
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #3   (View Single Post)  
Old 25th October 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

I agree with vermaden, this is a BSD forum... bash, as an optional package, should not be used by default.
Reply With Quote
  #4   (View Single Post)  
Old 25th October 2008
Gabe_G23 Gabe_G23 is offline
New User
 
Join Date: Oct 2008
Posts: 5
Thanked 0 Times in 1 Post
Default

Quote:
Originally Posted by vermaden View Post
Why use bash(1) wne you can do the same with plain POSIX sh(1)

Code:
#! /bin/sh

clear
echo Choose the environment to start:
echo "1. gnome"
echo "2. wmaker"
echo -n "choice: "
read OPT

case $OPT in
  (1)
    echo "/usr/local/bin/gnome-session" > ~/.xinitrc && startx
    exit 0
    ;;
  (2)
    echo "exec wmaker" > ~/.xinitrc && startx
    exit 0
    ;;
  (*)
    echo "ERROR: wrong option"
    exit 1
    ;;
esac
Always use sh(1) for scripts, bash(1) provides some fancy out of standart syntax and arrays. but for 99% cases its useless and can be achieved in plain sh(1).

... and welcome to bsdforums.org ... I mean daemonforums.org
Haha. Thank you very much!

I was looking for an implementation in sh, seems like it found me.
Reply With Quote
  #5   (View Single Post)  
Old 25th October 2008
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,052
Thanked 118 Times in 93 Posts
Default

Quote:
Originally Posted by BSDfan666 View Post
I agree with vermaden, this is a BSD forum... bash, as an optional package, should not be used by default.
Even in Linux in most cases the only avialable shell is bash(1) I always use only POSIX sh(1) sollutions, and they work very good.

Also it is possible to force bash(1) to behave like POSIX with --posix switch like that in scripts:

Code:
#! /bin/bash --posix
You can also use /usr/bin/env to point to bash(1), because bash(1) often lies in different PATH in systems other then Linux.

Code:
#! /usr/bin/env bash
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #6   (View Single Post)  
Old 25th October 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

'echo "exec windowmanager" > ~/.xinitrc && startx' would make me nervous if I used an .xinitrc, instead of my init.sh ;-)
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
  #7   (View Single Post)  
Old 25th October 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

This is almost 99.9% useless in practise, for instance.. one may have other things in their .xinitrc files, which would get clobbered.

I'm also sure most of us are capable of using a text editor or I/O redirection manually... besides, I don't see fluxbox on that list.. and it's a definite necessity.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab won't run script Petrocelli08 FreeBSD General 4 7th March 2009 04:19 AM
Backup script(s)? giddyupman General software and network 2 3rd January 2009 02:06 PM
Automation Script ninjatux FreeBSD General 2 24th October 2008 04:16 PM
my 1st sh script graudeejs Programming 12 18th August 2008 10:25 PM
Shell Script. bsdnewbie999 Programming 21 15th July 2008 07:54 AM


All times are GMT. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick