From: Michael Prokop Date: Wed, 6 Sep 2023 15:26:11 +0000 (+0200) Subject: Release new version 2.13.0 X-Git-Tag: v2.13.0^0 X-Git-Url: http://git.grml.org/?p=grml-scripts.git;a=commitdiff_plain;h=HEAD;hp=34819b81d79e260d1fca486316806bc1b2e33896 Release new version 2.13.0 --- diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..c988196 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,59 @@ +name: Code Testing + +on: + push: + pull_request: + schedule: + - cron: '42 1 * * *' + +jobs: + spellcheck: + runs-on: ubuntu-latest + name: Run spellcheck + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Update APT cache + run: sudo apt-get update + + - name: Install lintian + run: sudo apt-get -y install lintian + + - name: Spellcheck execution + run: make spellcheck + + codecheck: + runs-on: ubuntu-latest + name: Run codecheck + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Display original shellcheck version + run: shellcheck --version + + - name: Update shellcheck to latest stable version + run: | + wget -qO- https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz | tar -xJv + sudo cp shellcheck-stable/shellcheck /usr/bin/ + + - name: pip install flake8, isort + black + run: pip3 install -U flake8 isort black + + - name: Display current shellcheck version + run: shellcheck --version + + - name: Display current flake8 version + run: flake8 --version + + - name: Display current isort version + run: isort --version + + - name: Display current black version + run: black --version + + - name: Codecheck execution + run: make --keep-going codecheck diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bcbfe07 --- /dev/null +++ b/Makefile @@ -0,0 +1,68 @@ +.DEFAULT_GOAL:=help + +help: ## Display this help + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) + +allcheck: codecheck spellcheck ## Run codecheck and spellcheck + +codecheck: shellcheck pythoncheck ## Run shellcheck and pythoncheck + +.ONESHELL: +shellcheck: ## Run shellcheck + @RETURN=0 + @for shellfile in $$(ls usr_bin/* usr_sbin/* usr_share/*); do + @ [ "$${shellfile}" = "usr_bin/iimage" ] && continue + @ [ "$${shellfile}" = "usr_sbin/make_chroot_jail" ] && continue + @ file "$${shellfile}" | grep -q shell && (shellcheck -x "$${shellfile}" || RETURN=1) + @done + @exit $${RETURN} + +.ONESHELL: +pythoncheck: ## Run pythoncheck (flakecheck, isortcheck + blackcheck) + @RETURN=0 + @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do + @ if head -1 "$${pythonfile}" | grep -q "python"; then + @ flake8 --max-line-length 88 "$${pythonfile}" || RETURN=1 + @ isort --check "$${pythonfile}" || RETURN=1 + @ black --check "$${pythonfile}" || RETURN=1 + @ fi + @done + @exit $${RETURN} + +.ONESHELL: +flakecheck: ## Run flake8 only + @RETURN=0 + @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do + @ if head -1 "$${pythonfile}" | grep -q "python"; then + @ flake8 --max-line-length 88 "$${pythonfile}" || RETURN=1 + @ fi + @done + @exit $${RETURN} + +.ONESHELL: +isortcheck: ## Run isort --check only + @RETURN=0 + @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do + @ if head -1 "$${pythonfile}" | grep -q "python"; then + @ isort --check "$${pythonfile}" || RETURN=1 + @ fi + @done + @exit $${RETURN} + +.ONESHELL: +blackcheck: ## Run black --check only + @RETURN=0 + @for pythonfile in usr_bin/* usr_sbin/* usr_share/*; do + @ if head -1 "$${pythonfile}" | grep -q "python"; then + @ black --check "$${pythonfile}" || RETURN=1 + @ fi + @done + @exit $${RETURN} + +.ONESHELL: +spellcheck: ## Run spellcheck + @OUTPUT="$$(spellintian manpages/*)" + @echo $$OUTPUT + @if [ -n "$$OUTPUT" ]; then + @ false + @fi diff --git a/compile/.gitignore b/compile/.gitignore index 5f8d282..c6f80a9 100644 --- a/compile/.gitignore +++ b/compile/.gitignore @@ -1,4 +1,3 @@ align dpkg_not_running -vmware-detect grml-runtty diff --git a/compile/Makefile b/compile/Makefile index a5d42c3..964ae3c 100644 --- a/compile/Makefile +++ b/compile/Makefile @@ -1,4 +1,4 @@ -PROGS = vmware-detect dpkg_not_running grml-runtty +PROGS = dpkg_not_running grml-runtty #ifndef CFLAGS CFLAGS = -O2 -Wall -s @@ -14,9 +14,6 @@ CC = gcc all: $(PROGS) -vmware-detect: vmware-detect.c - diet $(CC) $(CFLAGS) -o $@ $^ - dpkg_not_running: dpkg_not_running.c diet $(CC) $(CFLAGS) -o $@ $^ diff --git a/compile/vmware-detect.c b/compile/vmware-detect.c deleted file mode 100644 index c99e36f..0000000 --- a/compile/vmware-detect.c +++ /dev/null @@ -1,143 +0,0 @@ -/* Filename: vmware-detect.c -* Purpose: Detect if running inside vmware -* Authors: grml-team (grml.org), (c) Michael Gebetsroither -* Bug-Reports: see http://grml.org/bugs/ -* License: This file is licensed under the GPL v2. -*******************************************************************************/ -// return 0 if running inside vmware, 1 otherwise - -#include "string.h" -#include "unistd.h" -#include "stdio.h" -#include "stdlib.h" -#include "signal.h" - -#define WRITE(x) write(1, x, strlen(x)) -#define DWRITE(x) do{ \ - if(debug) { \ - WRITE(x); \ - } \ -} while(0); -#define FALSE 0 -#define TRUE !FALSE - -/* doc: - * vmware IO backdoor: http://chitchat.at.infoseek.co.jp/vmware/backdoor.html - * http://www.honeynet.org/papers/bots/botnet-code.html - * http://www.codegurus.be/codegurus/Programming/virtualpc&vmware_en.htm - */ - -// from libowfat {{{ -static inline char tohex(char c) { - return c>=10?c-10+'a':c+'0'; -} - -unsigned int fmt_xlong(char *dest,unsigned long i) { - register unsigned long len,tmp; - /* first count the number of bytes needed */ - for (len=1, tmp=i; tmp>15; ++len) tmp>>=4; - if (dest) - for (tmp=i, dest+=len; ; ) { - *--dest = tohex(tmp&15); - if (!(tmp>>=4)) break; - } - return len; -} -// }}} - -void printIdtr(const unsigned char* idtr, unsigned size) -{ - unsigned i; - for(i=0; i Wed, 06 Sep 2023 17:24:49 +0200 + +grml-scripts (2.12.2) unstable; urgency=medium + + [ Michael Schierl ] + * [099f921] Fix `grml2ram` when booted via `loopback.cfg` + + -- Michael Prokop Fri, 03 Feb 2023 17:26:26 +0100 + +grml-scripts (2.12.1) unstable; urgency=medium + + [ Darshaka Pathirana ] + * [b382566] grml-resolution: Quick 'n dirty xrandr output parser fix + + -- Michael Prokop Mon, 28 Nov 2022 08:35:17 +0100 + +grml-scripts (2.12.0) unstable; urgency=medium + + [ Darshaka Pathirana ] + * [570d959] Set SHELL variable in run-welcome + run-screen + + -- Michael Prokop Fri, 25 Nov 2022 09:50:44 +0100 + +grml-scripts (2.11.2) unstable; urgency=medium + + * [454a3e5] iimage: replace egrep usage with grep -E + + -- Michael Prokop Fri, 11 Nov 2022 17:01:40 +0100 + +grml-scripts (2.11.1) unstable; urgency=medium + + * [40ec66c] Drop debian/compat and switch to debhelper-compat approach + * [3b7f948] grml_chroot: fix broken mount argument handling + + -- Michael Prokop Tue, 07 Jun 2022 15:59:26 +0200 + +grml-scripts (2.11.0) unstable; urgency=medium + + [ Darshaka Pathirana ] + * [cb8ed97] Add Code testing workflow + * [e41ddb1] Makefile: Do not shellcheck iimage + * [584376f] Makefile: Do not shellcheck make_chroot_jail + * [02a237b] Makefile: return error if a check fails + * [95f1a38] grml-swapon.8: Fix spelling (via spellintian) + * [a4b7aa6] grepedit/notifyd.py: Convert to Python 3 + * Many shellcheck related changes + + -- Michael Prokop Fri, 06 May 2022 14:06:47 +0200 + +grml-scripts (2.10.0) unstable; urgency=medium + + * [7bbfe54] grml-chroot: support efivarfs in EFI environments + + -- Michael Prokop Fri, 09 Jul 2021 09:15:50 +0200 + +grml-scripts (2.9.1) unstable; urgency=medium + + * [749ee8e] grml-info: drop support for deprecated gdialog and prefer + zenity over Xdialog + * [09e5d68] grml-lock: drop gdialog usage and don't wrap text in zenity + + -- Michael Prokop Sun, 19 Jul 2020 18:09:17 +0200 + +grml-scripts (2.9.0) unstable; urgency=medium + + * [34819b8] grml2ram: switch default mount point from + /lib/live/mount/medium to /run/live/medium + + -- Michael Prokop Thu, 21 Mar 2019 12:25:51 +0100 + grml-scripts (2.8.4) unstable; urgency=medium * [74367b9] grml-chroot: bind-mount /run/udev in target system as diff --git a/debian/compat b/debian/compat deleted file mode 100644 index f599e28..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -10 diff --git a/debian/control b/debian/control index 5fcd241..a944854 100644 --- a/debian/control +++ b/debian/control @@ -3,7 +3,7 @@ Section: utils Priority: optional Maintainer: Michael Prokop Build-Depends: asciidoc, - debhelper (>= 10~), + debhelper-compat (= 12), dietlibc-dev, docbook-xsl, xsltproc diff --git a/debian/overrides b/debian/overrides index 1785ad1..7ed3bef 100644 --- a/debian/overrides +++ b/debian/overrides @@ -1,3 +1,2 @@ grml-scripts: script-with-language-extension usr/bin/notifyd.py -grml-scripts: statically-linked-binary usr/bin/vmware-detect grml-scripts: statically-linked-binary usr/sbin/dpkg_not_running diff --git a/debian/rules b/debian/rules index b5632fe..d9bebef 100755 --- a/debian/rules +++ b/debian/rules @@ -39,7 +39,6 @@ install: build cp -a usr_bin/* debian/grml-scripts/usr/bin/ cp -a usr_sbin/* debian/grml-scripts/usr/sbin/ cp -a usr_share/* debian/grml-scripts/usr/share/grml-scripts/ - install -m 755 compile/vmware-detect debian/grml-scripts/usr/bin/vmware-detect install -m 755 compile/dpkg_not_running debian/grml-scripts/usr/sbin/dpkg_not_running install -m 755 compile/grml-runtty debian/grml-scripts/sbin/grml-runtty @@ -85,7 +84,7 @@ binary-arch: build install /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/pong.1.gz \ /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/soundtest.1.gz \ /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/unblacklist.1.gz \ - /usr/share/man/man1/grml-scripts.1.gz /usr/share/man/man1/vmware-detect.1.gz + dh_strip dh_compress mkdir -p $(CURDIR)/debian/grml-scripts/usr/share/lintian/overrides/ diff --git a/manpages/grml-swapon.8 b/manpages/grml-swapon.8 index 8ede4c1..965be99 100644 --- a/manpages/grml-swapon.8 +++ b/manpages/grml-swapon.8 @@ -8,7 +8,7 @@ grml\-swapon \- activate swap partitions with taking care of suspend signatures grml-swapon is a small script for enabling swap partitions found in /etc/fstab. Starting with grml 0.9 booting the live-cd system does not activate swap -parititions by default anymore. It is possible to force usage of swap partitions +partitions by default anymore. It is possible to force usage of swap partitions via booting with the bootoption "swap". In case you forgot to use this bootoption but want to use swap partition(s) anyway you could do that by running "swapon \-a". But the command "swapon" does not take of suspend signatures, diff --git a/usr_bin/grepedit b/usr_bin/grepedit index 2d5730b..9908ff2 100755 --- a/usr_bin/grepedit +++ b/usr_bin/grepedit @@ -1,20 +1,20 @@ #!/usr/bin/python -## Copyright 2005 Drew Perttula - -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# Copyright 2005 Drew Perttula + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """sometimes we grep for something in a bunch of files, and then we want to make edits to the lines that were returned from the grep. It's @@ -49,9 +49,14 @@ ez_setup.py-179- for name in filenames: """ -import tempfile, sys, os, re +import os +import re +import sys +import tempfile + from sets import Set + def grep_parse(filename): """parse grep output lines in given file into a dict of (filename, lineno) : text""" @@ -59,41 +64,50 @@ def grep_parse(filename): for line in open(filename): if line == "--\n": continue - m = re.match(r"(?P.*?)(?P[-:])(?P\d+)(?P=sep)(?P.*\n)$", line) + m = re.match( + r"(?P.*?)(?P[-:])(?P\d+)(?P=sep)(?P.*\n)$", + line, + ) if m is None: - print "couldn't parse grep result line %r" % line + print("couldn't parse grep result line %r" % line) continue - filename, lineno, text = (m.group('filename'), int(m.group('lineno')), - m.group('line')) - if (filename,lineno) in parse: - raise ValueError("multiple results found for %s:%s" % - (filename, lineno)) + filename, lineno, text = ( + m.group("filename"), + int(m.group("lineno")), + m.group("line"), + ) + if (filename, lineno) in parse: + raise ValueError("multiple results found for %s:%s" % (filename, lineno)) parse[(filename, lineno)] = text return parse + options = {} passthru_args = [] for arg in sys.argv[1:]: if arg == "--sort-text": - options['sort-text'] = True + options["sort-text"] = True continue passthru_args.append(arg) tf = tempfile.NamedTemporaryFile(prefix="grepedit_") tf.close() -cmd = ("grep --with-filename --line-number --binary-files=without-match %s > %s" % - (" ".join(['"%s"' % s.replace("\\","\\\\").replace('"','\\"') - for s in passthru_args]),tf.name)) +cmd = "grep --with-filename --line-number --binary-files=without-match %s > %s" % ( + " ".join( + ['"%s"' % s.replace("\\", "\\\\").replace('"', '\\"') for s in passthru_args] + ), + tf.name, +) os.system(cmd) originals = grep_parse(tf.name) -if options.get('sort-text', False): - orig = [(v,k) for k,v in originals.items()] +if options.get("sort-text", False): + orig = [(v, k) for k, v in list(originals.items())] orig.sort() f = open(tf.name, "w") - for text, (filename,lineno) in orig: + for text, (filename, lineno) in orig: f.write("%s:%s:%s" % (filename, lineno, text)) f.close() @@ -101,25 +115,29 @@ os.system("%s %s" % (os.getenv("EDITOR"), tf.name)) corrections = grep_parse(tf.name) -files = Set([filename for filename,lineno in corrections.keys()]) +files = Set([filename for filename, lineno in list(corrections.keys())]) for orig_filename in files: (copy_fd, copy_filename) = tempfile.mkstemp( dir=os.path.dirname(orig_filename), - prefix="_%s_tmp_grepedit" % os.path.basename(orig_filename)) + prefix="_%s_tmp_grepedit" % os.path.basename(orig_filename), + ) any_changes = False - for lineno,line in enumerate(open(orig_filename)): - lineno = lineno + 1 # grep is 1-based - key = orig_filename,lineno + for lineno, line in enumerate(open(orig_filename)): + lineno = lineno + 1 # grep is 1-based + key = orig_filename, lineno if key in corrections: if line != originals[key]: - print "%s:%s has changed since the grep command ran- not modifying this line" % key - print repr(line) - print repr(originals[key]) + print( + "%s:%s has changed since the grep command ran- " + "not modifying this line" % key + ) + print(repr(line)) + print(repr(originals[key])) elif corrections[key] == line: pass else: - print "%s:%s substituting new line" % key + print("%s:%s substituting new line" % key) line = corrections[key] any_changes = True os.write(copy_fd, line) @@ -128,7 +146,5 @@ for orig_filename in files: if any_changes: os.rename(copy_filename, orig_filename) else: - print "no changes made in file %s" % orig_filename + print("no changes made in file %s" % orig_filename) os.unlink(copy_filename) - - diff --git a/usr_bin/grml-exec-wrapper b/usr_bin/grml-exec-wrapper index d3ff8ee..4e5a3cc 100755 --- a/usr_bin/grml-exec-wrapper +++ b/usr_bin/grml-exec-wrapper @@ -6,15 +6,16 @@ # License: This file is licensed under the GPL v2 or any later version. ################################################################################ +PN=$(basename "$0") + usage() { - printf "Usage: $0 [] + printf "Usage: %s [] Available options: -h | --help display this usage information -p check specified argument instead of default args, like: - $(basename $0) -p aumix xterm -T aumix -e aumix -" + %s -p aumix xterm -T aumix -e aumix\n" "${PN}" "${PN}" } is_installed() { @@ -49,7 +50,7 @@ else fi } -if [ -z "$1" -o "$1" = '-h' -o "$1" = '--help' ] ; then +if [ -z "$1" ] || [ "$1" = '-h' ] || [ "$1" = '--help' ] ; then usage exit 1 fi @@ -80,7 +81,7 @@ Looks like the grml flavour you are using does not ship ${PROG}. :( You can search for ${PROG} executing: -apt-get update && apt-cache search $(basename ${PROG}) +apt-get update && apt-cache search $(basename "${PROG}") " exit 1 diff --git a/usr_bin/grml-info b/usr_bin/grml-info index 1f31776..0017344 100755 --- a/usr_bin/grml-info +++ b/usr_bin/grml-info @@ -29,15 +29,12 @@ if [ -n "$DISPLAY" ] ; then firefox $PAGE elif check4progs x-www-browser &>/dev/null ; then x-www-browser $PAGE + elif check4progs zenity &>/dev/null ; then + zenity --no-wrap --error --text="Sorry, no usable X browser (dillo, xlinks2, firefox,...) found." + exit 1 elif check4progs Xdialog &>/dev/null ; then Xdialog --msgbox "Sorry, no usable X browser (dillo, xlinks2, firefox,...) found." 0 0 exit 1 - elif check4progs gdialog &>/dev/null ; then - gdialog --msgbox "Sorry, no usable X browser (dillo, xlinks2, firefox,...) found." 0 0 - exit 1 - elif check4progs zenity &>/dev/null ; then - zenity --info --text="Sorry, no usable X browser (dillo, xlinks2, firefox,...) found." - exit 1 fi else # no X: # do we have a real console? diff --git a/usr_bin/grml-lang b/usr_bin/grml-lang index 0e774ae..52b81a0 100755 --- a/usr_bin/grml-lang +++ b/usr_bin/grml-lang @@ -7,10 +7,10 @@ ################################################################################ CONFFILE=/etc/default/keyboard -PN="$(basename $0)" +PN="$(basename "$0")" usage(){ - echo "Usage: $0 " + echo "Usage: ${PN} " echo "supported values: at, ch, de, dvorak, es, fr, it, jp, us" } @@ -26,6 +26,7 @@ fi LANGUAGE="$1" +# shellcheck disable=SC1091 . /etc/grml/language-functions if [ -n "$XKEYBOARD" ] ; then diff --git a/usr_bin/grml-lock b/usr_bin/grml-lock index ac05958..46e0ab5 100755 --- a/usr_bin/grml-lock +++ b/usr_bin/grml-lock @@ -6,7 +6,7 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN="$(basename $0)" +PN="$(basename "$0")" [ -n "$USER" ] || USER=grml @@ -21,6 +21,7 @@ Usage: just execute $PN without any further options." fi if [ -r /etc/grml/script-functions ] ; then + # shellcheck disable=SC1091 . /etc/grml/script-functions check4progs physlock sudo chpasswd dialog || { echo "Sorry, necessary tools missing - can not continue. Exiting.">&2 ; exit 1 ; } fi @@ -32,15 +33,22 @@ PWD_TEXT2="Retype new password:" DIALOG='dialog' PWD_CMD="dialog --stdout --title $PN --passwordbox" -# only if using X and gdialog + zenity are available use graphical frontend -if [ -n "$DISPLAY" ] && [ -x "$(which gdialog)" ] && [ -x "$(which zenity)" ] ; then - DIALOG='gdialog' +GUI=false +# only when using X and zenity is available use graphical frontend +if [ -n "${DISPLAY}" ] && [ -x "$(command -v zenity)" ] ; then + DIALOG='zenity' PWD_CMD="zenity --title $PN --entry --hide-text" + GUI=true fi if ! [ -r /etc/grml_version ] ; then - $DIALOG --title "$PN" --msgbox "Warning: this system does not look like a Grml (based) system -and therefore might not work as intended." 7 70 + if [ "${GUI}" = true ] ; then + $DIALOG --no-wrap --title "$PN" --warning --text "Warning: this system does not look like a Grml (based) system,\n + and therefore might not work as intended." + else + $DIALOG --title "$PN" --msgbox "Warning: this system does not look like a Grml (based) system + and therefore might not work as intended." 7 70 + fi fi lock_desktop() { @@ -61,7 +69,7 @@ is_passwd_set() { } set_passwd() { - if [ "$DIALOG" = "gdialog" ] ; then + if [ "${GUI}" = true ] ; then PASSWD1="$($PWD_CMD --text="$PWD_TEXT1")" PASSWD2="$($PWD_CMD --text="$PWD_TEXT2")" else @@ -70,20 +78,29 @@ set_passwd() { fi if [ -z "$PASSWD1" ] ; then - $DIALOG --title "$PN" --msgbox "Error retrieving password. Exiting." 0 0 + if [ -n "${GUI}" ] ; then + $DIALOG --title "$PN" --error --text "Error retrieving password. Exiting." + else + $DIALOG --title "$PN" --msgbox "Error retrieving password. Exiting." 0 0 + fi exit 1 fi + if [ "$PASSWD1" = "$PASSWD2" ] ; then echo "$USER:$PASSWD2" | sudo chpasswd else - $DIALOG --title "$PN" --msgbox "Error: passwords do not match. Exiting." 0 0 + if [ "${GUI}" = true ] ; then + $DIALOG --no-wrap --title "$PN" --error --text "Error: passwords do not match.\nExiting." + else + $DIALOG --title "$PN" --msgbox "Error: passwords do not match. Exiting." 0 0 + fi exit 1 fi } askpwd() { - if [ "$DIALOG" = "gdialog" ] ; then - zenity --title="$PN" --question --cancel-label='Exit' --ok-label='Set password' --text="User $USER has no password set yet. Without a password you will not be able to log in again. Set password for user $USER?" + if [ "${GUI}" = true ] ; then + $DIALOG --no-wrap --title="$PN" --question --cancel-label='Exit' --ok-label='Set password' --text="User $USER has no password set yet.\nWithout a password you will not be able to log in again.\nSet password for user $USER?" RC=$? else $DIALOG --title "$PN" --no-label Exit --yes-label Continue --yesno "User $USER has no password set yet. Without a password you will not be able to log in again. Set password for user $USER?" 0 0 @@ -100,8 +117,11 @@ askpwd() { if ! isgrmlcd ; then lock_desktop else - is_passwd_set || askpwd - [ "$?" = "0" ] && lock_desktop || exit 1 + if is_passwd_set || askpwd ; then + lock_desktop + else + exit 1 + fi fi ## END OF FILE ################################################################# diff --git a/usr_bin/grml-resolution b/usr_bin/grml-resolution index c30111e..08d075a 100755 --- a/usr_bin/grml-resolution +++ b/usr_bin/grml-resolution @@ -6,13 +6,13 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN=$(basename $0) +PN="$(basename "$0")" RESOLUTION=$(mktemp) ERROR=$(mktemp) bailout(){ - rm -f $RESOLUTION $ERROR - exit $1 + rm -f "$RESOLUTION" "$ERROR" + exit "$1" } trap bailout 1 2 3 15 @@ -23,31 +23,30 @@ COUNTER=0 STRING="" # current mode -CURRENT_NUM=$(xrandr | awk '/\*/ {print $1}' | tr -d '*') -CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $2 $3 $4}') +CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $1"_"$2}') # menu -for i in $(xrandr | awk {'print $2$3$4'} | grep "^[0-9]") ; do +for i in $(xrandr | awk '{print $1"_"$2}' | grep "^[0-9]") ; do STRING="$STRING $COUNTER $i" ((COUNTER++)) done # Menu Tool -dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>$RESOLUTION +# shellcheck disable=SC2086 +dialog --title "$PN" --menu "Change X resolution via xrandr (current resolution: $CURRENT_RESOLUTION):" 0 0 0 $STRING 2>"$RESOLUTION" retval=$? case $retval in (1) echo "Cancel pressed." ; exit 1 ;; (255) echo "ESC pressed." ; exit 1 ;; esac -CHOSE=$(cat $RESOLUTION) +CHOSE=$(cat "$RESOLUTION") -if [ "$CHOSE" = "$CURRENT_NUM" ] ; then - dialog --title "$PN" --msgbox "Chosen resolution corresponds to current resolution. No changes needed." 0 0 -elif [ -n "$CHOSE" ] ; then - xrandr -s $CHOSE 2>$ERROR && \ +if [ -n "$CHOSE" ] ; then +# shellcheck disable=SC2015 + xrandr -s "$CHOSE" 2>"$ERROR" && \ dialog --title "$PN" --msgbox "Running xrandr with resolution was succesful." 0 0 || \ - dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: `cat $ERROR`" 0 0 + dialog --title "$PN" --msgbox "Error when running xrandr with resolution $CHOSE: $(cat "$ERROR")" 0 0 fi } @@ -55,6 +54,6 @@ while true ; do main done -bailout +bailout 0 # EOF # diff --git a/usr_bin/iimage b/usr_bin/iimage index 9b210d0..b2f81f7 100755 --- a/usr_bin/iimage +++ b/usr_bin/iimage @@ -1004,7 +1004,7 @@ function update_description_names() { find_all_images for i in $ALL_IMAGES ; do - if ! egrep "$i=" ./description >/dev/null ; then + if ! grep -E "$i=" ./description >/dev/null ; then echo "$i=`description $i`" >> ./description fi diff --git a/usr_bin/iso-term b/usr_bin/iso-term index 0362eb2..440233b 100755 --- a/usr_bin/iso-term +++ b/usr_bin/iso-term @@ -15,12 +15,10 @@ esac } if isutfenv ; then - for ENV in `env | grep UTF` ; do - eval export "$(echo $ENV | sed 's/UTF-8/iso885915/')" + for ENV in $(env | grep UTF) ; do + eval export "$(echo "$ENV" | sed 's/UTF-8/iso885915/')" done - ZSH_NO_DEFAULT_LOCALE=1 x-terminal-emulator $* -else - ZSH_NO_DEFAULT_LOCALE=1 x-terminal-emulator $* fi +ZSH_NO_DEFAULT_LOCALE=1 x-terminal-emulator "$@" ## END OF FILE ################################################################# diff --git a/usr_bin/notifyd.py b/usr_bin/notifyd.py index 312c9b0..ec50fce 100755 --- a/usr_bin/notifyd.py +++ b/usr_bin/notifyd.py @@ -29,7 +29,7 @@ host = "127.0.0.1" port = 8901 logfile = os.path.expanduser("~/.event.log") osdparams = "-p bottom --color=red --delay=4 --age=4 " \ - "--font=\-\*\-helvetica\-medium\-r\-\*\-\*\-34\-\*\-\*\-\*\-\*\-\*\-\*\-15 " \ + "--font=\-\*\-helvetica\-medium\-r\-\*\-\*\-34\-\*\-\*\-\*\-\*\-\*\-\*\-15 " \ # noqa: W605,E501 "--offset=100 --shadow=0 --lines=5 --align=right --indent=100" actions = ( (".*", [log], True), @@ -40,78 +40,101 @@ actions = ( """ +import getopt +import logging import os -import sys import re -import string import socket -import logging -import getopt +import string import subprocess +import sys -default_hostname = 'localhost' +default_hostname = "localhost" default_port = 1234 -default_osd_params = osdparams = "-p bottom --color=red --delay=4 --age=4 " \ - "--font=\-\*\-helvetica\-medium\-r\-\*\-\*\-34\-\*\-\*\-\*\-\*\-\*\-\*\-15 " \ - "--offset=100 --shadow=0 --lines=5 --align=right --indent=100" +default_osd_params = osdparams = ( + "-p bottom --color=red --delay=4 --age=4 " + "--font=\-\*\-helvetica\-medium\-r\-\*\-\*\-34\-\*\-\*\-\*\-\*\-\*\-\*\-15 " # noqa: W605,E501 + "--offset=100 --shadow=0 --lines=5 --align=right --indent=100" +) default_logfile = None def play(sound_file): def play_wrapper(msg): - with open(os.devnull, 'w') as devnull: - subprocess.Popen(['/usr/bin/aplay', sound_file], stderr=devnull) + with open(os.devnull, "w") as devnull: + subprocess.Popen(["/usr/bin/aplay", sound_file], stderr=devnull) + return play_wrapper + def execute(command): def command_wrapper(msg): - subprocess.call(command % dict(msg = msg)) + subprocess.call(command % dict(msg=msg)) + return command_wrapper + def osd(msg): osdcmd = "/usr/bin/osd_cat" - osdpipe = os.popen("%s %s" % (osdcmd, osdparams), 'w') + osdpipe = os.popen("%s %s" % (osdcmd, osdparams), "w") osdpipe.write(msg) osdpipe.close() + def libnotify(msg): try: import dbus except ImportError: - sys.stderr.write('Please install python-dbus\n') + sys.stderr.write("Please install python-dbus\n") raise SystemExit(1) bus = dbus.SessionBus() - notifyService = bus.get_object("org.freedesktop.Notifications", '/org/freedesktop/Notifications') - interface = dbus.Interface(notifyService, 'org.freedesktop.Notifications') + notifyService = bus.get_object( + "org.freedesktop.Notifications", "/org/freedesktop/Notifications" + ) + interface = dbus.Interface(notifyService, "org.freedesktop.Notifications") - message, title = (':' + msg).split(':')[::-1][0:2] + message, title = (":" + msg).split(":")[::-1][0:2] if not title: title, message = message, title - interface.Notify('notify-server', 0, 'notification-message-im', title, message, [], {'x-canonical-append':'allowed'}, -1) + interface.Notify( + "notify-server", + 0, + "notification-message-im", + title, + message, + [], + {"x-canonical-append": "allowed"}, + -1, + ) + def log(msg): if logger: logger.info(msg) + def syntax(): - print "osd_server.py [options]" - print " options:" - print " -h --help print this message" - print " -H --host host of the osd server (def: " + default_hostname + ")" - print " -P --port port of the osd server (def: " + str(default_port) + ")" - print " -l --log log file ('-' logs to stdout)" - - -env = { 'play' : play, - 'execute' : execute, - 'osd' : osd, - 'libnotify' : libnotify, - 'log' : log, - 'host' : default_hostname, - 'port' : default_port, - 'logfile' : default_logfile, - } + print("osd_server.py [options]") + print(" options:") + print(" -h --help print this message") + print(" -H --host host of the osd server (def: " + default_hostname + ")") + print( + " -P --port port of the osd server (def: " + str(default_port) + ")" + ) + print(" -l --log log file ('-' logs to stdout)") + + +env = { + "play": play, + "execute": execute, + "osd": osd, + "libnotify": libnotify, + "log": log, + "host": default_hostname, + "port": default_port, + "logfile": default_logfile, +} default_actions = ( (".*", [log], True), @@ -122,12 +145,22 @@ default_actions = ( default_bind = (default_hostname, default_port) try: - execfile(os.path.expanduser('~/.notifyd.conf'), {}, env) + exec( + compile( + open(os.path.expanduser("~/.notifyd.conf"), "rb").read(), + os.path.expanduser("~/.notifyd.conf"), + "exec", + ), + {}, + env, + ) except IOError: pass try: - opts, args = getopt.getopt(sys.argv[1:], "hH:P:l:", ["help", "host=", "port=", "log="]) + opts, args = getopt.getopt( + sys.argv[1:], "hH:P:l:", ["help", "host=", "port=", "log="] + ) except getopt.GetoptError: syntax() sys.exit(2) @@ -137,23 +170,23 @@ for opt, arg in opts: syntax() sys.exit(3) elif opt in ("-H", "--host"): - env['host'] = arg + env["host"] = arg elif opt in ("-P", "--port"): - env['port'] = int(arg) + env["port"] = int(arg) elif opt in ("-l", "--log"): - env['logfile'] = arg + env["logfile"] = arg -actions = env.get('actions', default_actions) -logfile_name = env.get('logfile') -logfile_format = env.get('logformat', '%(asctime)s %(message)s') -bind_address = (env['host'], env['port']) -osd_params = env.get('osdparams', default_osd_params) +actions = env.get("actions", default_actions) +logfile_name = env.get("logfile") +logfile_format = env.get("logformat", "%(asctime)s %(message)s") +bind_address = (env["host"], env["port"]) +osd_params = env.get("osdparams", default_osd_params) if logfile_name: - logger = logging.getLogger('notify_server') + logger = logging.getLogger("notify_server") lformatter = logging.Formatter(logfile_format) - if logfile_name not in ('', '-'): + if logfile_name not in ("", "-"): lfh = logging.FileHandler(logfile_name) lfh.setFormatter(lformatter) logger.addHandler(lfh) @@ -165,23 +198,25 @@ if logfile_name: else: logger = None -l = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -l.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) -l.bind(bind_address) -l.listen(5) +listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +listen.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +listen.bind(bind_address) +listen.listen(5) + def filter_char(c): - return c in string.printable + "äöüßÄÖÜ" and c or '_' + return c in string.printable + "äöüßÄÖÜ" and c or "_" + while 1: try: - (con, addr) = l.accept() - except: + (con, addr) = listen.accept() + except OSError: continue data = con.recv(50).strip() con.close() - log = ''.join(filter_char(c) for c in data) + log = "".join(filter_char(c) for c in data) for pattern, handlers, cont in actions: if re.match(pattern, log): diff --git a/usr_bin/random-hostname b/usr_bin/random-hostname index b523523..7386abb 100755 --- a/usr_bin/random-hostname +++ b/usr_bin/random-hostname @@ -5,13 +5,13 @@ # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. ################################################################################ -num=$(wc -l $0) -num=${num%% $0} -num=$(( $num - 16 )) -randline=$(($(date +%Y%M%S) * $$ % $num)) -hostname=$(tail -n $randline "$0" | head -1 | grep -v "'" | grep -v '^#' | grep -v '^$') +hostname_start=$(grep -n "^# EOF" "$0") +hostname_start=${hostname_start%%:#*} +hostname_start=$(( hostname_start + 3 )) +hostname=$(tail -n +$hostname_start "$0" | grep -v "'" | grep -v '^#' | grep -v '^$' | sort -R | tail -1) [ -n "$hostname" ] && echo "$hostname" || echo "grml" -# EOF - line 15; now the hostnames: +# EOF - now the hostnames: +# shellcheck disable=SC2034 hostnames=' 23 42 diff --git a/usr_bin/soundtest b/usr_bin/soundtest index 6146df7..dc57bf3 100755 --- a/usr_bin/soundtest +++ b/usr_bin/soundtest @@ -6,7 +6,7 @@ # License: This file is licensed under the GPL v2. ################################################################################ -if ! [ $(which speaker-test) ] ; then +if ! [ "$(command -v speaker-test)" ] ; then echo "Sorry, speaker-test (from alsa-utils) not available.">&2 exit 1 fi diff --git a/usr_sbin/blacklist b/usr_sbin/blacklist index 8446a41..396dc08 100755 --- a/usr_sbin/blacklist +++ b/usr_sbin/blacklist @@ -6,8 +6,9 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN="$(basename $0)" +PN="$(basename "$0")" [ -n "$MODPROBEFILE" ] || MODPROBEFILE=/etc/modprobe.d/grml.conf +# shellcheck disable=SC1091 [ -r /etc/grml/lsb-functions ] && . /etc/grml/lsb-functions if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then @@ -17,7 +18,7 @@ if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then fi if [ "$(id -ru)" != "0" ] ; then - echo Error: become root before starting $0 >& 2 + echo "Error: become root before starting $0" >& 2 exit 100 fi diff --git a/usr_sbin/dirvish-setup b/usr_sbin/dirvish-setup index bef4524..8a2497c 100755 --- a/usr_sbin/dirvish-setup +++ b/usr_sbin/dirvish-setup @@ -13,7 +13,9 @@ set -e +# shellcheck disable=SC1091 . /etc/grml/script-functions +# shellcheck disable=SC1091 . /etc/grml/lsb-functions check4root @@ -71,7 +73,8 @@ EOF # TODO / integrate? cronsetup() { - test -f ~/.keychain/`uname -n`-sh && . ~/.keychain/`uname -n`-sh +# shellcheck disable=SC1090 + test -f "${HOME}/.keychain/$(uname -n)-sh" && . "${HOME}/.keychain/$(uname -n)-sh" } get_backup_dir() { @@ -80,8 +83,9 @@ get_backup_dir() { if ! [ -d "$BACKUP_DIR" ] ; then dialog --stdout --title "${PN}" --yesno "The directory $BACKUP_DIR does not yet exist. Do you want me to create it for you? " 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then echo "mkdir $BACKUP_DIR" echo "chmod 700 $BACKUP_DIR" else @@ -121,23 +125,25 @@ EOF } sshkey_setup() { - CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@$(hostname))" + CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@"$(hostname)")" dialog --stdout --title "${PN}" --yesno "Do you want me to create ssh setup for client ${CLIENTNAME} using ssh-keygen and ssh-copy-id?" 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then [ -d "$HOME/.ssh" ] || mkdir "$HOME/.ssh" einfo "Creating $HOME/.ssh/id_rsa_dirvish_${CLIENT} using ssh-keygen:" ssh-keygen -t rsa -f "$HOME/.ssh/id_rsa_dirvish_${CLIENT}" ; eend $? einfo "Running ssh-copy-id to copy ssh key to $CLIENTNAME:" - ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" $CLIENTNAME ; eend $? + ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" "$CLIENTNAME" ; eend $? fi } client_setup() { dialog --stdout --title "${PN}" --yesno "Do you want to backup $CLIENT via network? Answering with no will use localhost [$(hostname)] as client." 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then sshkey_setup else CLIENTNAME=$(hostname) # use localhost only @@ -148,7 +154,7 @@ display_info() { einfo "Running $PN was successful. Enjoy using dirvish!" ; eend 0 echo einfo "Please adjust ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf according to your needs. -$MASTERINFO +$MASTERINFO Then run the following command to create an initial backup: dirvish --summary long --vault $CLIENT --init diff --git a/usr_sbin/grml-chroot b/usr_sbin/grml-chroot index 3b27505..b13b57e 100755 --- a/usr_sbin/grml-chroot +++ b/usr_sbin/grml-chroot @@ -6,14 +6,14 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PROG_NAME_=$(basename $0) +PROG_NAME_=$(basename "$0") DEST_="" MOUNTED_="" # all mounted destinations function die { - echo "Error: $@" >&2 + echo "Error: $*" >&2 exit 1 } @@ -43,19 +43,20 @@ function mountit local dest_="$2" local options_="$3" - local all_options_="" + local all_options_=() if [[ $options_ == "--bind" ]]; then - all_options_="--bind $type_" + all_options_+=(--bind "$type_") else - all_options_="-t $type_ none" + all_options_+=(-t "$type_" none) fi - mount $all_options_ "${DEST_}/$dest_" && storeMounts "$dest_" + mount "${all_options_[@]}" "${DEST_}/$dest_" && storeMounts "$dest_" } function umount_all { - local reverse=$(echo $MOUNTED_ | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }') + local reverse + reverse=$(echo "$MOUNTED_" | awk '{ for (i=NF; i>1; i--) printf("%s ",$i); print $1; }') for i in $reverse; do umount "${DEST_}/$i" done @@ -72,14 +73,14 @@ while getopts "h" opt; do ?) printUsage; exit 64 ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) if (( $# < 1 )); then printUsage die "Wrong number of arguments." fi -if ! which awk >/dev/null 2>&1 ; then +if ! command -v awk >/dev/null 2>&1 ; then die "No awk binary found, required for execution." fi @@ -98,6 +99,9 @@ else mountit "sysfs" "sys" mountit "/dev" "dev" "--bind" mountit "devpts" "dev/pts" + if [ -d /sys/firmware/efi/efivars ] ; then + mountit "efivarfs" "sys/firmware/efi/efivars" + fi if [ -d "$DEST_"/run/udev ] && [ -d /run/udev ] ; then mountit "/run/udev" "/run/udev" "--bind" fi @@ -119,7 +123,7 @@ else fi umount_all -if [ ! -z "$WROTE_DEBIAN_CHROOT" ]; then +if [ -n "$WROTE_DEBIAN_CHROOT" ]; then rm "$DEST_"/etc/debian_chroot fi diff --git a/usr_sbin/grml-config-root b/usr_sbin/grml-config-root index e1e1158..db6a2a5 100755 --- a/usr_sbin/grml-config-root +++ b/usr_sbin/grml-config-root @@ -9,8 +9,8 @@ PATH=${PATH:-'/bin/:/sbin/:/usr/bin:/usr/sbin'} # set up some variables -DIALOG=`which dialog` -PN=$(basename $0) +DIALOG=$(command -v dialog) +PN=$(basename "$0") if [ "$(id -ru)" != "0" ] ; then $DIALOG --msgbox "Error: $0 requires root permissions. Exiting." 0 0 diff --git a/usr_sbin/grml-hostname b/usr_sbin/grml-hostname index ade8631..400aeef 100755 --- a/usr_sbin/grml-hostname +++ b/usr_sbin/grml-hostname @@ -6,6 +6,7 @@ # License: This file is licensed under the GPL v2. ################################################################################ +# shellcheck disable=SC1091 . /etc/grml/script-functions check4root || exit 1 @@ -31,7 +32,7 @@ fi if [ -z "$NONINTERACTIVE" ] ; then NEW_HOSTNAME="$(dialog --stdout --title "${PN}" --extra-button --extra-label "Propose hostname" \ --inputbox "Set hostname (/etc/hostname, /etc/hosts and /etc/postfix/main.cf will be adjusted)\ -\n\nTip: press 'Propose hostname' for another proposal" 14 70 $NEW_HOSTNAME)" +\\n\\nTip: press 'Propose hostname' for another proposal" 14 70 "$NEW_HOSTNAME")" retval=$? else retval=0 @@ -55,7 +56,9 @@ case $retval in 0) echo "$NEW_HOSTNAME" > /etc/hostname echo "$NEW_HOSTNAME" > /etc/mailname + # shellcheck disable=SC1117 sed -ir "s/^\(127.0.0.1\s*\).*localhost.*/\1$NEW_HOSTNAME localhost/" /etc/hosts + # shellcheck disable=SC1117 sed -ir "s/^\(::1\s*\).*ip6-localhost.*/\1ip6-localhost ip6-loopback $NEW_HOSTNAME/" /etc/hosts POSTFIX='' @@ -66,7 +69,7 @@ Configuration of myhostname in /etc/postfix/main.cf has been adjusted as well. D fi if [ -n "$DISPLAY" ] ; then - if sudo -u $RUNASUSER xauth add $(xauth -n list | grep "${OLDHOSTNAME}/unix:0" | sed "s|${OLDHOSTNAME}/unix:0|${NEW_HOSTNAME}/unix:0|") ; then + if sudo -u $RUNASUSER xauth add "$(xauth -n list | grep "${OLDHOSTNAME}/unix:0" | sed "s|${OLDHOSTNAME}/unix:0|${NEW_HOSTNAME}/unix:0|")" ; then sudo -u $RUNASUSER xauth remove "${OLDHOSTNAME}/unix:0" fi fi diff --git a/usr_sbin/grml-iptstate b/usr_sbin/grml-iptstate index b9e9a2f..6dad6c2 100755 --- a/usr_sbin/grml-iptstate +++ b/usr_sbin/grml-iptstate @@ -6,7 +6,9 @@ # License: This file is licensed under the GPL v2. ################################################################################ +# shellcheck disable=SC1091 . /etc/grml/script-functions +# shellcheck disable=SC1091 . /etc/grml/lsb-functions check4progs iptstate || exit 1 @@ -18,8 +20,9 @@ else ewarn "Module ip_conntrack is not present. Can not start iptstate therefore." eindent einfon "Do you want to load it and invoke iptstate afterwards? [YES|no] " - read a - if [ "$a" = YES -o "$a" = yes -o "$a" = '' -o "$a" = y -o "$a" = Y ] ; then + read -r a + a=$(echo "$a" | tr '[:upper:]' '[:lower:]') + if [ "$a" = "yes" ] || [ "$a" = "y" ] || [ "$a" = "" ] ; then modprobe ip_conntrack ; RC=$? eend $RC [ "$RC" = 0 ] && exec iptstate diff --git a/usr_sbin/grml-setkeyboard b/usr_sbin/grml-setkeyboard index 0ee4eab..ad2366c 100755 --- a/usr_sbin/grml-setkeyboard +++ b/usr_sbin/grml-setkeyboard @@ -6,10 +6,11 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN="$(basename $0)" +PN="$(basename "$0")" DIALOG=dialog CMDLINE=/proc/cmdline +# shellcheck disable=SC1091 . /etc/grml/script-functions check4root || exit 1 @@ -17,10 +18,10 @@ check4root || exit 1 setvalue(){ [ -n "$2" ] || return 1 # already present in conffile? - if grep -q ${1} $CONFFILE ; then - sed -i "s#^${1}.*#${1}=${2}#" $CONFFILE + if grep -q "${1}" "$CONFFILE" ; then + sed -i "s#^${1}.*#${1}=${2}#" "$CONFFILE" else - echo "$1=${2}" >> $CONFFILE + echo "$1=${2}" >> "$CONFFILE" fi } @@ -39,6 +40,7 @@ getbootparam(){ return 0 } +# shellcheck disable=SC1091 [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard [ -n "$KEYTABLE" ] && DEFAULT_KEYBOARD="$KEYTABLE" @@ -49,6 +51,8 @@ if [ -z "$DEFAULT_KEYBOARD" ] ; then fi fi +# shellcheck disable=SC1010 +{ LANGUAGE=$(LANG=C $DIALOG --stdout --title "$PN" --default-item $DEFAULT_KEYBOARD --radiolist \ "Which keyboard layout do you want to use? @@ -85,6 +89,7 @@ Configuration will be written to /etc/sysconfig/keyboard" 0 0 0 \ tw "chinese (traditional)" off \ uk british off \ ) +} retval=$? case $retval in @@ -96,7 +101,8 @@ case $retval in esac # read in the file where all the $LANGUAGE stuff is defined - . /etc/grml/language-functions +# shellcheck disable=SC1091 +. /etc/grml/language-functions cat > /etc/sysconfig/keyboard <> $CONFFILE @@ -61,8 +64,11 @@ You have to make sure the appropriate packages are installed." 0 0 fi fi +# shellcheck disable=SC1091 +{ [ -r /etc/environment ] && . /etc/environment [ -r /etc/default/locale ] && . /etc/default/locale +} [ -n "$LANGUAGE" ] && DEFAULT_LANGUAGE="$LANGUAGE" if [ -z "$DEFAULT_LANGUAGE" ] ; then @@ -70,6 +76,8 @@ if [ -z "$DEFAULT_LANGUAGE" ] ; then fi if [ -z "$NONINTERACTIVE" ] ; then +# shellcheck disable=SC1010 +{ LANGUAGE=$(LANG=C $DIALOG --stdout --title "$PN" --default-item $DEFAULT_LANGUAGE --radiolist \ "Which language do you want to use? @@ -148,6 +156,7 @@ Configuration will be written to $CONFFILE" 0 0 0 \ us 'american (unicode version)' off \ us-iso 'american (iso version)' off \ ) +} retval=$? case $retval in @@ -168,12 +177,13 @@ fi # fallback to C if using an ISO system (which is latin1 for LC_CTYPE); # this should prevent users from broken ctype settings if the set # locale isn't available on a remote system -if echo $LANGUAGE | grep -q -- '-iso' ; then +if echo "$LANGUAGE" | grep -q -- '-iso' ; then LC_CTYPE=C fi # read in the file where all the $LANGUAGE stuff is defined - . $LANGFUNC +# shellcheck disable=SC1090 +. $LANGFUNC # make sure the file exists if ! [ -r $CONFFILE ] ; then @@ -194,7 +204,7 @@ LANG=$LANG EOF fi -setvalue 'LANG=' $LANG +setvalue 'LANG=' "$LANG" retval=$? case $retval in diff --git a/usr_sbin/grml-setservices b/usr_sbin/grml-setservices index 1d8e146..0ef7af4 100755 --- a/usr_sbin/grml-setservices +++ b/usr_sbin/grml-setservices @@ -6,13 +6,16 @@ # License: This file is licensed under the GPL v2. ################################################################################ -PN="$(basename $0)" +PN="$(basename "$0")" TMP=$(mktemp) DIALOG=dialog CONFFILE='/etc/runlevel.conf' +# shellcheck disable=SC1091 +{ . /etc/grml/script-functions . /etc/grml/lsb-functions +} check4root || exit 100 @@ -26,7 +29,7 @@ trap bailout HUP INT QUIT TERM is_value_set(){ [ -n "$1" ] || return 2 [ -r "$TMP" ] || return 3 - grep -q "$1" $TMP && return 0 || return 1 + grep -q "$1" "$TMP" && return 0 || return 1 } INFO="Which services would you like to have enabled on your system? @@ -43,7 +46,7 @@ or choose cancel. [ -r /etc/init.d/lvm2 ] && LVM='lvm!logical volume management!on' [ -r /etc/init.d/mdadm ] && SRAID='mdadm!software-raid via mdadm!on' [ -r /etc/init.d/dmraid ] && MRAID='dmraid!software-raid via dmraid!off' -[ -r /etc/init.d/dbus -o -r /etc/init.d/dbus-1 ] && DBUS='dbus!hal/dbus (important for KDE e.g.)!off' +[ -r /etc/init.d/dbus ] || [ -r /etc/init.d/dbus-1 ] && DBUS='dbus!hal/dbus (important for KDE e.g.)!off' [ -r /etc/init.d/hal ] && HAL='hal!Hardware Abstraction Layer daemon (important for KDE e.g.)!off' [ -r /etc/init.d/nfs-common ] && NFS='nfs!Network File System (client setup)!off' @@ -123,7 +126,7 @@ set_values(){ # the interface itself oifs="$IFS" IFS='!' -$DIALOG --title "$PN" --checklist "$INFO" 30 65 8 $LVM $SRAID $MRAID $DBUS $HAL $NFS 2>$TMP +$DIALOG --title "$PN" --checklist "$INFO" 30 65 8 "$LVM" "$SRAID" "$MRAID" "$DBUS" "$HAL" "$NFS" 2>"$TMP" retval="$?" case $retval in @@ -144,7 +147,7 @@ case $retval in ;; esac -rm -f $TMP +rm -f "$TMP" IFS="$oifs" ## END OF FILE ################################################################# diff --git a/usr_sbin/grml2ram b/usr_sbin/grml2ram index 3482bdb..0806383 100755 --- a/usr_sbin/grml2ram +++ b/usr_sbin/grml2ram @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Filename: grml2ram # Purpose: copy compressed GRML image to RAM # Authors: (c) Michael Schierl , (c) Michael Prokop @@ -8,7 +8,9 @@ set -e +# shellcheck disable=SC1091 . /etc/grml/lsb-functions +# shellcheck disable=SC1091 . /etc/grml/script-functions check4root || exit 1 @@ -50,7 +52,7 @@ getbootparam(){ MEDIA_PATH="$(getbootparam live-media-path)" MEDIA_PATH="${MEDIA_PATH:-.}" -IMAGE=$(find ${LIVECD_PATH}/${MEDIA_PATH}/ -name *.squashfs 2>/dev/null | head -1) +IMAGE=$(find "${LIVECD_PATH}/${MEDIA_PATH}/" -name "*.squashfs" 2>/dev/null | head -1) if ! [ -r "$IMAGE" ] ; then if [ -r /cdrom/GRML/GRML ] ; then IMAGE='/cdrom/GRML/GRML' @@ -63,12 +65,13 @@ fi GRMLSIZE="$(du $IMAGE | awk '{print $1}')" RAM=$(/usr/bin/gawk '/MemFree/{print $2}' /proc/meminfo) +LOOPDEV=$(/sbin/losetup -j "${IMAGE}" -n -O NAME) case "$*" in -f|--force) ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0 ;; *) - if test $RAM -lt $GRMLSIZE ; then + if test "$RAM" -lt "$GRMLSIZE" ; then eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1 exit 1 fi @@ -78,7 +81,7 @@ esac einfo "Copying $IMAGE to RAM, this might take a while." rsync -a --progress $IMAGE /tmp/GRML LANGUAGE=C LANG=C LC_ALL=C perl << EOF -open LOOP, '/dev/null 2>&1 # now run screen with config - if [ `id -u` = 0 ] ; then - exec screen -U -c /etc/grml/screenrc + if [ "$(id -u)" = 0 ] ; then + exec screen -U -c /etc/grml/screenrc -s "-$SHELL" elif [ -r "$HOME/.screenrc" ] ; then - exec screen -U -c "$HOME/.screenrc" + exec screen -U -c "$HOME/.screenrc" -s "-$SHELL" else - exec screen -U -c /etc/grml/screenrc_generic + exec screen -U -c /etc/grml/screenrc_generic -s "-$SHELL" fi ## END OF FILE ################################################################# diff --git a/usr_share/run-welcome b/usr_share/run-welcome index de46a1f..d8d694a 100755 --- a/usr_share/run-welcome +++ b/usr_share/run-welcome @@ -6,8 +6,11 @@ # License: This file is licensed under the GPL v2. ################################################################################ +# shellcheck disable=SC1091 . /etc/grml/sh-lib +export SHELL=/bin/zsh + [ -r /etc/grml_version ] && GRMLVERSION=$(cat /etc/grml_version) || GRMLVERSION='(no version information available)' PATH=$HOME/bin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/games:/home/grml/bin CMDLINE=$(cat /proc/cmdline) @@ -26,7 +29,7 @@ case "$CMDLINE" in # allow customized startup via bootoption startup: *startup=*) script="$(getBootParam startup)" - if [ -x $(which $script) ] ; then + if [ -x "$(command -v "$script")" ] ; then $script fi ;; @@ -36,7 +39,7 @@ case "$CMDLINE" in ;; *) # by default run grml-quickconfig, but only if running as root if [ "$(id -u)" = "0" ] ; then - which grml-quickconfig &>/dev/null && grml-quickconfig + command -v grml-quickconfig &>/dev/null && grml-quickconfig fi esac @@ -81,6 +84,6 @@ Happy hacking! http://grml.org/ " fi -exec /bin/zsh -l +exec "$SHELL" -l ## END OF FILE #################################################################