LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2008, 05:24 PM   #1
username88
LQ Newbie
 
Registered: Mar 2008
Posts: 5

Rep: Reputation: 0
What are hookscripts?-in noob terms please!!


Hey everyone,
Could someone explain to me what a hookscript is/how it works, in general/noob terms? I've googled it but there are no good, idiot-style explanations. I need to understand them to modify this shell script I found for a project I am working on with gphoto2, but I don't know where to start and have had a hard time finding understandable info because I am linux uber-noob. Please help!!!
Thanks!!!
 
Old 06-15-2008, 05:46 PM   #2
judecn
LQ Newbie
 
Registered: Jul 2007
Distribution: Debian, Angstrom, Familiar, OpenZaurus
Posts: 24

Rep: Reputation: 15
Welcome to Linux!

A "hook," in programming terms, refers to a location in a program where a 3rd party developer can add functionality to the program by creating a specially-crafted piece of code that will execute once that location is reached. E.g. a program that can have plug-ins uses hooks, and each plug-in must be designed to take advantage of the hooks.

A hookscript, in general, is a script that takes advantage of a hook. In your case, a hookscript would be a script you supply that gphoto2 would invoke to accomplish a specific task. Details on how gphoto2 will handle a hookscript designed for it (and how you should develop a hookscript) are outlined here: http://www.gphoto.org/doc/manual/ref-gphoto2-cli.html. Basically, gphoto2 will run your hookscript whenever a particular event happens, and your script can tell what happened based on the ACTION environment variable and act accordingly.
 
Old 06-15-2008, 06:42 PM   #3
username88
LQ Newbie
 
Registered: Mar 2008
Posts: 5

Original Poster
Rep: Reputation: 0
thanks for the reply!!
Now I have another stupid question, but please be patient with me, I am a scripting/programming noob too!!
In the previous post it says:
"Basically, gphoto2 will run your hookscript whenever a particular event happens, and your script can tell what happened based on the ACTION environment variable and act accordingly."

What does "environment variable" mean? Is ACTION a variable in the hookscript itself, or in gphoto, or...?
Oh dear, please help
 
Old 06-16-2008, 08:17 PM   #4
judecn
LQ Newbie
 
Registered: Jul 2007
Distribution: Debian, Angstrom, Familiar, OpenZaurus
Posts: 24

Rep: Reputation: 15
Every running process on Linux is given a set of data called "environment variables" that describe the the state of the current session. For example, which directory on disk is your home directory is an environment variable (type "echo $HOME" in a shell to see what it is). You can get a list of them in the shell using the "env" command. Common ones include PATH (the search path for executables), HOME (your home directory), PWD (if you're in a shell, this is the directory you're currently in), TERM (the terminal emulator you're using), MAIL (the directory where your mail is stored), etc. You can read more at http://en.wikipedia.org/wiki/Environment_variable.

A program's environment variables are inherited from the program that started it up. In this case, the hookscript inherits all the environment variables that gphoto2 knows about. Before gphoto2 invokes your script, it will create an environment variable called "ACTION" that your script will inherit and can access as soon as it starts. Depending on the scripting language you choose to use, there are multiple ways to access the value of the ACTION environment variable. Here are some examples:

1. shell script (bash-compatible)
Code:
#!/bin/sh

# print out the contents of ACTION
echo $ACTION

# exit normally
exit 0
2. ruby
Code:
#!/usr/bin/ruby

# print out the contents of ACTION
puts "#{ENV['ACTION'])"

# exit normally
Process.exit
3. python
Code:
#!/usr/bin/python

import os
import sys

# print out the contents of ACTION
print os.environ['ACTION']

# exit normally
sys.exit()
Hope this helps
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with the terms linuxhr123 Linux - Newbie 1 12-06-2007 11:45 AM
Terms RodimusProblem General 6 01-20-2005 09:43 AM
Defining terms Kurt M. Weber General 1 10-25-2003 08:25 PM
Linux Terms NSKL Linux - General 8 07-15-2003 05:17 AM
linux terms blistfix Linux - Newbie 2 06-24-2001 02:36 AM


All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration