--- /dev/null
+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: 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
--- /dev/null
+.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
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,
#!/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
"""
-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"""
for line in open(filename):
if line == "--\n":
continue
- m = re.match(r"(?P<filename>.*?)(?P<sep>[-:])(?P<lineno>\d+)(?P=sep)(?P<line>.*\n)$", line)
+ m = re.match(
+ r"(?P<filename>.*?)(?P<sep>[-:])(?P<lineno>\d+)(?P=sep)(?P<line>.*\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()
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)
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)
-
-
# License: This file is licensed under the GPL v2 or any later version.
################################################################################
+PN=$(basename "$0")
+
usage() {
- printf "Usage: $0 <program> [<arguments>]
+ printf "Usage: %s <program> [<arguments>]
Available options:
-h | --help display this usage information
-p <program> 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() {
fi
}
-if [ -z "$1" -o "$1" = '-h' -o "$1" = '--help' ] ; then
+if [ -z "$1" ] || [ "$1" = '-h' ] || [ "$1" = '--help' ] ; then
usage
exit 1
fi
You can search for ${PROG} executing:
-apt-get update && apt-cache search $(basename ${PROG})
+apt-get update && apt-cache search $(basename "${PROG}")
"
exit 1
################################################################################
CONFFILE=/etc/default/keyboard
-PN="$(basename $0)"
+PN="$(basename "$0")"
usage(){
- echo "Usage: $0 <language>"
+ echo "Usage: ${PN} <language>"
echo "supported values: at, ch, de, dvorak, es, fr, it, jp, us"
}
LANGUAGE="$1"
+# shellcheck disable=SC1091
. /etc/grml/language-functions
if [ -n "$XKEYBOARD" ] ; then
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
# 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
CURRENT_RESOLUTION=$(xrandr | awk '/\*/ {print $2 $3 $4}')
# menu
-for i in $(xrandr | awk {'print $2$3$4'} | grep "^[0-9]") ; do
+for i in $(xrandr | awk '{print $2$3$4}' | 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 && \
+# 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
}
main
done
-bailout
+bailout 0
# EOF #
}
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 #################################################################
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),
"""
+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),
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)
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)
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):
# 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
# 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
# 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
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
set -e
+# shellcheck disable=SC1091
. /etc/grml/script-functions
+# shellcheck disable=SC1091
. /etc/grml/lsb-functions
check4root
# 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() {
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
}
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
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
# 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
}
else
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
?) 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
fi
umount_all
-if [ ! -z "$WROTE_DEBIAN_CHROOT" ]; then
+if [ -n "$WROTE_DEBIAN_CHROOT" ]; then
rm "$DEST_"/etc/debian_chroot
fi
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
# License: This file is licensed under the GPL v2.
################################################################################
+# shellcheck disable=SC1091
. /etc/grml/script-functions
check4root || exit 1
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
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=''
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
# 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
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
# 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
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
}
return 0
}
+# shellcheck disable=SC1091
[ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
[ -n "$KEYTABLE" ] && DEFAULT_KEYBOARD="$KEYTABLE"
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?
tw "chinese (traditional)" off \
uk british off \
)
+}
retval=$?
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 <<EOF
# File generated by $PN on $(date)
# License: This file is licensed under the GPL v2.
################################################################################
-PN="$(basename $0)"
+PN="$(basename "$0")"
DIALOG=dialog
-CMDLINE=/proc/cmdline
LANGFUNC=/etc/grml/language-functions
# notice: Debian's locales.postinst has been modified to write
# so modifying it was a policy violation.
CONFFILE=/etc/default/locale
+# shellcheck disable=SC1091
+{
. /etc/grml/script-functions
. /etc/grml/lsb-functions
+}
check4root || exit 100
sed -i "s#^${1}.*#${1}${2}#" $CONFFILE
# is the new Debian style /etc/default/locale present?
elif grep -q "^# ${1}$" "$CONFFILE" ; then
+ # shellcheck disable=SC1117
sed -i "s#^\# ${1}#${1}${2}#" $CONFFILE
else
echo "$1${2}" >> $CONFFILE
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
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?
us 'american (unicode version)' off \
us-iso 'american (iso version)' off \
)
+}
retval=$?
case $retval in
# 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
EOF
fi
-setvalue 'LANG=' $LANG
+setvalue 'LANG=' "$LANG"
retval=$?
case $retval in
# 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
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?
[ -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'
# 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
;;
esac
-rm -f $TMP
+rm -f "$TMP"
IFS="$oifs"
## END OF FILE #################################################################
-#!/bin/sh
+#!/bin/bash
# Filename: grml2ram
# Purpose: copy compressed GRML image to RAM
# Authors: (c) Michael Schierl <schierlm-public@gmx.de>, (c) Michael Prokop <mika@grml.org>
set -e
+# shellcheck disable=SC1091
. /etc/grml/lsb-functions
+# shellcheck disable=SC1091
. /etc/grml/script-functions
check4root || exit 1
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'
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
[ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
einfo "Unmounting cdrom"
-[ -d $LIVECD_PATH ] && umount $LIVECD_PATH || umount /cdrom
+if [ -d $LIVECD_PATH ] ;
+then
+ umount $LIVECD_PATH
+else
+ umount /cdrom
+fi
eend $?
einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0
################################################################################
touch /etc/noeject
-exec $*
+exec "$@"
## END OF FILE #################################################################
################################################################################
touch /etc/noprompt
-exec $*
+exec "$@"
## END OF FILE #################################################################
# now run screen with config
- if [ `id -u` = 0 ] ; then
+ if [ "$(id -u)" = 0 ] ; then
exec screen -U -c /etc/grml/screenrc
elif [ -r "$HOME/.screenrc" ] ; then
exec screen -U -c "$HOME/.screenrc"
# License: This file is licensed under the GPL v2.
################################################################################
+# shellcheck disable=SC1091
. /etc/grml/sh-lib
[ -r /etc/grml_version ] && GRMLVERSION=$(cat /etc/grml_version) || GRMLVERSION='(no version information available)'
# allow customized startup via bootoption startup:
*startup=*)
script="$(getBootParam startup)"
- if [ -x $(which $script) ] ; then
+ if [ -x "$(command -v "$script")" ] ; then
$script
fi
;;
;;
*) # 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