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!"
21 if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
22 echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
23 echo "Check /etc/sysconfig/hwprof and hwprofile -h."
30 if [ $QUIET -eq 0 ]; then
41 -r foo - run specified profile or "default" if such exist
42 -s - save/update running profile
43 -f - find proper profile and run it
44 -l - list configured profiles
45 -q - be quiet (used only in few modes)
47 Please send all bug reports to:
48 pld-rc-scripts@pld-linux.org.
52 # This function probably must be enhanced.
56 grep -v "MHz" /proc/cpuinfo 2> /dev/null \
57 grep -v "Latency" /proc/pci 2> /dev/null \
58 ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
61 while getopts adfhlsqr: opt "$@"; do
66 echo "Adding new profile..."
68 if [ -f /var/run/hwprofile ]; then
69 echo -n "Current profile is: "
70 cat /var/run/hwprofile
74 while [ -z "${PROFILE}" ]; do
75 echo -n "Enter profile name: "
78 if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
79 echo "Profile ${PROFILE} exist. Try other name."
84 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
85 md5sumgen > ${PROFDIR}/${PROFILE}.md5
86 LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
87 mkdir -p ${PROFDIR}/data/${PROFILE}/
88 chmod 700 ${PROFDIR}/data/${PROFILE}/
90 echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
92 [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
93 echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
94 echo "Now, editor will be started and you need to enter list of files"
95 echo "for this profile (later as ${EDITOR} ${PROFDIR}/${PROFILE}.files)."
99 if [ -f ${PROFDIR}/files -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
100 cat ${PROFDIR}/files > ${PROFDIR}/${PROFILE}.files;
102 ${EDITOR} ${PROFDIR}/${PROFILE}.files
105 echo "Validating and copying valid files for this profile:"
106 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
107 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
108 echo "${file}: invalid, skipping"
112 bfile=$(basename ${file})
113 echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
114 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
115 FILES="${file}\n${FILES}"
118 echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
119 rm -f ${PROFDIR}/${PROFILE}.*~
121 echo "New profile ready."
127 echo "Deleting existing profile..."
130 while [ -z ${PROFILE} ]; do
131 echo -n "Enter profile name: "
134 if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
135 echo "Profile ${PROFILE} doesn't exist. Try other name."
140 echo -n "Are you sure? [y/N]: "
152 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
162 if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
163 echo "Can't setup ${PROFILE}. No required data."
167 echo -n "Setting up profile \"${PROFILE}\" "
170 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
171 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
172 myecho "${file}: invalid, skipping"
177 myecho "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
178 cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file} 2>/dev/null
181 echo ${PROFILE} > /var/run/hwprofile
183 myecho "Profile \"${PROFILE}\" running."
190 PROFILEMD5=$(md5sumgen)
192 myecho "Trying to find proper profile..."
193 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
194 prof=$(basename ${prof})
195 CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
196 # echo "$prof ${CURRENTMD5} ${PROFILEMD5}";
197 [ -z "${CURRENTMD5}" ] && continue
199 if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
200 PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
205 if [ -z "${PROFILE}" ]; then
206 if is_yes "${ASKFORPROFILE}"; then
207 echo "Available profiles:";
208 PS3='Enter profile number: ';
209 LISTA=$(ls ${PROFDIR}/*.desc 2> /dev/null);
210 for i in ${LISTA}; do
211 a=$(basename $i .desc);
212 LISTA1="${a} ${LISTA1}";
214 LISTA1="${LISTA1} Default";
216 select PROFILE in $LISTA1; do
217 if [ -n "${PROFILE}" ]; then
222 if [ "${PROFILE}" = "Default" ]; then
228 if [ -z "${PROFILE}" ]; then
229 if [ ! -f ${PROFDIR}/default.md5 ]; then
230 echo "Valid profile not found. Starting with current files."
233 echo "Valid profile not found. Starting with \"default\" profile."
238 if [ ! -z "${PROFILE}" ]; then
239 myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
240 if [ $QUIET -eq 0 ]; then
251 PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
253 if [ -z "${PROFILE}" ]; then
254 echo "No profile currenty running."
258 if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
259 echo "${PROFILE}.files is missing. Can't continue."
263 echo -n "Saving/updating current [${PROFILE}] profile "
264 md5sumgen > ${PROFDIR}/${PROFILE}.md5
266 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
269 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
270 myecho "${file}: invalid, skipping"
274 myecho "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
275 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
281 echo "List of configured profiles:"
283 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
284 prof=$(basename ${prof})
285 profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
286 echo "Name : ${profname}"
288 if [ -f ${PROFDIR}/${profname}.md5 ]; then
289 cat ${PROFDIR}/${profname}.desc
294 if [ -f ${PROFDIR}/${profname}.date ]; then
295 cat ${PROFDIR}/${profname}.date
300 if [ -f ${PROFDIR}/${profname}.md5 ]; then
301 cat ${PROFDIR}/${profname}.md5
306 if [ -f ${PROFDIR}/${profname}.files ]; then
307 cat ${PROFDIR}/${profname}.files | xargs
317 QUIET=1; export QUIET;
327 if [ "$#" -le "0" -o "$OPTIND" -eq 1 ]; then