2 # (C) 2001 Arkadiusz MiĆkiewicz <misiek@pld.ORG.PL>
3 # Hardware Profiles for rc-scripts TOTALNEW.
5 PROFDIR="/etc/sysconfig/hwprofiles"
8 . /etc/rc.d/init.d/functions
9 . /etc/sysconfig/hwprof
11 [ -z "${EDITOR}" ] && EDITOR=vi
13 if [ "$(id -u)" != "0" ]; then
14 echo "Need superuser privileges. Can't continue!"
20 if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
21 echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
22 echo "Check /etc/sysconfig/hwprof and hwprofile -h."
29 if [ $QUIET -eq 0 ]; then
40 -r foo - run specified profile or "default" if such exist
41 -s - save/update running profile
42 -f - find proper profile and run it
43 -l - list configured profiles
44 -q - be quiet (used only in few modes)
46 Please send all bug reports to:
47 pld-rc-scripts@pld-linux.org.
51 # This function probably must be enhanced.
55 grep -v "MHz" /proc/cpuinfo 2> /dev/null \
56 grep -v "Latency" /proc/pci 2> /dev/null \
57 ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
60 while getopts adfhlsqr: opt "$@"; do
65 echo "Adding new profile..."
67 if [ -f /var/run/hwprofile ]; then
68 echo -n "Current profile is: "
69 cat /var/run/hwprofile
73 while [ -z "${PROFILE}" ]; do
74 echo -n "Enter profile name: "
77 if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
78 echo "Profile ${PROFILE} exist. Try other name."
83 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
84 md5sumgen > ${PROFDIR}/${PROFILE}.md5
85 LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
86 mkdir -p ${PROFDIR}/data/${PROFILE}/
87 chmod 700 ${PROFDIR}/data/${PROFILE}/
89 echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
91 [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
92 echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
93 echo "Now, editor will be started and you need to enter list of files"
94 echo "for this profile (later as ${EDITOR} ${PROFDIR}/${PROFILE}.files)."
98 if [ -f ${PROFDIR}/files -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
99 cat ${PROFDIR}/files > ${PROFDIR}/${PROFILE}.files;
101 ${EDITOR} ${PROFDIR}/${PROFILE}.files
104 echo "Validating and copying valid files for this profile:"
105 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
106 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
107 echo "${file}: invalid, skipping"
111 bfile=$(basename ${file})
112 echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
113 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
114 FILES="${file}\n${FILES}"
117 echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
118 rm -f ${PROFDIR}/${PROFILE}.*~
120 echo "New profile ready."
126 echo "Deleting existing profile..."
129 while [ -z ${PROFILE} ]; do
130 echo -n "Enter profile name: "
133 if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
134 echo "Profile ${PROFILE} doesn't exist. Try other name."
139 echo -n "Are you sure? [y/N]: "
151 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
161 if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
162 echo "Can't setup ${PROFILE}. No required data."
166 echo -n "Setting up profile \"${PROFILE}\" "
169 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
170 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
171 myecho "${file}: invalid, skipping"
176 myecho "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
177 cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file} 2>/dev/null
180 echo ${PROFILE} > /var/run/hwprofile
182 myecho "Profile \"${PROFILE}\" running."
189 PROFILEMD5=$(md5sumgen)
191 myecho "Trying to find proper profile..."
192 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
193 prof=$(basename ${prof})
194 CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
195 # echo "$prof ${CURRENTMD5} ${PROFILEMD5}";
196 [ -z "${CURRENTMD5}" ] && continue
198 if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
199 PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
204 if [ -z "${PROFILE}" ]; then
205 if is_yes "${ASKFORPROFILE}"; then
206 echo "Available profiles:";
207 PS3='Enter profile number: ';
208 LISTA=$(ls ${PROFDIR}/*.desc 2> /dev/null);
209 for i in ${LISTA}; do
210 a=$(basename $i .desc);
211 LISTA1="${a} ${LISTA1}";
213 LISTA1="${LISTA1} Default";
215 select PROFILE in $LISTA1; do
216 if [ -n "${PROFILE}" ]; then
221 if [ "${PROFILE}" = "Default" ]; then
227 if [ -z "${PROFILE}" ]; then
228 if [ ! -f ${PROFDIR}/default.md5 ]; then
229 echo "Valid profile not found. Starting with current files."
232 echo "Valid profile not found. Starting with \"default\" profile."
237 if [ ! -z "${PROFILE}" ]; then
238 myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
239 if [ $QUIET -eq 0 ]; then
250 PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
252 if [ -z "${PROFILE}" ]; then
253 echo "No profile currenty running."
257 if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
258 echo "${PROFILE}.files is missing. Can't continue."
262 echo -n "Saving/updating current [${PROFILE}] profile "
263 md5sumgen > ${PROFDIR}/${PROFILE}.md5
265 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
268 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
269 myecho "${file}: invalid, skipping"
273 myecho "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
274 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
280 echo "List of configured profiles:"
282 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
283 prof=$(basename ${prof})
284 profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
285 echo "Name : ${profname}"
287 if [ -f ${PROFDIR}/${profname}.md5 ]; then
288 cat ${PROFDIR}/${profname}.desc
293 if [ -f ${PROFDIR}/${profname}.date ]; then
294 cat ${PROFDIR}/${profname}.date
299 if [ -f ${PROFDIR}/${profname}.md5 ]; then
300 cat ${PROFDIR}/${profname}.md5
305 if [ -f ${PROFDIR}/${profname}.files ]; then
306 cat ${PROFDIR}/${profname}.files | xargs
316 QUIET=1; export QUIET;
326 if [ "$#" -le "0" -o "$OPTIND" -eq 1 ]; then