]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - hwprofile
makefile fix
[projects/rc-scripts.git] / hwprofile
index 1be2ac0df73d5753dc2f79febdc99aa501bd3010..4f24a9e6ad8cecaff8839bdeb6c76d4a5c68152a 100755 (executable)
--- a/hwprofile
+++ b/hwprofile
@@ -1,7 +1,6 @@
 #!/bin/sh
-# (C) 2001 Arkadiusz Mikiewicz <misiek@pld.ORG.PL>
+# (C) 2001 Arkadiusz Miśkiewicz <misiek@pld.ORG.PL>
 # Hardware Profiles for rc-scripts TOTALNEW.
-# $Id$
 
 PROFDIR="/etc/sysconfig/hwprofiles"
 QUIET=0
@@ -12,24 +11,24 @@ QUIET=0
 [ -z "${EDITOR}" ] && EDITOR=vi
 
 if [ "$(id -u)" != "0" ]; then
-       echo "Need superuser privileges. Can't continue!"
+       echo "Need superuser privileges. Can't continue!"
        exit 1
 fi
 
 checkprofdir()
 {
-  if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
-         echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
+       if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
+               echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
                echo "Check /etc/sysconfig/hwprof and hwprofile -h."
-         exit 1
-  fi
+               exit 1
+       fi
 }
 
 myecho()
 {
-  if [ $QUIET -eq 0 ]; then
-    echo $@
-  fi
+       if [ $QUIET -eq 0 ]; then
+               echo $@
+       fi
 }
 
 showhelp()
@@ -52,284 +51,281 @@ pld-rc-scripts@pld-linux.org.
 # This function probably must be enhanced.
 md5sumgen()
 {
-  ( \
-  grep -v "MHz" /proc/cpuinfo 2> /dev/null \
-  grep -v "Latency" /proc/pci 2> /dev/null \
-  ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
+       ( \
+               grep -v "MHz" /proc/cpuinfo 2> /dev/null \
+               grep -v "Latency" /proc/pci 2> /dev/null \
+       ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
 }
 
 while getopts adfhlsqr: opt "$@"; do
        case "$opt" in
-               a)
-                 checkprofdir
-                       
-                 echo "Adding new profile..."
-                       
-                       if [ -f /var/run/hwprofile ]; then
-                               echo -n "Current profile is: "
-                               cat /var/run/hwprofile
+         a)
+               checkprofdir
+
+               echo "Adding new profile..."
+
+               if [ -f /var/run/hwprofile ]; then
+                       echo -n "Current profile is: "
+                       cat /var/run/hwprofile
+               fi
+
+               PROFILE=
+               while [ -z "${PROFILE}" ]; do
+                       echo -n "Enter profile name: "
+                       read PROFILE
+
+                       if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
+                               echo "Profile ${PROFILE} exist. Try other name."
+                               PROFILE=
                        fi
