LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-06-2012, 09:30 PM   #1
freefall12
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Rep: Reputation: Disabled
shell scripting question


when you put a path name to a function file immediately after the #!/bin/sh, what does it mean? it looks like this
#!/bin/sh /etc/rc.common

Thanks in advance! anyway, this is my first post!
 
Old 06-06-2012, 09:32 PM   #2
freefall12
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
this is the full text.

#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2011 OpenWrt.org

START=60

smb_header() {
local interface
config_get interface $1 interface "loopback lan"

# resolve interfaces
local interfaces=$(
include /lib/network
scan_interfaces

local net
for net in $interface; do
local ifname
config_get ifname "$net" ifname
[ -n "$ifname" ] && {
local ipaddr netmask
config_get ipaddr "$net" ipaddr
config_get netmask "$net" netmask
[ -n "$ipaddr" ] && echo -n "$ipaddr/${netmask:-255.255.255.255} "

local ip6addr
config_get ip6addr "$net" ip6addr
[ -n "$ip6addr" ] && echo -n "$ip6addr "
}

echo -n "${ifname:-$net} "
done
)

local name workgroup description charset
local hostname="$(uci_get system.@system[0].hostname)"

config_get name $1 name "${hostname:-OpenWrt}"
config_get workgroup $1 workgroup "${hostname:-OpenWrt}"
config_get description $1 description "Samba on ${hostname:-OpenWrt}"
config_get charset $1 charset "UTF-8"

mkdir -p /var/etc
sed -e "s#|NAME|#$name#g" \
-e "s#|WORKGROUP|#$workgroup#g" \
-e "s#|DESCRIPTION|#$description#g" \
-e "s#|INTERFACES|#$interfaces#g" \
-e "s#|CHARSET|#$charset#g" \
/etc/samba/smb.conf.template > /var/etc/smb.conf

local homes
config_get_bool homes $1 homes 0
[ $homes -gt 0 ] && {
cat <<EOT >> /var/etc/smb.conf

[homes]
comment = Home Directories
browsable = no
read only = no
create mode = 0750
EOT
}

[ -L /etc/samba/smb.conf ] || ln -nsf /var/etc/smb.conf /etc/samba/smb.conf
}

smb_add_share() {
local name
local path
local users
local read_only
local guest_ok
local create_mask
local dir_mask

config_get name $1 name
config_get path $1 path
config_get users $1 users
config_get read_only $1 read_only
config_get guest_ok $1 guest_ok
config_get create_mask $1 create_mask
config_get dir_mask $1 dir_mask

[ -z "$name" -o -z "$path" ] && return

echo -e "\n[$name]\n\tpath = $path" >> /var/etc/smb.conf
[ -n "$users" ] && echo -e "\tvalid users = $users" >> /var/etc/smb.conf
[ -n "$read_only" ] && echo -e "\tread only = $read_only" >> /var/etc/smb.conf
[ -n "$guest_ok" ] && echo -e "\tguest ok = $guest_ok" >> /var/etc/smb.conf
[ -n "$create_mask" ] && echo -e "\tcreate mask = $create_mask" >> /var/etc/smb.conf
[ -n "$dir_mask" ] && echo -e "\tdirectory mask = $dir_mask" >> /var/etc/smb.conf
}

start() {
config_load samba
config_foreach smb_header samba
config_foreach smb_add_share sambashare
service_start /usr/sbin/smbd -D
service_start /usr/sbin/nmbd -D
}

stop() {
service_stop /usr/sbin/smbd
service_stop /usr/sbin/nmbd
}
 
Old 06-06-2012, 09:39 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Perhaps the second entry is an argument to "sh"--telling it where to find a key file.
 
Old 06-06-2012, 10:15 PM   #4
freefall12
LQ Newbie
 
Registered: Apr 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
thanks for replying! on closer look, i find the path name of this script seems to be used as a positional parameter to /etc/rc.common

cat /etc/rc.common
#!/bin/sh
# Copyright (C) 2006-2011 OpenWrt.org

. $IPKG_INSTROOT/lib/functions.sh
. $IPKG_INSTROOT/lib/functions/service.sh

initscript=$1
action=${2:-help}
shift 2

start() {
return 0
}

stop() {
return 0
}

reload() {
return 1
}

restart() {
trap '' TERM
stop "$@"
start "$@"
}

boot() {
start "$@"
}

shutdown() {
stop
}

disable() {
name="$(basename "${initscript}")"
rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
rm -f "$IPKG_INSTROOT"/etc/rc.d/K??$name
}

enable() {
name="$(basename "${initscript}")"
disable
[ -n "$START" -o -n "$STOP" ] || {
echo "/etc/init.d/$name does not have a START or STOP value"
return 1
}
[ "$START" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
[ "$STOP" ] && ln -s "../init.d/$name" "$IPKG_INSTROOT/etc/rc.d/K${STOP}${name##K[0-9][0-9]}"
}

enabled() {
name="$(basename "${initscript}")"
[ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
}

depends() {
return 0
}

help() {
cat <<EOF
Syntax: $initscript [command]

Available commands:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if that fails)
enable Enable service autostart
disable Disable service autostart
$EXTRA_HELP
EOF
}

. "$initscript"

ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
list_contains ALL_COMMANDS "$action" || action=help
[ "$action" = "reload" ] && action='eval reload "$@" || restart "$@" && :'
$action "$@"
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scripting question himitsu Programming 9 09-02-2009 08:59 PM
shell scripting question Komelore Linux - Software 3 03-12-2007 04:21 AM
shell scripting question bhert Linux - General 2 01-29-2007 08:55 PM
Shell Scripting Question b_vasu Linux - Newbie 1 11-21-2003 02:10 PM
Shell Scripting Question chrisk5527 Linux - General 12 07-09-2003 03:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:47 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
Open Source Consulting | Domain Registration