|
| 1 | +#!/bin/bash |
| 2 | +# laptop-info |
| 3 | +# Prints some info about the current device |
| 4 | + |
| 5 | +# I want to know: |
| 6 | +# - System info |
| 7 | +# - memory size |
| 8 | +# - CPU info |
| 9 | +# - Disk size |
| 10 | +# - Disk health info |
| 11 | +# - Display info |
| 12 | + |
| 13 | +# Copyright (C) 2014-2015 Alexander Swen <alex@swen.nu> |
| 14 | + |
| 15 | +# This program is free software: you can redistribute it and/or modify |
| 16 | +# it under the terms of the GNU General Public License as published by |
| 17 | +# the Free Software Foundation; either version 2 of the License, or |
| 18 | +# (at your option) any later version. |
| 19 | + |
| 20 | +# This program is distributed in the hope that it will be useful, |
| 21 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | +# GNU General Public License for more details. |
| 24 | +# |
| 25 | +# You should have received a copy of the GNU General Public License |
| 26 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | + |
| 28 | +# Alexander Swen |
| 29 | +# Private contact: alex@swen.nu |
| 30 | + |
| 31 | +# CHANGELOG: |
| 32 | +# 2023-04-20 A.Swen created. |
| 33 | + |
| 34 | +# SETTINGS |
| 35 | +date=$(date +%Y%m%d) |
| 36 | +me=$(basename $0) |
| 37 | +mydir=$(dirname $0) |
| 38 | + |
| 39 | + |
| 40 | +# FUNCTIONS |
| 41 | +die () { |
| 42 | + rc=$1 |
| 43 | + shift |
| 44 | + printf '%s\n' "=====================" >&2 |
| 45 | + printf '%s\n' "==== FATAL ERROR ====" >&2 |
| 46 | + printf '%s\n\n' "=====================" >&2 |
| 47 | + printf '%s\n\n' "$@" >&2 |
| 48 | + exit $rc |
| 49 | +} |
| 50 | + |
| 51 | +usage () { |
| 52 | + printf '%s\n' "===============" >&2 |
| 53 | + printf '%s\n' "==== USAGE ====" >&2 |
| 54 | + printf '%s\n\n' "===============" >&2 |
| 55 | + printf '%s\n' "Usage: ${me} " >&2 |
| 56 | + printf '%s\n\n' "example: ${me} " >&2 |
| 57 | + exit 1 |
| 58 | +} |
| 59 | +get_options () { |
| 60 | + while [[ $# -gt 0 ]]; do |
| 61 | + case "$1" in |
| 62 | + --thing1|-a) |
| 63 | + shift |
| 64 | + declare -r thing="$1" |
| 65 | + shift |
| 66 | + ;; |
| 67 | + --thing2|-b) |
| 68 | + shift |
| 69 | + declare -r other_thing="$1" |
| 70 | + shift |
| 71 | + ;; |
| 72 | + -h|--help) |
| 73 | + usage |
| 74 | + ;; |
| 75 | + *) |
| 76 | + usage |
| 77 | + ;; |
| 78 | + esac |
| 79 | + done |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +log () { printf '%s %s\n' "$(date +%F' '%T)" "$@"; } |
| 84 | + |
| 85 | +# SCRIPT |
| 86 | +[ ${UID} -gt 0 ] && die 1 "Only root may do that." |
| 87 | +log "$(date) started ${me}" |
| 88 | +if [[ $# -gt 0 ]];then |
| 89 | + get_options |
| 90 | +fi |
| 91 | + |
| 92 | +# System info |
| 93 | +log "System information:" |
| 94 | +dmidecode -t system|grep -E "Product Name|Serial Number" |
| 95 | +echo |
| 96 | + |
| 97 | +# CPU |
| 98 | +log "CPU:" |
| 99 | +dmidecode -t processor|grep -E 'Family|Manufacturer|(Thread|Core) Count:|Max Speed:' |
| 100 | +echo |
| 101 | + |
| 102 | +# Memory |
| 103 | +log "Memory:" |
| 104 | +dmidecode -t memory | grep -E '^Physical Memory Array|Number Of Devices|^Memory Device|^\s+(Size|Type:|Manufacturer|Serial Number|Rank|Configured Memory Speed|Part Number|Locator)' |
| 105 | +echo |
| 106 | + |
| 107 | +# Disk |
| 108 | +log "Disk:" |
| 109 | +smartctl -a /dev/nvme0n1|grep -E '^(Model|Serial|Namespace 1 Size|Temperature|Available Spare:|Percentage Used|Warning|Critical)|Errors|self-assess' |
| 110 | +echo |
| 111 | + |
| 112 | +# Display |
| 113 | +log "Display:" |
| 114 | +lshw -c display |
| 115 | +xrandr |
| 116 | +log "$(date) finished" |
| 117 | +# END |
0 commit comments