diff options
author | John Bowler <jbowler@nslu2-linux.org> | 2005-07-31 17:46:29 +0000 |
---|---|---|
committer | OpenEmbedded Project <openembedded-devel@lists.openembedded.org> | 2005-07-31 17:46:29 +0000 |
commit | 510fbcbb4355e84fcdabb99e0c1cc4f2a49955c5 (patch) | |
tree | 7cd033cb12d6615705f499d0f158cbbb65b9fd30 /packages/initscripts/initscripts-1.0/populate-volatile.sh | |
parent | 4ee908e0d96dae594c302fa8102f0b34563bebb3 (diff) | |
parent | d56e294e802bcbf85493a82ed7e73b9874ef7117 (diff) |
merge of 121ddca6013972dd4ad8d52c0eece2b80188cff9
and 214e28220f1a269af25029de6f726b7883040283
Diffstat (limited to 'packages/initscripts/initscripts-1.0/populate-volatile.sh')
-rwxr-xr-x | packages/initscripts/initscripts-1.0/populate-volatile.sh | 168 |
1 files changed, 121 insertions, 47 deletions
diff --git a/packages/initscripts/initscripts-1.0/populate-volatile.sh b/packages/initscripts/initscripts-1.0/populate-volatile.sh index 311a2764da..99a469d576 100755 --- a/packages/initscripts/initscripts-1.0/populate-volatile.sh +++ b/packages/initscripts/initscripts-1.0/populate-volatile.sh @@ -1,64 +1,138 @@ #!/bin/sh . /etc/default/rcS -CFGFILE="/etc/default/volatiles" + +CFGDIR="/etc/default/volatiles" +TMPROOT="/var/tmp" +COREDEF="00_core" [ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems." -cat ${CFGFILE} | grep -v "^#" | \ -while read LINE; do - TTYPE=`echo ${LINE} | cut -d " " -f 1` - TUSER=`echo ${LINE} | cut -d " " -f 2` - TGROUP=`echo ${LINE} | cut -d " " -f 3` - TMODE=`echo ${LINE} | cut -d " " -f 4` - TNAME=`echo ${LINE} | cut -d " " -f 5` - [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-." +check_requirements() { - [ "${TTYPE}" = "l" ] && { - [ -e "${TNAME}" ] && { - echo "Cannot create link over existing -${TNAME}-." >&2 - } || { - TSOURCE=`echo ${LINE} | cut -d " " -f 6` - [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-." - ln -s "${TSOURCE}" "${TNAME}" - } - continue + cleanup() { + rm "${TMP_INTERMED}" + rm "${TMP_DEFINED}" + rm "${TMP_COMBINED}" } + + CFGFILE="$1" - [ -L "${TNAME}" ] && { - [ "${VERBOSE}" != "no" ] && echo "Found link." - NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'` - echo ${NEWNAME} | grep -v "^/" >/dev/null && { - TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}" - [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-." - } || { - TNAME="${NEWNAME}" - [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-." - } + [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0 + + TMP_INTERMED="${TMPROOT}/tmp.$$" + TMP_DEFINED="${TMPROOT}/tmpdefined.$$" + TMP_COMBINED="${TMPROOT}/tmpcombined.$$" + + + cat /etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}" + cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}" + cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}" + + NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`" + NR_COMBINED_USERS="`cat "${TMP_COMBINED}" | wc -l`" + + [ "${NR_DEFINED_USERS}" -ne "${NR_COMBINED_USERS}" ] && { + echo "Undefined users:" + diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>" + cleanup + return 1 + } + + + cat /etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}" + cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}" + cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}" + + NR_DEFINED_GROUPS="`cat "${TMP_DEFINED}" | wc -l`" + NR_COMBINED_GROUPS="`cat "${TMP_COMBINED}" | wc -l`" + + [ "${NR_DEFINED_GROUPS}" -ne "${NR_COMBINED_GROUPS}" ] && { + echo "Undefined groups:" + diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>" + cleanup + return 1 } - [ -e "${TNAME}" ] && { - [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping." - continue + # Add checks for required directories here + + cleanup + return 0 + } + +apply_cfgfile() { + + CFGFILE="$1" + + check_requirements "${CFGFILE}" || { + echo "Skipping ${CFGFILE}" + return 1 } - case "${TTYPE}" in - "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-." - touch "${TNAME}" - ;; - "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-." - mkdir -p "${TNAME}" - # Add check to see if there's an entry in fstab to mount. - ;; - *) [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-." - continue - ;; - esac - - chown ${TUSER} ${TNAME} || echo "Failed to set owner -${TUSER}- for -${TNAME}-." >&2 - chgrp ${TGROUP} ${TNAME} || echo "Failed to set group -${TGROUP}- for -${TNAME}-." >&2 - chmod ${TMODE} ${TNAME} || echo "Failed to set mode -${TMODE}- for -${TNAME}-." >&2 + cat ${CFGFILE} | grep -v "^#" | \ + while read LINE; do + TTYPE=`echo ${LINE} | cut -d " " -f 1` + TUSER=`echo ${LINE} | cut -d " " -f 2` + TGROUP=`echo ${LINE} | cut -d " " -f 3` + TMODE=`echo ${LINE} | cut -d " " -f 4` + TNAME=`echo ${LINE} | cut -d " " -f 5` + + [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-." + + [ "${TTYPE}" = "l" ] && { + [ -e "${TNAME}" ] && { + echo "Cannot create link over existing -${TNAME}-." >&2 + } || { + TSOURCE=`echo ${LINE} | cut -d " " -f 6` + [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-." + ln -s "${TSOURCE}" "${TNAME}" + } + continue + } + + [ -L "${TNAME}" ] && { + [ "${VERBOSE}" != "no" ] && echo "Found link." + NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'` + echo ${NEWNAME} | grep -v "^/" >/dev/null && { + TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}" + [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-." + } || { + TNAME="${NEWNAME}" + [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-." + } + } + + [ -e "${TNAME}" ] && { + [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping." + continue + } + + case "${TTYPE}" in + "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-." + touch "${TNAME}" + ;; + "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-." + mkdir -p "${TNAME}" + # Add check to see if there's an entry in fstab to mount. + ;; + *) [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-." + continue + ;; + esac + + chown ${TUSER} ${TNAME} || echo "Failed to set owner -${TUSER}- for -${TNAME}-." >&2 + chgrp ${TGROUP} ${TNAME} || echo "Failed to set group -${TGROUP}- for -${TNAME}-." >&2 + chmod ${TMODE} ${TNAME} || echo "Failed to set mode -${TMODE}- for -${TNAME}-." >&2 + + done + + return 0 + + } + +for file in `ls -1 "${CFGDIR}" | sort`; do + apply_cfgfile "${CFGDIR}/${file}" done |