Increase dvbapp PR.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-core / initscripts / initscripts-1.0 / populate-volatile.sh
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:             volatile
4 # Required-Start:       $local_fs
5 # Required-Stop:      $local_fs
6 # Default-Start:        S
7 # Default-Stop:
8 # Short-Description:  Populate the volatile filesystem
9 ### END INIT INFO
10
11 . /etc/default/rcS
12
13 CFGDIR="/etc/default/volatiles"
14 TMPROOT="/var/tmp"
15 COREDEF="00_core"
16
17 [ "${VERBOSE}" != "no" ] && echo "Populating volatile Filesystems."
18
19 create_file() {
20         EXEC=" 
21         touch \"$1\"; 
22         chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/ttyS0 2>&1; 
23         chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/ttyS0 2>&1 " 
24
25         test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
26
27         [ -e "$1" ] && {
28           [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
29         } || {
30           eval $EXEC &
31         }
32 }
33
34 mk_dir() {
35         EXEC=" 
36         mkdir -p \"$1\"; 
37         chown ${TUSER}.${TGROUP} $1 || echo \"Failed to set owner -${TUSER}- for -$1-.\" >/dev/ttyS0 2>&1; 
38         chmod ${TMODE} $1 || echo \"Failed to set mode -${TMODE}- for -$1-.\" >/dev/ttyS0 2>&1 "
39
40         test "$VOLATILE_ENABLE_CACHE" = yes && echo "$EXEC" >> /etc/volatile.cache.build
41         
42         [ -e "$1" ] && {
43           [ "${VERBOSE}" != "no" ] && echo "Target already exists. Skipping."
44         } || {
45           eval $EXEC &
46         }
47 }
48
49 link_file() {
50         EXEC="test -e \"$2\" -o -L $2 || ln -s \"$1\" \"$2\" >/dev/ttyS0 2>&1" 
51
52         test "$VOLATILE_ENABLE_CACHE" = yes && echo "   $EXEC" >> /etc/volatile.cache.build
53         
54         [ -e "$2" ] && {
55           echo "Cannot create link over existing -${TNAME}-." >&2
56         } || {
57           eval $EXEC &
58         }
59 }
60
61 check_requirements() {
62
63   cleanup() {
64     rm "${TMP_INTERMED}"
65     rm "${TMP_DEFINED}"
66     rm "${TMP_COMBINED}"
67     }
68     
69   CFGFILE="$1"
70
71   [ `basename "${CFGFILE}"` = "${COREDEF}" ] && return 0
72
73   TMP_INTERMED="${TMPROOT}/tmp.$$"
74   TMP_DEFINED="${TMPROOT}/tmpdefined.$$"
75   TMP_COMBINED="${TMPROOT}/tmpcombined.$$"
76
77
78   cat /etc/passwd | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
79   cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 2 > "${TMP_INTERMED}"
80   cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
81
82   NR_DEFINED_USERS="`cat "${TMP_DEFINED}" | wc -l`"
83   NR_COMBINED_USERS="`cat "${TMP_COMBINED}" | wc -l`"
84
85   [ "${NR_DEFINED_USERS}" -ne "${NR_COMBINED_USERS}" ] && {
86     echo "Undefined users:"
87     diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
88     cleanup
89     return 1
90     }
91
92
93   cat /etc/group | sed 's@\(^:\)*:.*@\1@' | sort | uniq > "${TMP_DEFINED}"
94   cat ${CFGFILE} | grep -v "^#" | cut -d " " -f 3 > "${TMP_INTERMED}"
95   cat "${TMP_DEFINED}" "${TMP_INTERMED}" | sort | uniq > "${TMP_COMBINED}"
96
97   NR_DEFINED_GROUPS="`cat "${TMP_DEFINED}" | wc -l`"
98   NR_COMBINED_GROUPS="`cat "${TMP_COMBINED}" | wc -l`"
99
100   [ "${NR_DEFINED_GROUPS}" -ne "${NR_COMBINED_GROUPS}" ] && {
101     echo "Undefined groups:"
102     diff "${TMP_DEFINED}" "${TMP_COMBINED}" | grep "^>"
103     cleanup
104     return 1
105     }
106
107   # Add checks for required directories here
108
109   cleanup
110   return 0
111   }
112
113 apply_cfgfile() {
114
115   CFGFILE="$1"
116
117   check_requirements "${CFGFILE}" || {
118     echo "Skipping ${CFGFILE}"
119     return 1
120     }
121
122   cat ${CFGFILE} | grep -v "^#" | \
123   while read LINE; do
124
125     eval `echo "$LINE" | sed -n "s/\(.*\)\ \(.*\) \(.*\)\ \(.*\)\ \(.*\)\ \(.*\)/TTYPE=\1 ; TUSER=\2; TGROUP=\3; TMODE=\4; TNAME=\5 TLTARGET=\6/p"`
126
127     [ "${VERBOSE}" != "no" ] && echo "Checking for -${TNAME}-."
128
129
130     [ "${TTYPE}" = "l" ] && {
131       TSOURCE="$TLTARGET"
132       [ -L "${TNAME}" ] || {
133         [ "${VERBOSE}" != "no" ] && echo "Creating link -${TNAME}- pointing to -${TSOURCE}-."
134         link_file "${TSOURCE}" "${TNAME}" &
135         }
136       continue
137       }
138
139     [ -L "${TNAME}" ] && {
140       [ "${VERBOSE}" != "no" ] && echo "Found link."
141       NEWNAME=`ls -l "${TNAME}" | sed -e 's/^.*-> \(.*\)$/\1/'`
142       echo ${NEWNAME} | grep -v "^/" >/dev/null && {
143         TNAME="`echo ${TNAME} | sed -e 's@\(.*\)/.*@\1@'`/${NEWNAME}"
144         [ "${VERBOSE}" != "no" ] && echo "Converted relative linktarget to absolute path -${TNAME}-."
145         } || {
146         TNAME="${NEWNAME}"
147         [ "${VERBOSE}" != "no" ] && echo "Using absolute link target -${TNAME}-."
148         }
149       }
150
151     case "${TTYPE}" in
152       "f")  [ "${VERBOSE}" != "no" ] && echo "Creating file -${TNAME}-."
153             create_file "${TNAME}" &
154             ;;
155       "d")  [ "${VERBOSE}" != "no" ] && echo "Creating directory -${TNAME}-."
156             mk_dir "${TNAME}" &
157             # Add check to see if there's an entry in fstab to mount.
158             ;;
159       *)    [ "${VERBOSE}" != "no" ] && echo "Invalid type -${TTYPE}-."
160             continue
161             ;;
162     esac
163
164
165     done
166
167   return 0
168
169   }
170
171 clearcache=0
172 exec 9</proc/cmdline
173 while read line <&9
174 do
175         case "$line" in
176                 *clearcache*)  clearcache=1
177                                ;;
178                 *)             continue
179                                ;;
180         esac
181 done
182 exec 9>&-
183
184 if test -e /etc/volatile.cache -a "$VOLATILE_ENABLE_CACHE" = "yes" -a "x$1" != "xupdate" -a "x$clearcache" = "x0"
185 then
186         sh /etc/volatile.cache
187 else    
188         rm -f /etc/volatile.cache /etc/volatile.cache.build
189         for file in `ls -1 "${CFGDIR}" | sort`; do
190                 apply_cfgfile "${CFGDIR}/${file}"
191         done
192
193         [ -e /etc/volatile.cache.build ] && sync && mv /etc/volatile.cache.build /etc/volatile.cache
194 fi
195
196 if test -f /etc/ld.so.cache -a ! -f /var/run/ld.so.cache
197 then
198         ln -s /etc/ld.so.cache /var/run/ld.so.cache
199 fi