2 # (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
3 # Hardware Profiles for rc-scripts TOTALNEW.
6 PROFDIR="/etc/sysconfig/hwprofiles"
9 . /etc/rc.d/init.d/functions
10 . /etc/sysconfig/hwprof
12 [ -z "${EDITOR}" ] && EDITOR=vi
14 if [ "$(id -u)" != "0" ]; then
15 echo "Need superuser privileges. Can't continue!"
19 if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
20 echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
26 if [ $QUIET -eq 0 ]; then
37 r foo - run specified profile or "default" if such exist
38 s - save/update running profile
39 f - find proper profile and run it
40 l - list configured profiles
41 q - be quiet (used only in few modes)
43 Please send all bug reports to:
44 pld-rc-scripts@pld-linux.org.
48 # This function probably must be enhanced.
52 grep -v "MHz" /proc/cpuinfo 2> /dev/null \
53 grep -v "Latency" /proc/pci 2> /dev/null \
54 ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
57 while getopts adflsqr: opt "$@"; do
60 echo "Adding new profile..."
61 if [ -f /var/run/hwprofile ]; then
62 echo -n "Current profile is: "
63 cat /var/run/hwprofile
66 while [ -z "${PROFILE}" ]; do
67 echo -n "Enter profile name: "
69 if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
70 echo "Profile ${PROFILE} exist. Try other name."
74 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
75 md5sumgen > ${PROFDIR}/${PROFILE}.md5
76 LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
77 mkdir -p ${PROFDIR}/data/${PROFILE}/
78 chmod 700 ${PROFDIR}/data/${PROFILE}/
79 echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
81 [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
82 echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
83 echo "Now, editor will be started and you need to enter list of files"
84 echo "for this profile (later as ${EDITOR} ${PROFDIR}/${PROFILE}.files)."
87 if [ -f ${PROFDIR}/files -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
88 cat ${PROFDIR}/files > ${PROFDIR}/${PROFILE}.files;
90 ${EDITOR} ${PROFDIR}/${PROFILE}.files
92 echo "Validating and copying valid files for this profile:"
93 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
94 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
95 echo "${file}: invalid, skipping"
98 bfile=$(basename ${file})
99 echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
100 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
101 FILES="${file}\n${FILES}"
103 echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
104 rm -f ${PROFDIR}/${PROFILE}.*~
105 echo "New profile ready."
109 echo "Deleting existing profile..."
111 while [ -z ${PROFILE} ]; do
112 echo -n "Enter profile name: "
114 if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
115 echo "Profile ${PROFILE} doesn't exist. Try other name."
119 echo -n "Are you sure? [t/N]: "
130 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
136 if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
137 echo "Can't setup ${PROFILE}. No required data."
140 echo -n "Setting up profile \"${PROFILE}\" "
142 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
143 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
144 myecho "${file}: invalid, skipping"
148 myecho "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
149 cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file} 2>/dev/null
151 echo ${PROFILE} > /var/run/hwprofile
153 myecho "Profile \"${PROFILE}\" running."
158 PROFILEMD5=$(md5sumgen)
159 myecho "Trying to find proper profile..."
160 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
161 prof=$(basename ${prof})
162 CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
163 # echo "$prof ${CURRENTMD5} ${PROFILEMD5}";
164 [ -z "${CURRENTMD5}" ] && continue
165 if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
166 PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
170 if [ -z "${PROFILE}" ]; then
171 if is_yes "${ASKFORPROFILE}"; then
172 echo "Avialable profiles:";
173 PS3='Enter number profile: ';
174 LISTA=$(ls ${PROFDIR}/*.desc 2> /dev/null);
177 a=$(basename $i .desc);
178 LISTA1="${a} ${LISTA1}";
180 LISTA1="${LISTA1} Default";
182 select PROFILE in $LISTA1;
189 if [ "${PROFILE}" == "Default" ]; then
194 if [ -z "${PROFILE}" ]; then
195 if [ ! -f ${PROFDIR}/default.md5 ]; then
196 echo "Valid profile not found. Starting with current files."
199 echo "Valid profile not found. Starting with \"default\" profile."
204 if [ ! -z "${PROFILE}" ]; then
205 myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
206 if [ $QUIET -eq 0 ]; then
215 PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
216 if [ -z "${PROFILE}" ]; then
217 echo "No profile currenty running."
220 if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
221 echo "${PROFILE}.files is missing. Can't continue."
224 echo -n "Saving/updating current [${PROFILE}] profile "
225 md5sumgen > ${PROFDIR}/${PROFILE}.md5
227 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
229 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
230 myecho "${file}: invalid, skipping"
233 myecho "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
234 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
240 echo "List of configured profiles:"
241 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
242 prof=$(basename ${prof})
243 profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
244 echo "Name : ${profname}"
246 if [ -f ${PROFDIR}/${profname}.md5 ]; then
247 cat ${PROFDIR}/${profname}.desc
252 if [ -f ${PROFDIR}/${profname}.date ]; then
253 cat ${PROFDIR}/${profname}.date
258 if [ -f ${PROFDIR}/${profname}.md5 ]; then
259 cat ${PROFDIR}/${profname}.md5
264 if [ -f ${PROFDIR}/${profname}.files ]; then
265 cat ${PROFDIR}/${profname}.files | xargs
275 QUIET=1; export QUIET;
285 if [ "$#" -le "0" ]; then
292 # This must be last line !
293 # vi:syntax=sh:tw=78:ts=2:sw=2