diff options
author | Nicolás Reynolds <apoyosis@correo.inta.gob.ar> | 2011-12-14 11:17:39 -0300 |
---|---|---|
committer | Nicolás Reynolds <apoyosis@correo.inta.gob.ar> | 2011-12-14 11:17:39 -0300 |
commit | a68232261a533c2c9998a8016f27b00f4534fdde (patch) | |
tree | a06e6ae1c5aaec9cd072140717e2234050dac600 /functions | |
parent | c3d6cdb72f7130d3361bc1b8c99e862fe15a75fa (diff) | |
parent | b420829c5fe4441038c125789b1dd3eafb61457c (diff) |
Merge branch 'master' of https://projects.archlinux.org/git/initscripts into HEAD
Conflicts:
functions
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 198 |
1 files changed, 141 insertions, 57 deletions
@@ -5,6 +5,12 @@ # sanitize 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" +localevars=(LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY + LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE + LC_MEASUREMENT LC_IDENTIFICATION LC_ALL) + +vconsolevars=(KEYMAP KEYMAP_TOGGLE FONT FONT_MAP FONT_UNIMAP) + if [[ $1 == "start" ]]; then if [[ $STARTING ]]; then echo "A daemon is starting another daemon, this is unlikely to work as intended." @@ -64,52 +70,57 @@ unset TERM_COLORS unset TZ # sanitize the locale settins -unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ - LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ - LC_MEASUREMENT LC_IDENTIFICATION LC_ALL -if [[ $DAEMON_LOCALE = [yY][eE][sS] ]]; then - LANG="${LOCALE:=C}" - if [ -r /etc/locale.conf ]; then - . /etc/locale.conf +unset "${localevars[@]}" + +parse_envfile() { + local file=$1 validkeys=("${@:2}") ret=0 lineno=0 key= val= + local -r quotes=$'[\'"]' comments=$'[;#]*' + + if [[ -z $file ]]; then + printf "error: no environment file specified\n" + return 1 fi - export LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ - LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ - LC_MEASUREMENT LC_IDENTIFICATION LC_ALL -else - export LANG=C -fi -# set colors -if [[ $USECOLOR = [yY][eE][sS] ]]; then - if tput setaf 0 &>/dev/null; then - C_CLEAR=$(tput sgr0) # clear text - C_MAIN=${C_CLEAR}$(tput bold) # main text - C_OTHER=${C_MAIN}$(tput setaf 5) # prefix & brackets - C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator - C_BUSY=${C_CLEAR}$(tput setaf 6) # busy - C_FAIL=${C_MAIN}$(tput setaf 1) # failed - C_DONE=${C_MAIN} # completed - C_BKGD=${C_MAIN}$(tput setaf 5) # backgrounded - C_H1=${C_MAIN} # highlight text 1 - C_H2=${C_MAIN}$(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 + if [[ ! -f $file ]]; then + printf "error: cannot parse \`%s': No such file or directory\n" "$file" + return 1 fi -fi -# prefixes: + if [[ ! -r $file ]]; then + printf "error: cannot read \`%s': Permission denied\n" "$file" + return 1 + fi -PREFIX_REG="::" -PREFIX_HL=" >" + while IFS='=' read -r key val; do + (( ++lineno )) + + # trim whitespace, avoiding usage of a tempfile + key=$(echo "$key" | { read -r key; echo "$key"; }) + + # key must exist and line must not be a comment + [[ -z $key || ${key:0:1} = $comments ]] && continue + + # trim whitespace, strip matching quotes + val=$(echo "$val" | { read -r val; echo "$val"; }) + [[ ${val:0:1} = $quotes && ${val:(-1)} = "${val:0:1}" ]] && val=${val:1:(-1)} + + if [[ -z $val ]]; then + printf "error: found key \`%s' without value on line %s of %s\n" \ + "$key" "$lineno" "$file" + (( ++ret )) + continue + fi + + # ignore invalid keys if we have a list of valid ones + if (( ${#validkeys[*]} )) && ! in_array "$key" "${validkeys[@]}"; then + continue + fi + + export "$key=$val" || (( ++ret )) + done <"$file" + + return $ret +} # functions: @@ -128,7 +139,7 @@ printsep() { stat_bkgd() { printf "${C_OTHER}${PREFIX_REG} ${C_MAIN}${1}${C_CLEAR} " deltext - printf " ${C_OTHER}[${C_BKGD}BKGD${C_OTHER}]${C_CLEAR} " + printf " ${C_OTHER}[${C_BKGD}BKGD${C_OTHER}]${C_CLEAR} \n" } stat_busy() { @@ -370,7 +381,7 @@ activate_vgs() { # Newer packages will only have /sbin/cryptsetup and no static binary # This ensures maximal compatibility with the old and new layout for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ - /sbin/cryptsetup.static ''; do + /sbin/cryptsetup.static ''; do [[ -x $CS ]] && break done @@ -417,8 +428,11 @@ NETFS="nfs,nfs4,smbfs,cifs,codafs,ncpfs,shfs,fuse,fuseblk,glusterfs,davfs,fuse.g # Check local filesystems fsck_all() { - fsck -A -T -C"$FSCK_FD" -a -t "no${NETFS//,/,no},noopts=_netdev" $FORCEFSCK - return $? + if [[ -e /run/initramfs/root-fsck ]]; then + IGNORE_MOUNTED="-M" + fi + + fsck -A -T -C${FSCK_FD} -a -t no${NETFS//,/,no},noopts=_netdev ${FORCEFSCK} ${IGNORE_MOUNTED} } # Single-user login and/or automatic reboot after fsck (if needed) @@ -460,15 +474,48 @@ mount_all() { mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev } +umount_all() { + # $1: restrict to fstype + + local mounts + + while read -r target fstype options; do + + # match only targetted fstypes + if [[ $1 && $1 != "$fstype" ]]; then + continue + fi + + # don't unmount API filesystems + if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then + continue + fi + + # avoid networked devices + IFS=, read -ra opts <<< "$options" + if in_array _netdev "${opts[@]}"; then + continue + fi + + mounts+=("$target") + done < <(findmnt -mrunRo TARGET,FSTYPE,OPTIONS / | tac) + + umount -r "${mounts[@]}" + +} + remove_leftover() { stat_busy "Removing Leftover Files" - # handle this separately until we declare the non-symlinks obsoleted - [[ ! -L /var/lock ]] && rm -rf /var/lock/* - if [[ ! -L /var/run && -d /var/run ]]; then - find /var/run/ \! -type d -delete - ln -s /run/daemons /var/run/daemons - fi /usr/lib/initscripts/arch-tmpfiles --create --remove && stat_done || stat_fail + # move from static /var/{run,lock} to /run + if [[ ! -L /var/lock ]]; then + rm -rf /var/lock + ln -s /run/lock /var/lock + fi + if [[ ! -L /var/run ]]; then + rm -rf /var/run + ln -s /run /var/run + fi } bootlogd_stop() { @@ -477,7 +524,7 @@ bootlogd_stop() { kill $(< /run/bootlogd.pid) rm -f /run/bootlogd.pid sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[1?[0-9]1|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot + -e 's/\^\[(\[1?[0-9][0-9]|%)G//g' -e 's/\^\[\[0;1//g' /var/log/boot } ############################### @@ -511,6 +558,7 @@ bootlogd_stop() { # single_prekillall: before all processes are being killed in rc.single # shutdown_postkillall: after all processes have been killed in rc.shutdown # single_postkillall: after all processes have been killed in rc.single +# shutdown_preumount: after last filesystem write, but before filesystems are unmounted # shutdown_postumount: after filesystems are unmounted # shutdown_poweroff: directly before powering off in rc.shutdown # @@ -550,16 +598,52 @@ set_consolefont() { done if (( $? )); then stat_fail - elif [[ $CONSOLEMAP ]]; then - cat <<"EOF" >>/etc/profile.d/locale.sh -if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi -EOF - stat_done else stat_done fi } +if [[ $DAEMON_LOCALE = [yY][eE][sS] ]]; then + export LANG=${LOCALE:-C} + if [[ -r /etc/locale.conf ]]; then + parse_envfile /etc/locale.conf "${localevars[@]}" + fi +else + export LANG=C +fi + +# set colors +if [[ $USECOLOR = [yY][eE][sS] ]]; then + if tput setaf 0 &>/dev/null; then + C_CLEAR=$(tput sgr0) # clear text + C_MAIN=${C_CLEAR}$(tput bold) # main text + C_OTHER=${C_MAIN}$(tput setaf 5) # prefix & brackets + C_SEPARATOR=${C_MAIN}$(tput setaf 0) # separator + C_BUSY=${C_CLEAR}$(tput setaf 6) # busy + C_FAIL=${C_MAIN}$(tput setaf 1) # failed + C_DONE=${C_MAIN} # completed + C_BKGD=${C_MAIN}$(tput setaf 5) # backgrounded + C_H1=${C_MAIN} # highlight text 1 + C_H2=${C_MAIN}$(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 + +# prefixes: + +PREFIX_REG="::" +PREFIX_HL=" >" + # Source additional functions at the end to allow overrides for f in /etc/rc.d/functions.d/*; do [[ -e $f ]] && . "$f" |