diff --git a/x230/release.sh b/x230/release.sh index 37957ec..cfe6ea9 100755 --- a/x230/release.sh +++ b/x230/release.sh @@ -111,6 +111,7 @@ tar -cJf skulls-x230-"${version}".tar.xz \ NEWS \ util \ LICENSE* \ + skulls_common.sh \ x230_before_first_install.sh \ x230_skulls.sh \ x230_heads.sh \ diff --git a/x230/skulls_common.sh b/x230/skulls_common.sh new file mode 100755 index 0000000..af420b4 --- /dev/null +++ b/x230/skulls_common.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-3.0+ +# Copyright (C) 2018, Martin Kepplinger +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +NC='\033[0m' + +check_x230_root() +{ + command -v dmidecode >/dev/null 2>&1 || { echo -e >&2 "${RED}Please install dmidecode and run as root.${NC}"; exit 1; } + + local LAPTOP=$(dmidecode | grep -i x230 | sort -u) + if [ -z "$LAPTOP" ] ; then + echo "This is no Thinkpad X230. This script is useless then." + exit 0 + fi +} + +check_battery() { + local capacity=$(cat /sys/class/power_supply/BAT*/capacity 2>/dev/null || echo -ne "0") + local online=$(cat /sys/class/power_supply/AC/online 2>/dev/null || cat /sys/class/power_supply/ADP*/online 2>/dev/null || echo -ne "0") + local failed=0 + + if [ "${online}" == "0" ] ; then + failed=1 + fi + if [ "${capacity}" -lt 25 ]; then + failed=1 + fi + if [ $failed == "1" ]; then + echo -e "${YELLOW}WARNING:${NC} To prevent shutdowns, we recommend to only run this script when" + echo " your laptop is plugged in to the power supply AND" + echo " the battery is present and sufficiently charged (over 25%)." + while true; do + read -r -p "Continue anyways? (please do NOT!) y/N: " yn + case $yn in + [Yy]* ) break;; + [Nn]* ) exit;; + * ) exit;; + esac + done + fi +} + diff --git a/x230/x230_before_first_install.sh b/x230/x230_before_first_install.sh index 66fad4c..86c8659 100755 --- a/x230/x230_before_first_install.sh +++ b/x230/x230_before_first_install.sh @@ -5,6 +5,7 @@ RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' +. skulls_common.sh set -e usage() @@ -44,13 +45,7 @@ do shift done -command -v dmidecode >/dev/null 2>&1 || { echo -e >&2 "${RED}Please install dmidecode and run as root.${NC}"; exit 1; } - -LAPTOP=$(dmidecode | grep -i x230 | sort -u) -if [ -z "$LAPTOP" ] ; then - echo "This is no Thinkpad X230. This script is useless then." - exit 0 -fi +check_x230_root BIOS_VENDOR=$(dmidecode -t bios | grep Vendor | cut -d':' -f2) if [[ $BIOS_VENDOR = *"coreboot"* ]] ; then diff --git a/x230/x230_heads.sh b/x230/x230_heads.sh index 4c8cf30..64866e4 100755 --- a/x230/x230_heads.sh +++ b/x230/x230_heads.sh @@ -7,6 +7,9 @@ YELLOW='\033[0;33m' NC='\033[0m' set -e + +. skulls_common.sh + have_input_image=0 usage() @@ -22,32 +25,6 @@ usage() echo "Usage: $0 -i .rom" } -check_battery() { - local capacity=$(cat /sys/class/power_supply/BAT*/capacity 2>/dev/null || echo -ne "0") - local online=$(cat /sys/class/power_supply/AC/online 2>/dev/null || cat /sys/class/power_supply/ADP*/online 2>/dev/null || echo -ne "0") - local failed=0 - - if [ "${online}" == "0" ] ; then - failed=1 - fi - if [ "${capacity}" -lt 25 ]; then - failed=1 - fi - if [ $failed == "1" ]; then - echo -e "${YELLOW}WARNING:${NC} To prevent shutdowns, we recommend to only run this script when" - echo " your laptop is plugged in to the power supply AND" - echo " the battery is present and sufficiently charged (over 25%)." - while true; do - read -r -p "Continue anyways? (please do NOT!) y/N: " yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) exit;; - esac - done - fi -} - args=$(getopt -o i:h -- "$@") if [ $? -ne 0 ] ; then usage @@ -79,6 +56,8 @@ do shift done +check_x230_root + if [ ! "$have_input_image" -gt 0 ] ; then image_available=$(ls -1 | grep rom || true) if [ -z "${image_available}" ] ; then diff --git a/x230/x230_skulls.sh b/x230/x230_skulls.sh index 2e1fa04..11f3908 100755 --- a/x230/x230_skulls.sh +++ b/x230/x230_skulls.sh @@ -7,6 +7,9 @@ YELLOW='\033[0;33m' NC='\033[0m' set -e + +. skulls_common.sh + have_input_image=0 usage() @@ -20,32 +23,6 @@ usage() echo "Usage: $0 -i <4mb_top_image>.rom" } -check_battery() { - local capacity=$(cat /sys/class/power_supply/BAT*/capacity 2>/dev/null || echo -ne "0") - local online=$(cat /sys/class/power_supply/AC/online 2>/dev/null || cat /sys/class/power_supply/ADP*/online 2>/dev/null || echo -ne "0") - local failed=0 - - if [ "${online}" == "0" ] ; then - failed=1 - fi - if [ "${capacity}" -lt 25 ]; then - failed=1 - fi - if [ $failed == "1" ]; then - echo -e "${YELLOW}WARNING:${NC} To prevent shutdowns, we recommend to only run this script when" - echo " your laptop is plugged in to the power supply AND" - echo " the battery is present and sufficiently charged (over 25%)." - while true; do - read -r -p "Continue anyways? (please do NOT!) y/N: " yn - case $yn in - [Yy]* ) break;; - [Nn]* ) exit;; - * ) exit;; - esac - done - fi -} - args=$(getopt -o i:h -- "$@") if [ $? -ne 0 ] ; then usage @@ -77,6 +54,8 @@ do shift done +check_x230_root + if [ ! "$have_input_image" -gt 0 ] ; then image_available=$(ls -1 | grep x230_coreboot_seabios || true) if [ -z "${image_available}" ] ; then