Codebase list laptop-detect / 22db44c
Added debug mode Simó Albert i Beltran 6 years ago
2 changed file(s) with 21 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1818 laptop\-detect \- attempt to detect a laptop
1919 .SH "SYNOPSIS"
2020 .LP
21 laptop\-detect [\fI\-h\fR|\fI\-\-help\fR|\fI\-v\fR|\fI\-\-verbose\fR|\fI\-V\fR|\fI\-\-version\fR]
21 laptop\-detect [\fI\-h\fR|\fI\-\-help\fR|\fI\-v\fR|\fI\-\-verbose\fR|\fI\-V\fR|\fI\-\-version\fR|\fI\-D\fR|\fI\-\-debug\fR]
2222 .SH "DESCRIPTION"
2323 .LP
2424 Laptop\-detect attempts to determine whether it is being run on a laptop or a desktop and appraises its caller of this.
3333 .TP
3434 \fB\-V\fR \fB\-\-version\fR
3535 Output version information and exit.
36 .TP
37 \fB\-D\fR \fB\-\-debug\fR
38 Debug mode.
3639 .SH "EXIT STATUS"
3740 .br
3841 .nf
55 echo " -h | --help print this help"
66 echo " -v | --verbose be verbose (messages go to STDOUT)"
77 echo " -V | --version print version information"
8 echo " -D | --debug debug mode"
89 echo ""
910 echo " Possible return values:"
1011 echo " 0 most likely running on a laptop"
1112 echo " 1 most likely NOT running on a laptop"
12 echo " 2 called with unknown option, -h, --help, -V or --version"
13 echo " 2 called with unknown option, -h, --help, -V, --version, -D or --debug"
1314 }
1415
1516 PRINTIT="/bin/true" # /bin/true accepts any option but never prints anything
17 EXIT="exit" # replaced in debug mode by /bin/true
1618
1719 # Check wether we were asked to be verbose
1820
2931 usage
3032 exit 2
3133 ;;
34 "-D"|"--debug")
35 EXIT="/bin/true"
36 set -x
37 ;;
3238 *)
3339 echo "UNKNOWN OPTION: $1"
3440 usage
4248 batteries=$(grep Battery /proc/pmu/info | cut -f2 -d:)
4349 if test "$batteries" -ne 0; then
4450 $PRINTIT "We're a laptop (Mac: batteries found)" >&2;
45 exit 0
51 $EXIT 0
4652 fi
4753 exit 1
4854 fi
5864
5965 if test "$dmitype" = "Notebook" || test "$dmitype" = "Portable"; then
6066 $PRINTIT "We're a laptop (dmidecode returned $dmitype)" >&2
61 exit 0
67 $EXIT 0
6268 fi
6369
6470 # turn back on for debugging
7076 case "$chassis_type" in
7177 8) # Portable
7278 $PRINTIT "We're a portable (chassis_type is $chassis_type)" >&2
73 exit 0
79 $EXIT 0
7480 ;;
7581 9) # Laptop
7682 $PRINTIT "We're a laptop (chassis_type is $chassis_type)" >&2
77 exit 0
83 $EXIT 0
7884 ;;
7985 10) # Notebook
8086 $PRINTIT "We're a notebook (chassis_type is $chassis_type)" >&2
81 exit 0
87 $EXIT 0
8288 ;;
8389 11) # Hand Held
8490 $PRINTIT "We're a hand held (chassis_type is $chassis_type)" >&2
85 exit 0
91 $EXIT 0
8692 ;;
8793 esac
8894 fi
100106 )
101107 then
102108 $PRINTIT "We're a laptop (non device ACPI batteries found)" >&2
103 exit 0
109 $EXIT 0
104110 fi
105111 done
106112 fi
109115 results=`find /proc/acpi/battery -mindepth 1 -type d`
110116 if [ ! -z "$results" ]; then
111117 $PRINTIT "We're a laptop (ACPI batteries found)" >&2
112 exit 0
118 $EXIT 0
113119 fi
114120 fi
115121
120126 battery=`awk '{print $6}' </proc/apm`
121127 if [ "$battery" != "0xff" ] && [ "$battery" != "0x80" ]; then
122128 $PRINTIT "We're a laptop (APM batteries found)" >&2
123 exit 0
129 $EXIT 0
124130 fi
125131 fi
126132
127133 $PRINTIT "We're not on a laptop (no relevant hint found)" >&2
128 exit 1
134 $EXIT 1