-                       
-                       PROFILE=
-                       while [ -z "${PROFILE}" ]; do
-                               echo -n "Enter profile name: "
-                               read PROFILE
-                               
-                               if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
-                                       echo "Profile ${PROFILE} exist. Try other name."
-                                       PROFILE=
-                               fi
-                       done
-                       
-                       rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
-                       md5sumgen > ${PROFDIR}/${PROFILE}.md5
-                       LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
-                       mkdir -p ${PROFDIR}/data/${PROFILE}/
-                       chmod 700 ${PROFDIR}/data/${PROFILE}/
-               
-                       echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
-                       read DESCRIPTION
-                       [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
-                       echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
-                       echo "Now, editor will be started and you need to enter list of files"
-                       echo "for this profile (later as ${EDITOR} ${PROFDIR}/${PROFILE}.files)."
-                       echo "Press Enter."
-                       read
-               
-                       if [ -f ${PROFDIR}/files -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
-                               cat ${PROFDIR}/files > ${PROFDIR}/${PROFILE}.files;
+               done
+
+               rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
+               md5sumgen > ${PROFDIR}/${PROFILE}.md5
+               LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
+               mkdir -p ${PROFDIR}/data/${PROFILE}/
+               chmod 700 ${PROFDIR}/data/${PROFILE}/
+
+               echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
+               read DESCRIPTION
+               [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
+               echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
+               echo "Now, editor will be started and you need to enter list of files"
+               echo "for this profile (later as ${EDITOR} ${PROFDIR}/${PROFILE}.files)."
+               echo "Press Enter."
+               read
+
+               if [ -f ${PROFDIR}/files -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
+                       cat ${PROFDIR}/files > ${PROFDIR}/${PROFILE}.files;
+               fi
+               ${EDITOR} ${PROFDIR}/${PROFILE}.files
+
+               FILES=
+               echo "Validating and copying valid files for this profile:"
+               for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
+                       if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
+                               echo "${file}: invalid, skipping"
+                               continue
                        fi
-                       ${EDITOR} ${PROFDIR}/${PROFILE}.files
-                       
-                       FILES=
-                       echo "Validating and copying valid files for this profile:"
-                       for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
-                               if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
-                                       echo "${file}: invalid, skipping"
-                                       continue
-                               fi
-               
-                               bfile=$(basename ${file})
-                               echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
-                               cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
-                               FILES="${file}\n${FILES}"
-                       done
-               
-                       echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
-                       rm -f ${PROFDIR}/${PROFILE}.*~
-               
-                       echo "New profile ready."
-                       break
+
+                       bfile=$(basename ${file})
+                       echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
+                       cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
+                       FILES="${file}\n${FILES}"
+               done
+
+               echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
+               rm -f ${PROFDIR}/${PROFILE}.*~
+
+               echo "New profile ready."
+               break
+               ;;
+         d)
+               checkprofdir
+
+               echo "Deleting existing profile..."
+
+               PROFILE=
+               while [ -z ${PROFILE} ]; do
+                       echo -n "Enter profile name: "
+                       read PROFILE
+
+                       if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
+                               echo "Profile ${PROFILE} doesn't exist. Try other name."
+                               PROFILE=
+                       fi
+               done
+
+               echo -n "Are you sure? [y/N]: "
+               read YN
+               case "${YN}" in
+                 y | Y | t | T )
+                       # ok
                        ;;
-    d)
-                 checkprofdir
-                       
-               echo "Deleting existing profile..."
-               
-                       PROFILE=
-                       while [ -z ${PROFILE} ]; do
-                               echo -n "Enter profile name: "
-                               read PROFILE
-               
-                               if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
-                                       echo "Profile ${PROFILE} doesn't exist. Try other name."
-                                       PROFILE=
-                               fi
-                       done
-               
-                       echo -n "Are you sure? [y/N]: "
-                       read YN
-                       case "${YN}" in
-                               y | Y | t | T )
-                                                                                               # ok
-                                                                                               ;;
-                               *)
-                                                                                               echo "Exiting then."
-                                                                                               exit 1
-                                                                                               ;;
-                       esac
-               
-                       rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
-                       echo "Done."
-                       break
+                 *)
+                       echo "Exiting then."
+                       exit 1
                        ;;
-    r)
-
-                 checkprofdir
-                       
-       PROFILE="${OPTARG}"
-               
-                       if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
-                               echo "Can't setup ${PROFILE}. No required data."
-                               exit 1
+               esac
+
+               rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
+               echo "Done."
+               break
+               ;;
+         r)
+
+               checkprofdir
+
+               PROFILE="${OPTARG}"
+
+               if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
+                       echo "Can't setup ${PROFILE}. No required data."
+                       exit 1
+               fi
+
+               echo -n "Setting up profile \"${PROFILE}\" "
+               myecho "";
+
+               for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
+                       if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
+                               myecho "${file}: invalid, skipping"
+                               continue
                        fi
