summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <apoyosis@correo.inta.gob.ar>2011-06-01 12:43:30 -0300
committerNicolás Reynolds <apoyosis@correo.inta.gob.ar>2011-06-01 12:43:30 -0300
commitdeac4d500c42135f40ea1f9777ed82fced8ccbf8 (patch)
treef1dc820279571cd5b6afb46a1a3d09956cf37dc0
parent84a17ca62a9bcfcfaef320c38bb45add1f673afd (diff)
parenta41c290180a5f7d0c7aa9eef2210956dd0a8bc63 (diff)
Merge branch 'master' of https://projects.archlinux.org/git/initscripts2011.06.1
Conflicts: functions
-rw-r--r--Makefile8
-rw-r--r--PKGBUILD7
-rw-r--r--bash-completion22
-rw-r--r--functions63
-rwxr-xr-xnetwork123
-rw-r--r--rc.conf59
-rwxr-xr-xrc.d20
-rwxr-xr-xrc.sysinit16
-rw-r--r--zsh-completion37
9 files changed, 245 insertions, 110 deletions
diff --git a/Makefile b/Makefile
index 6923840..fcabb0e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
VER := $(shell git describe)
-DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin
+DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin /etc/bash_completion.d /usr/share/zsh/site-functions
minilogd: minilogd.o
@@ -8,11 +8,13 @@ installdirs:
install: minilogd installdirs
install -m644 -t $(DESTDIR)/etc inittab rc.conf
- install -m644 -t $(DESTDIR)/etc/rc.d functions
install -m755 -t $(DESTDIR)/etc rc.local rc.local.shutdown rc.multi rc.shutdown rc.single rc.sysinit
install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime
- install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs
+ install -m644 -t $(DESTDIR)/etc/rc.d functions
+ install -m755 -t $(DESTDIR)/etc/rc.d hwclock network netfs
install -m755 -t $(DESTDIR)/sbin minilogd rc.d
+ install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d
+ install -m644 -T zsh-completion $(DESTDIR)/usr/share/zsh/site-functions/_rc.d
clean:
rm -f minilogd minilogd.o
diff --git a/PKGBUILD b/PKGBUILD
index 79cd475..dcf007b 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -9,9 +9,10 @@ groups=('base')
conflicts=('initscripts')
provides=('initscripts=9999')
backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown)
-depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1'
- 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit')
-optdepends=('bridge-utils: Network bridging support'
+depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' 'iproute2'
+ 'ncurses' 'kbd' 'findutils' 'sysvinit')
+optdepends=('net-tools: legacy networking support'
+ 'bridge-utils: Network bridging support'
'dhcpcd: DHCP network configuration'
'wireless_tools: Wireless networking')
source=()
diff --git a/bash-completion b/bash-completion
new file mode 100644
index 0000000..5151972
--- /dev/null
+++ b/bash-completion
@@ -0,0 +1,22 @@
+# rc.d bash completion by Seblu <seblu@seblu.net>
+
+_rc.d ()
+{
+ local action="help list start stop reload restart"
+ local cur="${COMP_WORDS[COMP_CWORD]}"
+ local caction="${COMP_WORDS[1]}"
+ if ((${COMP_CWORD} == 1)); then
+ COMPREPLY=($(compgen -W "${action}" -- "$cur"))
+ elif [[ "$caction" =~ help|list ]]; then
+ COMPREPLY=()
+ elif [[ "$caction" == start ]]; then
+ COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort)))
+ elif [[ "$caction" =~ stop|restart|reload ]]; then
+ COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort))
+ elif ((${COMP_CWORD} > 1)); then
+ COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort))
+ fi
+}
+complete -F _rc.d rc.d
+
+# vim: set ts=2 sw=2 ft=sh noet:
diff --git a/functions b/functions
index 83eb17b..6cd448c 100644
--- a/functions
+++ b/functions
@@ -49,28 +49,37 @@ else
export LANG=C
fi
-# colors:
-if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
- C_MAIN="\033[1;37;40m" # main text
-
- C_OTHER="\033[1;35;40m" # prefix & brackets
- C_SEPARATOR="\033[1;30;40m" # separator
-
- C_BUSY="\033[0;36;40m" # busy
- C_FAIL="\033[1;31;40m" # failed
- C_DONE="\033[1;37;40m" # completed
- C_BKGD="\033[1;35;40m" # backgrounded
-
- C_H1="\033[1;37;40m" # highlight text 1
- C_H2="\033[1;36;40m" # highlight text 2
-
- C_CLEAR="\033[1;0m"
+# set colors
+if [[ $USECOLOR =~ yes|YES ]]; then
+ if /bin/tput setaf 0 &>/dev/null; then
+ C_CLEAR="$(tput sgr0)" # clear text
+ C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text
+ C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets
+ C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator
+ C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy
+ C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed
+ C_DONE="${C_MAIN}" # completed
+ C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded
+ C_H1="${C_MAIN}" # highlight text 1
+ C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2
+ else
+ C_CLEAR="\e[m" # clear text
+ C_MAIN="\e[;1m" # main text
+ C_OTHER="\e[1;35m" # prefix & brackets
+ C_SEPARATOR="\e[1;30m" # separator
+ C_BUSY="\e[;36m" # busy
+ C_FAIL="\e[1;31m" # failed
+ C_DONE="${C_MAIN}" # completed
+ C_BKGD="\e[1;35m" # backgrounded
+ C_H1="${$C_MAIN}" # highlight text 1
+ C_H2="\e[1;36m" # highlight text 2
+ fi
fi
if [[ -t 1 ]]; then
- SAVE_POSITION="\033[s"
- RESTORE_POSITION="\033[u"
- DEL_TEXT="\033[$(($STAT_COL+4))G"
+ SAVE_POSITION="\e[s"
+ RESTORE_POSITION="\e[u"
+ DEL_TEXT="\e[$(($STAT_COL+4))G"
else
SAVE_POSITION=""
RESTORE_POSITION=""
@@ -222,6 +231,14 @@ ck_status() {
fi
}
+# PIDs to be omitted by killall5
+declare -a omit_pids
+
+add_omit_pids() {
+ omit_pids+=( $@ )
+}
+
+
kill_everything() {
# $1 = where we are being called from.
# This is used to determine which hooks to run.
@@ -241,12 +258,16 @@ kill_everything() {
# Terminate all processes
stat_busy "Sending SIGTERM To Processes"
run_hook "$1_prekillall"
- /sbin/killall5 -15 &> /dev/null
+ local pid k5args=""
+ for pid in ${omit_pids[@]}; do
+ k5args+=" -o $pid"
+ done
+ /sbin/killall5 -15 $k5args &> /dev/null
/bin/sleep 5
stat_done
stat_busy "Sending SIGKILL To Processes"
- /sbin/killall5 -9 &> /dev/null
+ /sbin/killall5 -9 $k5args &> /dev/null
/bin/sleep 1
stat_done
diff --git a/network b/network
index 5a261b4..7350149 100755
--- a/network
+++ b/network
@@ -7,6 +7,49 @@ for s in wireless bonding bridges dhcpcd; do
[[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s"
done
+# helper function to determine if legacy network support is needed
+need_legacy() {
+ if [[ -z $interface ]]; then
+ return 0 # need legacy
+ fi
+
+ return 1 # enough present for iproute2 support
+}
+
+deprecated() {
+ printf "${C_FAIL}Warning:${C_CLEAR} This functionality is deprecated.\n"
+ printf " Please refer to /etc/rc.conf on how to define a single wired\n"
+ printf " connection, or use a utility such as netcfg.\n"
+}
+
+network_up() {
+ /usr/sbin/ip link set dev $interface up || return 1
+
+ if [[ $address ]]; then
+ for var in netmask gateway; do
+ if [[ -z ${!var} ]]; then
+ printf "${C_FAIL}Error: static address defined without $var!\n"
+ return 1
+ fi
+ done
+ /usr/sbin/ip addr add $address/$netmask dev $interface || return 1
+ /usr/sbin/ip route add default via $gateway || return 1
+ else
+ /sbin/dhcpcd $DHCPCD_ARGS $interface || return 1
+ fi
+}
+
+network_down() {
+ if [[ -f /var/run/dhcpcd-$interface.pid ]]; then
+ /sbin/dhcpcd -k $interface || return 1
+ else
+ /usr/sbin/ip route del default || return 1
+ /usr/sbin/ip addr flush dev $interface || return 1
+ fi
+
+ /usr/sbin/ip link set dev $interface down || return 1
+}
+
ifup() {
local ifcfg=${!1}
@@ -179,29 +222,34 @@ bridge_down() {
case "$1" in
start)
+ # deprecation check
+ need_legacy && deprecated
if ! ck_daemon network; then
echo "Network is already running. Try 'network restart'"
exit
fi
-
stat_busy "Starting Network"
error=0
- # bring up bridge interfaces
- bridge_up
- # bring up ethernet interfaces
- for ifline in ${INTERFACES[@]}; do
- if [[ $ifline = ${ifline#!} ]]; then
- ifup $ifline || error=1
- fi
- done
- # bring up bond interfaces
- bond_up
- # bring up routes
- for rtline in "${ROUTES[@]}"; do
- if [ "$rtline" = "${rtline#!}" ]; then
- rtup $rtline || error=1
- fi
- done
+ if need_legacy; then
+ # bring up bridge interfaces
+ bridge_up
+ # bring up ethernet interfaces
+ for ifline in ${INTERFACES[@]}; do
+ if [[ $ifline = ${ifline#!} ]]; then
+ ifup $ifline || error=1
+ fi
+ done
+ # bring up bond interfaces
+ bond_up
+ # bring up routes
+ for rtline in "${ROUTES[@]}"; do
+ if [ "$rtline" = "${rtline#!}" ]; then
+ rtup $rtline || error=1
+ fi
+ done
+ else
+ network_up
+ fi
if ((error == 0)); then
add_daemon network
stat_done
@@ -210,11 +258,8 @@ case "$1" in
fi
;;
stop)
- #if ck_daemon network; then
- # echo "Network is not running. Try 'network start'"
- # exit
- #fi
-
+ # deprecation check
+ need_legacy && deprecated
if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then
status "Skipping Network Shutdown" true
exit 0
@@ -223,20 +268,24 @@ case "$1" in
stat_busy "Stopping Network"
rm_daemon network
error=0
- for rtline in "${ROUTES[@]}"; do
- if [[ $rtline = ${rtline#!} ]]; then
- rtdown $rtline || error=1
- fi
- done
- # bring down bond interfaces
- bond_down
- for ifline in ${INTERFACES[@]}; do
- if [[ $ifline = ${ifline#!} ]]; then
- ifdown $ifline || error=1
- fi
- done
- # bring down bridge interfaces
- bridge_down
+ if need_legacy; then
+ for rtline in "${ROUTES[@]}"; do
+ if [[ $rtline = ${rtline#!} ]]; then
+ rtdown $rtline || error=1
+ fi
+ done
+ # bring down bond interfaces
+ bond_down
+ for ifline in ${INTERFACES[@]}; do
+ if [[ $ifline = ${ifline#!} ]]; then
+ ifdown $ifline || error=1
+ fi
+ done
+ # bring down bridge interfaces
+ bridge_down
+ else
+ network_down
+ fi
if ((error == 0)); then
stat_done
else
@@ -249,6 +298,8 @@ case "$1" in
$0 start
;;
ifup|ifdown|iflist|rtup|rtdown|rtlist)
+ # deprecation check
+ need_legacy && deprecated
$1 $2
;;
*)
diff --git a/rc.conf b/rc.conf
index 1898aa3..18effe9 100644
--- a/rc.conf
+++ b/rc.conf
@@ -33,8 +33,12 @@ VERBOSE="3"
# HARDWARE
# -----------------------------------------------------------------------
#
-# MOD_AUTOLOAD: Allow autoloading of modules at boot and when needed
-# MODULES: Modules to load at boot-up. Prefix with a ! to blacklist.
+# MOD_AUTOLOAD: Deprecated. Always leave at "yes".
+# MODULES: Modules to load at boot-up. Blacklisting is no longer supported.
+# Replace every !module by an entry as on the following line in a file in
+# /etc/modprobe.d:
+# blacklist module
+# See "man modprobe.conf" for details.
#
MOD_AUTOLOAD="yes"
MODULES=()
@@ -59,44 +63,35 @@ USELVM="no"
#
HOSTNAME="myhost"
-# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces.
+# Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces.
#
-# Interfaces to start at boot-up (in this order)
-# Declare each interface then list in INTERFACES
-# - prefix an entry in INTERFACES with a ! to disable it
-# - no hyphens in your interface names - Bash doesn't like it
+# Wired network setup
+# - interface: name of device (required)
+# - address: IP address (leave blank for DHCP)
+# - netmask: subnet mask (ignored for DHCP)
+# - gateway: default route (ignored for DHCP)
#
-# DHCP: Set your interface to "dhcp" (eth0="dhcp")
-# Wireless: See network profiles below
-#
-
-#Static IP example
-#eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
-eth0="dhcp"
-INTERFACES=(eth0)
+# Static IP example
+# interface=eth0
+# address=192.168.0.2
+# netmask=255.255.255.0
+# gateway=192.168.0.1
+#
+# DHCP example
+# interface=eth0
+# address=
+# netmask=
+# gateway=
-# Routes to start at boot-up (in this order)
-# Declare each route then list in ROUTES
-# - prefix an entry in ROUTES with a ! to disable it
-#
-gateway="default gw 192.168.0.1"
-ROUTES=(!gateway)
+interface=
+address=
+netmask=
+gateway=
# Setting this to "yes" will skip network shutdown.
# This is required if your root device is on NFS.
NETWORK_PERSIST="no"
-# Enable these network profiles at boot-up. These are only useful
-# if you happen to need multiple network configurations (ie, laptop users)
-# - set to 'menu' to present a menu during boot-up (dialog package required)
-# - prefix an entry with a ! to disable it
-#
-# Network profiles are found in /etc/network.d
-#
-# This now requires the netcfg package
-#
-#NETWORKS=(main)
-
# -----------------------------------------------------------------------
# DAEMONS
# -----------------------------------------------------------------------
diff --git a/rc.d b/rc.d
index 02c2b6c..772f2c6 100755
--- a/rc.d
+++ b/rc.d
@@ -42,20 +42,28 @@ case $1 in
done
;;
*)
+ # check min args count
+ (( $# < 2 )) && usage
action=$1
shift
# set same environment variables as init
runlevel=$(/sbin/runlevel)
- ENV="PATH='/bin:/usr/bin:/sbin:/usr/sbin'"
- ENV+=" PREVLEVEL='${runlevel:0:1}'"
- ENV+=" RUNLEVEL='${runlevel:2:1}'"
- ENV+=" CONSOLE='${CONSOLE:-/dev/console}'"
+ ENV=("PATH=/bin:/usr/bin:/sbin:/usr/sbin"
+ "PREVLEVEL=${runlevel%% *}"
+ "RUNLEVEL=${runlevel##* }"
+ "CONSOLE=${CONSOLE:-/dev/console}"
+ "TERM=$TERM")
+ cd /
for i; do
- [[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action"
+ if [[ -x "/etc/rc.d/$i" ]]; then
+ /usr/bin/env -i "${ENV[@]}" "/etc/rc.d/$i" "$action"
+ else
+ printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script $i does not exist.\n"
+ fi
(( ret += !! $? )) # clamp exit value to 0/1
done
esac
exit $ret
-# vim: set ts=2 sw=2 noet:
+# vim: set ts=2 sw=2 ft=sh noet:
diff --git a/rc.sysinit b/rc.sysinit
index 908f639..aebecdb 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -14,7 +14,7 @@ printsep
run_hook sysinit_start
-# export standard PATH (will be overridden later when /etc/profile is sourced, but is usefull for UDev)
+# export standard PATH (will be overridden later when /etc/profile is sourced, but is useful for UDev)
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems)
@@ -30,9 +30,9 @@ if ! /bin/mountpoint -q /dev; then
fi
/bin/mkdir -p /run/lock /dev/{pts,shm}
/bin/chmod 1777 /run/lock
-/bin/mountpoint -q /dev/pts || /bin/mount /dev/pts &> /dev/null \
+/bin/mountpoint -q /dev/pts || /bin/mount -n /dev/pts &> /dev/null \
|| /bin/mount -n -t devpts devpts /dev/pts -o mode=620,gid=5,nosuid,noexec
-/bin/mountpoint -q /dev/shm || /bin/mount /dev/shm &> /dev/null \
+/bin/mountpoint -q /dev/shm || /bin/mount -n /dev/shm &> /dev/null \
|| /bin/mount -n -t tmpfs shm /dev/shm -o mode=1777,nosuid,nodev
# remount root ro to allow for fsck later on, we remount now to
@@ -113,7 +113,7 @@ run_hook sysinit_udevsettled
# bring up the loopback interface
[[ -d /sys/class/net/lo ]] && \
- status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up
+ status "Bringing up loopback interface" /usr/sbin/ip link set up dev lo
# FakeRAID devices detection
if [[ $USEDMRAID =~ yes|YES && -x /sbin/dmraid ]]; then
@@ -314,7 +314,7 @@ fi
stat_busy "Removing Leftover Files"
/bin/rm -rf /etc/{nologin,shutdownpid} /forcefsck &>/dev/null
-/bin/mountpoint -q /tmp || /bin/rm -rf /tmp/* /tmp/.* &>/dev/null
+/bin/rm -rf /tmp/* /tmp/.* &>/dev/null
[[ ! -L /var/lock ]] && /bin/rm -rf /var/lock/*
[[ ! -L /var/run && -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete
[[ ! -L /var/run && ! -L /var/run/daemons ]] && /bin/rm -rf /var/run/daemons \
@@ -326,8 +326,6 @@ stat_busy "Removing Leftover Files"
/bin/mkdir -m1777 /tmp/.{X11,ICE}-unix
stat_done
-#status "Updating Shared Library Links" /sbin/ldconfig
-
if [[ $HOSTNAME ]]; then
status "Setting Hostname: $HOSTNAME" /bin/hostname "$HOSTNAME"
fi
@@ -354,7 +352,7 @@ if [[ ${LOCALE,,} =~ utf ]]; then
# but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8.
for i in /dev/tty[0-9]*; do
/usr/bin/kbd_mode -u < ${i}
- printf "\033%%G" > ${i}
+ printf "\e%%G" > ${i}
done
echo 1 > /sys/module/vt/parameters/default_utf8
stat_done
@@ -364,7 +362,7 @@ else
# make non-UTF-8 consoles work on 2.6.24 and newer kernels
for i in /dev/tty[0-9]*; do
/usr/bin/kbd_mode -a < ${i}
- printf "\033%%@" > ${i}
+ printf "\e%%@" > ${i}
done
echo 0 > /sys/module/vt/parameters/default_utf8
stat_done
diff --git a/zsh-completion b/zsh-completion
new file mode 100644
index 0000000..f1b7165
--- /dev/null
+++ b/zsh-completion
@@ -0,0 +1,37 @@
+#compdef rc.d
+
+_rc.d () {
+ local curcontext="$curcontext" state line
+ typeset -A opt_args
+
+ _arguments "1: :->action" "*: :->service"
+
+ case $state in
+ action)
+ _arguments "1:action:(list help start stop restart)"
+ ;;
+ service)
+ local action="$words[2]"
+ curcontext="${curcontext%:*:*}:rc.d-${action}:"
+
+ case $action in
+ list|help)
+ _arguments "*: :"
+ ;;
+ start)
+ _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))"
+ ;;
+ stop|restart|reload)
+ _arguments "*: :(/run/daemons/*(N:t))"
+ ;;
+ *)
+ _arguments "*: :(/etc/rc.d/*(N-*:t))"
+ ;;
+ esac
+ ;;
+ esac
+}
+
+_rc.d "$@"
+
+# vim: set ts=2 sw=2 ft=sh noet: