2 # (C) 2001 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
3 # Hardware Profiles for rc-scripts TOTALNEW.
6 PROFDIR="/etc/sysconfig/hwprofiles"
9 [ -z "${EDITOR} " ] && EDITOR=vi
11 if [ "$(id -u)" != "0" ]; then
12 echo "Need superuser privileges. Can't continue!"
16 if [ ! -d ${PROFDIR} -o ! -d ${PROFDIR}/data ]; then
17 echo "${PROFDIR} or ${PROFDIR}/data not found. Can't continue!"
23 if [ "${QUIET}" != "1" ]; then
34 r foo - run specified profile or "default" if such exist
35 s - save/update running profile
36 f - find proper profile and run it
37 l - list configured profiles
38 q - be quiet (used only in few modes)
40 Please send all bug reports to:
41 pld-rc-scripts@pld.org.pl.
45 # This function probably must be enhanced.
49 grep -v "MHz" /proc/cpuinfo 2> /dev/null \
50 cat /proc/pci 2> /dev/null \
51 ) | md5sum | awk ' { gsub(/ .*$/,NIL); print $0 } '
54 while getopts adflsqr: opt "$@"; do
57 echo "Adding new profile..."
58 if [ -f /var/run/hwprofile ]; then
59 echo -n "Current profile is: "
60 cat /var/run/hwprofile
63 while [ -z "${PROFILE}" ]; do
64 echo -n "Enter profile name: "
66 if [ -f ${PROFDIR}/${PROFILE}.md5 ]; then
67 echo "Profile ${PROFILE} exist. Try other name."
71 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
72 md5sumgen > ${PROFDIR}/${PROFILE}.md5
73 LANG=C LC_ALL=C date > ${PROFDIR}/${PROFILE}.date
74 mkdir -p ${PROFDIR}/data/${PROFILE}/
75 chmod 700 ${PROFDIR}/data/${PROFILE}/
76 echo -n "Enter profile description (PROFDIR/${PROFILE}.desc): "
78 [ -z "${DESCRIPTION}" ] && DESCRIPTION="${PROFILE}"
79 echo "${DESCRIPTION}" > ${PROFDIR}/${PROFILE}.desc
80 echo "Now, editor will be started and you need to enter list of files"
81 echo "for this profile (later as ${PROFDIR}/${PROFILE}.files)."
84 ${EDITOR} ${PROFDIR}/${PROFILE}.files
86 echo "Validating and copying valid files for this profile:"
87 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
88 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
89 echo "${file}: invalid, skipping"
92 bfile=$(basename ${file})
93 echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}..."
94 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
95 FILES="${file}\n${FILES}"
97 echo -e "${FILES}" > ${PROFDIR}/${PROFILE}.files
98 rm -f ${PROFDIR}/${PROFILE}.*~
99 echo "New profile ready."
103 echo "Deleting existing profile..."
105 while [ -z ${PROFILE} ]; do
106 echo -n "Enter profile name: "
108 if [ ! -f ${PROFDIR}/${PROFILE}.md5 ]; then
109 echo "Profile ${PROFILE} doesn't exist. Try other name."
113 echo -n "Are you sure? [t/N]: "
124 rm -rf ${PROFDIR}/${PROFILE}.* ${PROFDIR}/data/${PROFILE}/
130 if [ -z "${PROFILE}" -o ! -f ${PROFDIR}/${PROFILE}.files ]; then
131 echo "Can't setup ${PROFILE}. No required data."
134 echo "Setting up profile \"${PROFILE}\"..."
135 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
136 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
137 echo "${file}: invalid, skipping"
140 echo "Copying ${PROFDIR}/data/${PROFILE}/${file} to ${file}..."
141 cp -dp ${PROFDIR}/data/${PROFILE}/${file} ${file}
143 myecho "Profile \"${PROFILE}\" running."
148 PROFILEMD5=$(md5sumgen)
149 myecho "Trying to find proper profile..."
150 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
151 prof=$(basename ${prof})
152 CURRENTMD5="$(cat ${PROFDIR}/${prof} 2> /dev/null)"
153 [ -z "${CURRENTMD5}" ] && continue
154 if [ "${CURRENTMD5}" = "${PROFILEMD5}" ]; then
155 PROFILE=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
159 if [ -z "${PROFILE}" ]; then
160 if [ ! -f ${PROFDIR}/default.md5 ]; then
161 echo "Valid profile not found. Starting with current files."
164 echo "Valid profile not found. Starting with \"default\" profile."
168 myecho "Found profile \"${PROFILE}\" with md5sum \"${PROFILEMD5}\"."
173 PROFILE=$(cat /var/run/hwprofile 2> /dev/null)
174 if [ -z "${PROFILE}" ]; then
175 echo "No profile currenty running."
178 if [ ! -f ${PROFDIR}/${PROFILE}.files ]; then
179 echo "${PROFILE}.files is missing. Can't continue."
182 echo "Saving/updating current profile..."
183 for file in $(grep -v "^#" ${PROFDIR}/${PROFILE}.files); do
184 if [ ! -f ${file} -o "${file}" = "/etc/sysconfig/hwprof" ]; then
185 echo "${file}: invalid, skipping"
188 echo "Copying ${file} to ${PROFDIR}/data/${PROFILE}/${file}"
189 cp -dp --parents ${file} ${PROFDIR}/data/${PROFILE}/
195 echo "List of configured profiles:"
196 for prof in $(ls -1 ${PROFDIR}/*.md5 2> /dev/null); do
197 prof=$(basename ${prof})
198 profname=$(echo ${prof} | awk ' { gsub(/\.md5/,NIL); print $0 } ')
199 echo "Name : ${profname}"
201 if [ -f ${PROFDIR}/${profname}.md5 ]; then
202 cat ${PROFDIR}/${profname}.desc
207 if [ -f ${PROFDIR}/${profname}.date ]; then
208 cat ${PROFDIR}/${profname}.date
213 if [ -f ${PROFDIR}/${profname}.md5 ]; then
214 cat ${PROFDIR}/${profname}.md5
219 if [ -f ${PROFDIR}/${profname}.files ]; then
220 cat ${PROFDIR}/${profname}.files | xargs
240 if [ "$#" -le "0" ]; then
247 # This must be last line !
248 # vi:syntax=sh:tw=78:ts=8:sw=2