-                       
-                       echo -n "Setting up profile \"${PROFILE}\" "
-                       myecho "";
-               
-                       for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
-                               if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
-                                       myecho "${file}: invalid, skipping"
-                                       continue
-                               fi
-                               echo -n ".";
-               
-                               myecho "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
-                               cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file} 2>/dev/null
-                       done
-               
-                       echo ${PROFILE} > /var/run/hwprofile
-                       echo " Done.";
-                       myecho "Profile \"${PROFILE}\" running."
-                       break
-                       ;;
-    f)
-                 checkprofdir
-                       
-       PROFILE=
-       PROFILEMD5=$(md5sumgen)
-               
-                       myecho "Trying to find proper profile..."
-                       for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
-                               prof=$(basename ${prof})
-                               CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
-                               # echo "$prof ${CURRENTMD5} ${PROFILEMD5}";
-                               [ -z "${CURRENTMD5}" ] && continue
-               
-                               if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
-                                       PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
-                                       break;
-                               fi
-                       done
-               
-                       if [ -z "${PROFILE}" ]; then
-                               if is_yes "${ASKFORPROFILE}"; then
-                                       echo "Available profiles:";
-                                       PS3='Enter profile number: ';
-                                       LISTA=$(ls ${PROFDIR}/*.desc 2> /dev/null);
-                                       for i in ${LISTA}; do
-                                               a=$(basename $i .desc);
-                                               LISTA1="${a} ${LISTA1}";
-                                       done
-                                       LISTA1="${LISTA1} Default";
-               
-                                       select PROFILE in $LISTA1; do
-                                       if [ -n "${PROFILE}" ]; then
-                                                       break
-                                               fi
-                                       done
-               
-                                       if [ "${PROFILE}" = "Default" ]; then
-                                               PROFILE=
+                       echo -n ".";
+
+                       myecho "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
+                       cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file} 2>/dev/null
+               done
+
+               echo ${PROFILE} > /var/run/hwprofile
+               echo " Done.";
+               myecho "Profile \"${PROFILE}\" running."
+               break
+               ;;
+         f)
+               checkprofdir
+
+               PROFILE=
+               PROFILEMD5=$(md5sumgen)
+
+               myecho "Trying to find proper profile..."
+               for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
+                       prof=$(basename ${prof})
+                       CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
+                       # echo "$prof ${CURRENTMD5} ${PROFILEMD5}";
+                       [ -z "${CURRENTMD5}" ] && continue
+
+                       if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
+                               PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
+                               break;
+                       fi
+               done
+
+               if [ -z "${PROFILE}" ]; then
+                       if is_yes "${ASKFORPROFILE}"; then
+                               echo "Available profiles:";
+                               PS3='Enter profile number: ';
+                               LISTA=$(ls ${PROFDIR}/*.desc 2> /dev/null);
+                               for i in ${LISTA}; do
+                                       a=$(basename $i .desc);
+                                       LISTA1="${a} ${LISTA1}";
+                               done
+                               LISTA1="${LISTA1} Default";
+
+                               select PROFILE in $LISTA1; do
+                                       if [ -n "${PROFILE}" ]; then
+                                               break
                                        fi
+                               done
+
+                               if [ "${PROFILE}" = "Default" ]; then
+                                       PROFILE=
                                fi
                        fi
+               fi
 
-                       if [ -z "${PROFILE}" ]; then
-                               if [ ! -f ${PROFDIR}/default.md5 ]; then
-                                       echo "Valid profile not found. Starting with current files."
-                                       exit 0
-                               else
-                                       echo "Valid profile not found. Starting with \"default\" profile."
-                                       PROFILE=default
-                               fi
+               if [ -z "${PROFILE}" ]; then
+                       if [ ! -f ${PROFDIR}/default.md5 ]; then
+                               echo "Valid profile not found. Starting with current files."
+                               exit 0
+                       else
+                               echo "Valid profile not found. Starting with \"default\" profile."
+                               PROFILE=default
                        fi
-               
-                       if [ ! -z "${PROFILE}" ]; then
-                               myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
-                               if [ $QUIET -eq 0 ]; then
-                                       $0 -r ${PROFILE};
-                               else
-                                       $0 -qr ${PROFILE};
-                               fi
+               fi
+
+               if [ ! -z "${PROFILE}" ]; then
+                       myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
+                       if [ $QUIET -eq 0 ]; then
+                               $0 -r ${PROFILE};
+                       else
+                               $0 -qr ${PROFILE};
                        fi
-                       break
-                       ;;
-    s)
-                 checkprofdir
-                       
-               PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
-               
-                       if [ -z "${PROFILE}" ]; then
-                               echo "No profile currenty running."
-                               exit 1
+               fi
+               break
+               ;;
+         s)
+               checkprofdir
+
+               PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
+
+               if [ -z "${PROFILE}" ]; then
+                       echo "No profile currenty running."
+                       exit 1
+               fi
+
+               if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
+                       echo "${PROFILE}.files is missing. Can't continue."
+                       exit 1
+               fi
+
+               echo -n "Saving/updating current [${PROFILE}] profile "
+               md5sumgen > ${PROFDIR}/${PROFILE}.md5
+               myecho "";
+               for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
+                       echo -n ".";
+
+                       if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
+                               myecho "${file}: invalid, skipping"
+                               continue
                        fi
-               
-                       if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
-                               echo "${PROFILE}.files is missing. Can't continue."
-                               exit 1
+
+                       myecho "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
+                       cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
+               done
+               echo " Done."
+               break
+               ;;
+         l)
+               echo "List of configured profiles:"
+
+               for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
+                       prof=$(basename ${prof})
+                       profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
+                       echo    "Name    : ${profname}"
+                       echo -n "Desc    : "
+                       if [ -f ${PROFDIR}/${profname}.md5 ]; then
+                               cat ${PROFDIR}/${profname}.desc
+                       else
+                               echo "MISSING"
                        fi
-               
-                       echo  -n "Saving/updating current [${PROFILE}] profile "
-                       md5sumgen > ${PROFDIR}/${PROFILE}.md5
-                       myecho "";
-                       for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
-                               echo -n ".";
-               
-                               if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
-                                       myecho "${file}: invalid, skipping"
-                                       continue
-                               fi
-               
-                               myecho "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
-                               cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/ 
-                       done
-                       echo " Done."
-                       break
-                       ;;
-    l)
-                       echo "List of configured profiles:"
-               
-                       for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
-                               prof=$(basename ${prof})
-                               profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
-                               echo    "Name    : ${profname}"
-                               echo -n "Desc    : "
-                               if [ -f ${PROFDIR}/${profname}.md5 ]; then
-                                       cat ${PROFDIR}/${profname}.desc
-                               else
-                                       echo "MISSING"
-                               fi
-                               echo -n "Created : "
-                               if [ -f ${PROFDIR}/${profname}.date ]; then
-                                       cat ${PROFDIR}/${profname}.date
-                               else
-                                       echo "MISSING"
-                               fi
-                               echo -n "md5sum  : "
-                               if [ -f ${PROFDIR}/${profname}.md5 ]; then
-                                       cat ${PROFDIR}/${profname}.md5
-                               else
-                                       echo "MISSING"
-                               fi
-                               echo -n "Files   : "
-                               if [ -f ${PROFDIR}/${profname}.files ]; then
-                                       cat ${PROFDIR}/${profname}.files | xargs
-                               else
-                                       echo "MISSING"
-                               fi
-                               echo
-                       done
-                       echo "End."
-                       break
-                       ;;
-    q)
-       QUIET=1; export QUIET;
-                       ;;
-    *)
-                       showhelp
-                       exit 1
-                       break
-                       ;;
-  esac
+                       echo -n "Created : "
+                       if [ -f ${PROFDIR}/${profname}.date ]; then
+                               cat ${PROFDIR}/${profname}.date
+                       else
+                               echo "MISSING"
+                       fi
+                       echo -n "md5sum  : "
+                       if [ -f ${PROFDIR}/${profname}.md5 ]; then
+                               cat ${PROFDIR}/${profname}.md5
+                       else
+                               echo "MISSING"
+                       fi
+                       echo -n "Files   : "
+                       if [ -f ${PROFDIR}/${profname}.files ]; then
+                               cat ${PROFDIR}/${profname}.files | xargs
+                       else
+                               echo "MISSING"
+                       fi
+                       echo
+               done
+               echo "End."
+               break
+               ;;
+         q)
+               QUIET=1; export QUIET;
+               ;;
+         *)
+               showhelp
+               exit 1
+               break
+               ;;
+       esac
 done
 
 if [ "$#" -le "0" -o "$OPTIND" -eq 1 ]; then
-  showhelp
-  exit 1
+       showhelp
+       exit 1
 fi
 
 exit 0
-
-# This must be last line !
-# vi:syntax=sh:ts=2:sw=2
This page took 0.066366 seconds and 4 git commands to generate.