summaryrefslogtreecommitdiffstats
path: root/meta/packages/initscripts/initscripts-1.0/populate-volatile.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/initscripts/initscripts-1.0/populate-volatile.sh')
-rwxr-xr-xmeta/packages/initscripts/initscripts-1.0/populate-volatile.sh138
1 files changed, 138 insertions, 0 deletions
diff --git a/meta/packages/initscripts/initscripts-1.0/populate-volatile.sh b/meta/packages/initscripts/initscripts-1.0/populate-volatile.sh
new file mode 100755
index 0000000000..99a469d576
--- /dev/null
+++ b/meta/packages/initscripts/initscripts-1.0/populate-volatile.sh
@@ -0,0 +1,138 @@
1#!/bin/sh
2
3. /etc/default/rcS
4
5CFGDIR="/etc/default/volatiles"
6TMPROOT="/var/tmp"
7COREDEF="00_core"
8
9[ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
10
11
12check_requirements() {
13
14 cleanup() {
15 rm "${TMP_INTERMED}"
16 rm "${TMP_DEFINED}"
17 rm "${TMP_COMBINED}"
18 }
19
20 CFGFILE="$1"
21
22 [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0
23
24 TMP_INTERMED="${TMPROOT}/tmp.$$"
25 TMP_DEFINED="${TMPROOT}/tmpdefined.$$"
26 TMP_COMBINED="${TMPROOT}/tmpcombined.$$"
27
28
29 cat /etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
30 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}"
31 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
32
33 NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`"
34 NR_COMBINED_USERS="`cat "${TMP_COMBINED}" | wc -l`"
35
36 [ "${NR_DEFINED_USERS}" -ne "${NR_COMBINED_USERS}" ] && {
37 echo "Undefined users:"
38 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
39 cleanup
40 return 1
41 }
42
43
44 cat /etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
45 cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}"
46 cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
47
48 NR_DEFINED_GROUPS="`cat "${TMP_DEFINED}" | wc -l`"
49 NR_COMBINED_GROUPS="`cat "${TMP_COMBINED}" | wc -l`"
50
51 [ "${NR_DEFINED_GROUPS}" -ne "${NR_COMBINED_GROUPS}" ] && {
52 echo "Undefined groups:"
53 diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
54 cleanup
55 return 1
56 }
57
58 # Add checks for required directories here
59
60 cleanup
61 return 0
62 }
63
64apply_cfgfile() {
65
66 CFGFILE="$1"
67
68 check_requirements "${CFGFILE}" || {
69 echo "Skipping ${CFGFILE}"
70 return 1
71 }
72
73 cat ${CFGFILE} | grep -v "^#" | \
74 while read LINE; do
75 TTYPE=`echo ${LINE} | cut -d " " -f 1`
76 TUSER=`echo ${LINE} | cut -d " " -f 2`
77 TGROUP=`echo ${LINE} | cut -d " " -f 3`
78 TMODE=`echo ${LINE} | cut -d " " -f 4`
79 TNAME=`echo ${LINE} | cut -d " " -f 5`
80
81 [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
82
83 [ "${TTYPE}" = "l" ] && {
84 [ -e "${TNAME}" ] && {
85 echo "Cannot create link over existing -${TNAME}-." >&2
86 } || {
87 TSOURCE=`echo ${LINE} | cut -d " " -f 6`
88 [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
89 ln -s "${TSOURCE}" "${TNAME}"
90 }
91 continue
92 }
93
94 [ -L "${TNAME}" ] && {
95 [ "${VERBOSE}" != "no" ] && echo "Found link."
96 NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'`
97 echo ${NEWNAME} | grep -v "^/" >/dev/null && {
98 TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}"
99 [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-."
100 } || {
101 TNAME="${NEWNAME}"
102 [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-."
103 }
104 }
105
106 [ -e "${TNAME}" ] && {
107 [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
108 continue
109 }
110
111 case "${TTYPE}" in
112 "f") [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-."
113 touch "${TNAME}"
114 ;;
115 "d") [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-."
116 mkdir -p "${TNAME}"
117 # Add check to see if there's an entry in fstab to mount.
118 ;;
119 *) [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-."
120 continue
121 ;;
122 esac
123
124 chown ${TUSER} ${TNAME} || echo "Failed to set owner -${TUSER}- for -${TNAME}-." >&2
125 chgrp ${TGROUP} ${TNAME} || echo "Failed to set group -${TGROUP}- for -${TNAME}-." >&2
126 chmod ${TMODE} ${TNAME} || echo "Failed to set mode -${TMODE}- for -${TNAME}-." >&2
127
128 done
129
130 return 0
131
132 }
133
134
135for file in `ls -1 "${CFGDIR}" | sort`; do
136 apply_cfgfile "${CFGDIR}/${file}"
137 done
138