4 # Required-Start: $local_fs
5 # Required-Stop: $local_fs
8 # Short-Description: Populate the volatile filesystem
13 ROOT_DIR=`echo $DIRNAME | sed -ne 's:/etc/.*::p'`
15 [ -e ${ROOT_DIR}/etc/default/rcS ] && . ${ROOT_DIR}/etc/default/rcS
16 # When running populate-volatile.sh at rootfs time, disable cache.
17 [ -n "$ROOT_DIR" ] && VOLATILE_ENABLE_CACHE=no
18 # If rootfs is read-only, disable cache.
19 [ "$ROOTFS_READ_ONLY" = "yes" ] && VOLATILE_ENABLE_CACHE=no
21 CFGDIR="${ROOT_DIR}/etc/default/volatiles"
22 TMPROOT="${ROOT_DIR}/var/volatile/tmp"
25 [ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
30 chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/ttyS0 2>&1;
31 chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/ttyS0 2>&1 "
33 test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
36 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
38 if [ -z "$ROOT_DIR" ]; then
41 # Creating some files at rootfs time may fail and should fail,
42 # but these failures should not be logged to make sure the do_rootfs
43 # process doesn't fail. This does no harm, as this script will
44 # run on target to set up the correct files and directories.
45 eval $EXEC > /dev/null 2>&1
53 chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/ttyS0 2>&1;
54 chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/ttyS0 2>&1 "
56 test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
58 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
60 if [ -z "$ROOT_DIR" ]; then
63 # For the same reason with create_file(), failures should
65 eval $EXEC > /dev/null 2>&1
72 if [ -L \"$2\" ]; then
73 [ \"\$(readlink -f \"$2\")\" != \"\$(readlink -f \"$1\")\" ] && { rm -f \"$2\"; ln -sf \"$1\" \"$2\"; };
74 elif [ -d \"$2\" ]; then
75 cp -a $2/* $1 2>/dev/null;
76 cp -a $2/.[!.]* $1 2>/dev/null;
84 test "$VOLATILE_ENABLE_CACHE" = yes && echo " $EXEC" >> /etc/volatile.cache.build
86 if [ -z "$ROOT_DIR" ]; then
89 # For the same reason with create_file(), failures should
91 eval $EXEC > /dev/null 2>&1
95 check_requirements() {
103 [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0
105 TMP_INTERMED="${TMPROOT}/tmp.$$"
106 TMP_DEFINED="${TMPROOT}/tmpdefined.$$"
107 TMP_COMBINED="${TMPROOT}/tmpcombined.$$"
109 sed 's@\(^:\)*:.*@\1@' ${ROOT_DIR}/etc/passwd | sort | uniq > "${TMP_DEFINED}"
110 cat ${CFGFILE} | grep -v "^#" | cut -s -d " " -f 2 > "${TMP_INTERMED}"
111 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
112 NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`"
113 NR_COMBINED_USERS="`cat "${TMP_COMBINED}" | wc -l`"
115 [ "${NR_DEFINED_USERS}" -ne "${NR_COMBINED_USERS}" ] && {
116 echo "Undefined users:"
117 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
123 sed 's@\(^:\)*:.*@\1@' ${ROOT_DIR}/etc/group | sort | uniq > "${TMP_DEFINED}"
124 cat ${CFGFILE} | grep -v "^#" | cut -s -d " " -f 3 > "${TMP_INTERMED}"
125 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
127 NR_DEFINED_GROUPS="`cat "${TMP_DEFINED}" | wc -l`"
128 NR_COMBINED_GROUPS="`cat "${TMP_COMBINED}" | wc -l`"
130 [ "${NR_DEFINED_GROUPS}" -ne "${NR_COMBINED_GROUPS}" ] && {
131 echo "Undefined groups:"
132 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
137 # Add checks for required directories here
146 check_requirements "${CFGFILE}" || {
147 echo "Skipping ${CFGFILE}"
151 cat ${CFGFILE} | grep -v "^#" | \
153 eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"`
154 TNAME=${ROOT_DIR}${TNAME}
155 [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
157 [ "${TTYPE}" = "l" ] && {
159 [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
160 link_file "${TSOURCE}" "${TNAME}"
164 [ -L "${TNAME}" ] && {
165 [ "${VERBOSE}" != "no" ] && echo "Found link."
166 NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'`
167 echo ${NEWNAME} | grep -v "^/" >/dev/null && {
168 TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}"
169 [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-."
172 [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-."
177 "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-."
178 create_file "${TNAME}" &
180 "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-."
182 # Add check to see if there's an entry in fstab to mount.
184 *) [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-."
197 *clearcache*) clearcache=1
205 if test -e ${ROOT_DIR}/etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes" -a "x$1" != "xupdate" -a "x$clearcache" = "x0"
207 sh ${ROOT_DIR}/etc/volatile.cache
209 rm -f ${ROOT_DIR}/etc/volatile.cache ${ROOT_DIR}/etc/volatile.cache.build
210 for file in `ls -1 "${CFGDIR}" | sort`; do
211 apply_cfgfile "${CFGDIR}/${file}"
214 [ -e ${ROOT_DIR}/etc/volatile.cache.build ] && sync && mv ${ROOT_DIR}/etc/volatile.cache.build ${ROOT_DIR}/etc/volatile.cache
217 if [ -z "${ROOT_DIR}" ] && [ -f /etc/ld.so.cache ] && [ ! -f /var/run/ld.so.cache ]
219 ln -s /etc/ld.so.cache /var/run/ld.so.cache