external-tool-tester.sh 2.27 KB
Newer Older
Mark Vander Stel's avatar
Mark Vander Stel committed
1
2
3
4
5
#!/bin/sh

# Do NOT error on failed commands
set +e

Mark Vander Stel's avatar
Mark Vander Stel committed
6
7
8
9
10
11
12
# Don't error (or do anything) for no matching globs.
if [ -n "${ZSH_VERSION-}" ]; then
  setopt nullglob
else  # Bash
  shopt -s nullglob
fi

Mark Vander Stel's avatar
Mark Vander Stel committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Error if the output is a terminal
if [ -t 1 ]; then
  printf 'This script must be redirected to a file, or special characters will be lost
  Ex: %s > output.txt\nOr, to upload directly:
  %s | curl -F "sprunge=<-" "http://sprunge.us"\n' "$0" "$0"
  exit 1
fi

# Export needed variables
export LC_ALL=C

# Print OS info
printf -- '---Uname:\n'
uname -a
printf -- '---lpb_release:\n'
lsb_release -a 2>/dev/null || printf '<none>\n'
printf -- '---/etc/*release:\n'
cat /etc/*release 2>/dev/null || printf '<none>\n'
printf -- '---/etc/issue*:\n'
cat /etc/issue* 2>/dev/null || printf '<none>\n'
printf -- '---/proc/version:\n'
cat /proc/version 2>/dev/null || printf '<none>\n'

# Sanity check to verify special characters have not been lost on upload
37
printf '\nSpecial character check: \a\b\t\001\r\n'
Mark Vander Stel's avatar
Mark Vander Stel committed
38

Mark Vander Stel's avatar
Mark Vander Stel committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
test_tool() {
  local stderr
  printf '\nCommand: "%s"\n--------stdout--------\n' "$*"
  { stderr="$( { "$@"; } 2>&1 1>&3 3>&- )"; } 3>&1
  printf '\n--------stderr--------\n%s\n----------------------\nReturn code: "%s"\n' "$stderr" "$?"
}

test_tool uname

hostname_cksum() {
  hostname | cksum
}
test_tool hostname_cksum

test_tool tput sgr0
test_tool tput me
test_tool tput bold
test_tool tput md
test_tool tput smul
test_tool tput us
test_tool tput colors
test_tool tput setaf 0
test_tool tput AF 0
test_tool tput AF 0 0 0
test_tool tput setab 0
test_tool tput AB 0
test_tool tput AB 0 0 0

test_tool who am i
test_tool ps -o comm= -p "$PPID"
test_tool logname

test_tool screen -ls
test_tool tmux list-sessions

Mark Vander Stel's avatar
Mark Vander Stel committed
74
75
76
77
78
for power_supply in "/sys/class/power_supply/"*; do
  for interface in "${power_supply}/"*; do
    test_tool cat "$interface"
  done
done
Mark Vander Stel's avatar
Mark Vander Stel committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
test_tool acpi --battery
test_tool pmset -g batt

test_tool nproc
# Not actually a command used, we read directly from the file
test_tool cat /proc/loadavg
test_tool sysctl -n hw.ncpu
test_tool sysctl -n vm.loadavg
test_tool kstat -m cpu_info
test_tool uptime

test_tool sensors -u
test_tool acpi -t

test_tool date '+%I %M'
test_tool tty
test_tool basename -- /dev/pts/0
Mark Vander Stel's avatar
Mark Vander Stel committed
96
97

printf 'Tests complete.\nMake sure to upload the file directly, do not `cat` and copy paste!\n' >&2