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