sábado, dezembro 22, 2007

sudoers

My favorite thing about computers is that they always do what they're told, even when you tell them bad things =P If there's an error, it's always the programmer's error! Well if not a chip error, but in that case... it's a design error, the machine is still doing what it was told to do.
I just noticed today that I always open the same programs when I start the computer. So I though... why the hell am I doing the same commands when I can just code some shell script to do it for me?
And that's what I did.
Now I came across a little problem. I have several partitions on a sata disk, and an IDE disk working in this system...
And slackware recognizes them and mounts them as told by /etc/fstab. I like this, and do not want to change it, because it's comfortable when I just need to read and not write info to those partitions....
In case the house is on fire and I need to transfer some files to a removable media... you never know, I'm the Murphy's laws in flesh...

############################################################################
# Configuring the sudoers file #
############################################################################

So on to it, we want to use root commands so we'll need special permissions. Such may easily be achieved using:
myUserName@hostName:~$ sudo myUsuallyRootCommand

But in order to use this we must specify the current user has an authorized user for the myUsuallyRootCommand.

We do this by editing: /etc/sudoers file.

So grab your konsole and log as root to edit /etc/sudoers.
root@hostName:~$ kwrite /etc/sudoers &

# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#
# bunch of bla bla bla in here...

# Samples
%users ALL=NOPASSWD: /bin/mount /cdrom,/bin/umount /cdrom, /bin/mount /dev/mysatapartition, /bin/umount /dev/mysatapartition, /bin/mount /dev/myIDEpartition, /bin/umount /dev/myIDEpartition
%users ALL=/sbin/shutdown -h -t secs now


uncoment the %users ALL=blabla line and add the commands you'd like.

The ALL=NOPASSWD: detail specifies that users in the users group can sudo to those commands with no password required.

############################################################################
# doing a very simple shell script #
############################################################################

grab any editor, I like Kwrite 'cause it automatically colors the words for me, avoiding certain Parkinson errors (as in Parkinson disease, tremble and press the wrong key without ever realizing it).

the next line identifies the shell you want to use it should be the first line in your file
#!/bin/bash

# grant all is reset , cause kde sometimes does a “save session” thing and keeps opening stuff I left
# open on exit X.
killall amarok
killall amsn

#--------------------------------------------------------------------
# MOUNT PARTITIONS
#--------------------------------------------------------------------

#use sudo to umount your partitions
sudo umount /dev/mySata
sudo umount /dev/myIDE

#Then mount them has your own
mount /dev/mySata
mount /dev/myIDE

#--------------------------------------------------------------------
# STARTING STUFF
#--------------------------------------------------------------------

#just run your favorite applications.
# you can even run a self welcoming voice file, but I guess that would be kind of sick =P

/usr/bin/thunderbird &
/usr/bin/amsn &
/usr/bin/amarok &



###################################################################
Save it has IlikeThisFileName.sh and then set it to be executable:
myUserName@hostName: chmod 755 IlikeThisFileName.sh


what that 755 is a list of permitions each digit corresponds to the individual permitions of a set, in order: owner , group, and all. Then to interpret it you must translate it to binary, least significant bit means executable, then writable, then readable. So 755 means, (111)(101)(101), owner can read write and execute, group and all the others can read and execute. Always though this was delightfull, wanna grab the guy who tough of this and kiss it. Well or not. =P but it's funny.


Off course you can then write another script for your work environment, say you're working on school assignments, set it to run you're favorite IDE, your favorite playlist to study, so and so. Customize!!!!

I believe more and more that laziness is the mother of invention. \_/

1 comentário :

Anónimo disse...

i'm new... hope to brief approximately more oftentimes!