Skip to content

Commit

Permalink
scripts: fix shellcheck issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zeha committed Nov 26, 2024
1 parent bb225fe commit fe3eef9
Show file tree
Hide file tree
Showing 41 changed files with 311 additions and 171 deletions.
3 changes: 3 additions & 0 deletions etc/grml/fai/config/scripts/DEBORPHAN/10-whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# workaround for dnsutils transitional package, we can drop this as soon as the
# bind9-dnsutils package is available in all our supported Debian releases
if [[ -r "${target}/usr/share/doc/dnsutils" ]] && [ -x "${target}/usr/bin/deborphan" ] ; then
Expand Down
5 changes: 5 additions & 0 deletions etc/grml/fai/config/scripts/DEBORPHAN/98-clean-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# remove all packages not necessary anymore:
echo "Executing apt-get -y --purge autoremove"
$ROOTCMD apt-get -y --purge autoremove
Expand All @@ -20,6 +23,7 @@ PURGE_PACKAGES=$($ROOTCMD dpkg --list | awk '/^rc/ {print $2}')

if [ -n "$PURGE_PACKAGES" ] ; then
echo "Getting rid of packages which have been removed but not yet purged: $PURGE_PACKAGES"
# shellcheck disable=SC2086 # PURGE_PACKAGES needs word-splitting.
$ROOTCMD dpkg --purge $PURGE_PACKAGES
fi

Expand All @@ -29,6 +33,7 @@ if [ -x "$target"/usr/bin/deborphan ] ; then
# remove packages until deborphan does not find anymore:
while [ "$($ROOTCMD deborphan)" != "" ] ; do
echo "Executing deborphan"
# shellcheck disable=SC2046 # deborphan result needs word-splitting.
$ROOTCMD apt-get -y --purge remove $($ROOTCMD deborphan)
done
fi
Expand Down
3 changes: 3 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/01-packages
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

echo -n > "${LOGDIR}"/package_errors.log # ensure we start with an empty file

if ! [ -e "${LOGDIR}"/software.log ] ; then
Expand Down
3 changes: 3 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/02-run
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# This is what initscripts would do if everything would be fine.
if [ -L "$target/run" ] ; then
rm -f "$target/run"
Expand Down
4 changes: 4 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/03-get-sources
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# License: This file is licensed under the GPL v2 or any later version.
################################################################################

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

if ifclass SOURCES ; then
echo "Class SOURCES set, retrieving source packages."
else
Expand All @@ -27,6 +30,7 @@ mkdir -p "${target}${SOURCES_PATH}"
$ROOTCMD apt-get update

# Collect *source* package names
# shellcheck disable=SC2016 # Embedded $ is correct.
$ROOTCMD dpkg-query -W -f='${Source} ${Package}\n' | sed -e 's/^ //' | awk '{ print $1 }' | sort -u | \
chroot "${target}" /bin/bash -c "cd \"${SOURCES_PATH}\" && xargs --max-args=32 --max-procs=12 apt-get --download-only source" 2> "${ERRORS_LOG}"

Expand Down
14 changes: 9 additions & 5 deletions etc/grml/fai/config/scripts/GRMLBASE/05-hostname
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

# the hostname of the chroot usually isn't the same as the one for the live-system
BUILD_HOSTNAME="$($ROOTCMD hostname)"
[ -n "$BUILD_HOSTNAME" ] || BUILD_HOSTNAME="grml"

echo "$HOSTNAME" > $target/etc/hostname
echo "$HOSTNAME" > $target/etc/mailname
echo "$HOSTNAME" > "$target"/etc/hostname
echo "$HOSTNAME" > "$target"/etc/mailname

if [ -r $target/etc/postfix/main.cf ] ; then
sed -i "s/^mydestination = .*/mydestination = $HOSTNAME, localhost, localhost.localdomain/" $target/etc/postfix/main.cf
sed -i "s/^myhostname = .*/myhostname = $HOSTNAME/" $target/etc/postfix/main.cf
if [ -r "$target"/etc/postfix/main.cf ] ; then
sed -i "s/^mydestination = .*/mydestination = $HOSTNAME, localhost, localhost.localdomain/" "$target"/etc/postfix/main.cf
sed -i "s/^myhostname = .*/myhostname = $HOSTNAME/" "$target"/etc/postfix/main.cf
echo "postfix postfix/mailname string $HOSTNAME" | $ROOTCMD debconf-set-selections
echo "postfix postfix/destinations string ${HOSTNAME}, localhost.grml.org, localhost" \
| $ROOTCMD debconf-set-selections
Expand Down
5 changes: 5 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/15-initsetup
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

systemd_setup() {
Expand Down
9 changes: 6 additions & 3 deletions etc/grml/fai/config/scripts/GRMLBASE/16-depmod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
set -u
set -e

if ! [ -x $target/sbin/depmod ] ; then
# FAI sets $target, but shellcheck does not know that.
target=${target:?}

if ! [ -x "$target"/sbin/depmod ] ; then
echo "Warning: depmod not installed"
exit 0
fi

for kernel in ${target}/boot/vmlinuz-* ; do
kernelversion=${kernel##$target}
for kernel in "$target"/boot/vmlinuz-* ; do
kernelversion=${kernel##"$target"}
kernelversion=${kernelversion##/boot/vmlinuz-}

echo "Updating modules.dep for kernel ${kernelversion}"
Expand Down
13 changes: 8 additions & 5 deletions etc/grml/fai/config/scripts/GRMLBASE/18-timesetup
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# tell if hwclock is running in UTC or local time
# by default it's set to UTC=no
if [ -n "$UTC" ] && [ "$UTC" = "yes" ] ; then
Expand All @@ -20,14 +23,14 @@ fi
if [ -n "$TIMEZONE" ] ; then
echo "Setting default timezone to $TIMEZONE"
# update debconf
area=$(echo $TIMEZONE | cut -d '/' -f1)
zone=$(echo $TIMEZONE | cut -d '/' -f2)
area=$(echo "$TIMEZONE" | cut -d '/' -f1)
zone=$(echo "$TIMEZONE" | cut -d '/' -f2)
echo "tzdata tzdata/Areas select $area" | $ROOTCMD debconf-set-selections
echo "tzdata tzdata/Zones/$area select $zone" | $ROOTCMD debconf-set-selections
# update files
echo $TIMEZONE > $target/etc/timezone
rm -f $target/etc/localtime
cp -f $target/usr/share/zoneinfo/$TIMEZONE $target/etc/localtime
echo "$TIMEZONE" > "$target"/etc/timezone
rm -f "$target"/etc/localtime
cp -f "$target"/usr/share/zoneinfo/"$TIMEZONE" "$target"/etc/localtime
fi

## END OF FILE ################################################################
Expand Down
11 changes: 8 additions & 3 deletions etc/grml/fai/config/scripts/GRMLBASE/20-sudo
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

fcopy -v /etc/sudoers
sed -i "s/\$USERNAME/$USERNAME/" $target/etc/sudoers
chmod 440 $target/etc/sudoers
chown 0:0 $target/etc/sudoers
sed -i "s/\$USERNAME/$USERNAME/" "$target"/etc/sudoers
chmod 440 "$target"/etc/sudoers
chown 0:0 "$target"/etc/sudoers

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
23 changes: 14 additions & 9 deletions etc/grml/fai/config/scripts/GRMLBASE/21-usersetup
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

if grep -q "$USERNAME:x:1000" $target/etc/group ; then
if grep -q "$USERNAME:x:1000" "$target"/etc/group ; then
echo "group $USERNAME exists already, skipping"
else
$ROOTCMD addgroup --gid 1000 $USERNAME
$ROOTCMD addgroup --gid 1000 "$USERNAME"
fi

if grep -q "$USERNAME:x:1000" $target/etc/passwd ; then
if grep -q "$USERNAME:x:1000" "$target"/etc/passwd ; then
echo "user $USERNAME exists already, skipping"
else
$ROOTCMD useradd -d /home/$USERNAME -m -s /bin/zsh -g 1000 $USERNAME
$ROOTCMD useradd -d /home/"$USERNAME" -m -s /bin/zsh -g 1000 "$USERNAME"
fi

# make sure to add the user to all relevant groups:
add_user_to_group() {
[ -n "$1" ] || return 1
if grep -q $1 $target/etc/group ; then
grep "$1:x:.*$USERNAME" $target/etc/group || $ROOTCMD adduser $USERNAME $1
if grep -q "$1" "$target"/etc/group ; then
grep "$1:x:.*$USERNAME" "$target"/etc/group || $ROOTCMD adduser "$USERNAME" "$1"
fi
}

Expand Down Expand Up @@ -55,12 +60,12 @@ add_user_to_group video
add_user_to_group vlock
add_user_to_group voice

sed -i 's/^root::/root:*:/' $target/etc/shadow
sed -i "s/^$USERNAME:!:/$USERNAME:*:/" $target/etc/shadow
sed -i 's/^root::/root:*:/' "$target"/etc/shadow
sed -i "s/^$USERNAME:!:/$USERNAME:*:/" "$target"/etc/shadow

if $ROOTCMD [ -r /bin/zsh ] ; then
$ROOTCMD chsh -s /bin/zsh root
$ROOTCMD chsh -s /bin/zsh $USERNAME
$ROOTCMD chsh -s /bin/zsh "$USERNAME"
fi

## END OF FILE #################################################################
Expand Down
9 changes: 6 additions & 3 deletions etc/grml/fai/config/scripts/GRMLBASE/25-locales
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# set up /etc/locale.gen, only GRML_FULL and LOCALES have
# the full setup, GRMLBASE installs a minimal configuration
fcopy -v /etc/locale.gen
Expand All @@ -23,7 +26,7 @@ set -u
echo 'Removing /usr/share/locale'

# get rid of the original
rm -rf $target/usr/share/locale
rm -rf "$target"/usr/share/locale

# restore *empty* directories because otherwise installation/upgrade of packages might fail
[ -d "$target"/usr/share/locale ] || mkdir "$target"/usr/share/locale
Expand All @@ -45,7 +48,7 @@ if $ROOTCMD dpkg --list localepurge 2>&1 | grep -q '^ii' ; then
$ROOTCMD dpkg-reconfigure -f noninteractive localepurge
fi

if ! [ -x $target/usr/sbin/localepurge ] ; then
if ! [ -x "$target"/usr/sbin/localepurge ] ; then
echo "Warning: localepurge not installed"
else
echo "Running localepurge."
Expand All @@ -55,7 +58,7 @@ fi
if $ROOTCMD dpkg-query -s locales-all >/dev/null 2>&1 ; then
echo "locales-all installed, skipping locales generation"
else
if ! [ -x ${target}/usr/sbin/locale-gen ] ; then
if ! [ -x "$target"/usr/sbin/locale-gen ] ; then
echo 'Warning: locale-gen [package locales] not installed'
else
echo "Running locale-gen"
Expand Down
7 changes: 6 additions & 1 deletion etc/grml/fai/config/scripts/GRMLBASE/30-fstab
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

fcopy -v /etc/fstab
sed -i "s/uid=USERNAME,gid=USERNAME/uid=$USERNAME,gid=$USERNAME/" $target/etc/fstab
sed -i "s/uid=USERNAME,gid=USERNAME/uid=$USERNAME,gid=$USERNAME/" "$target"/etc/fstab

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
9 changes: 6 additions & 3 deletions etc/grml/fai/config/scripts/GRMLBASE/32-xorg
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
set -u
set -e

if [ -r "$target/etc/X11/xorg.conf" ] ; then
# FAI sets $target, but shellcheck does not know that.
target=${target:?}

if [ -r "$target"/etc/X11/xorg.conf ] ; then
mv -f "$target"/etc/X11/xorg.conf "$target"/etc/X11/xorg.conf.debian
fi

if [ "$(readlink $target/etc/X11/X)" = "/bin/true" ] ; then
if [ "$(readlink "$target"/etc/X11/X)" = "/bin/true" ] ; then
echo "Warning: /etc/X11/X is a symlink to /bin/true - fixing for you">&2
ln -sf /usr/bin/Xorg $target/etc/X11/X
ln -sf /usr/bin/Xorg "$target"/etc/X11/X
fi

## END OF FILE #################################################################
Expand Down
6 changes: 5 additions & 1 deletion etc/grml/fai/config/scripts/GRMLBASE/33-aptsetup
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# use snapshot.debian.org based on build date for release
if ifclass RELEASE ; then
set -u
perl -pi -e 'BEGIN { $d="'$(date +%Y%m%d)'"; } s#^(\s+)(deb.* )(.*://ftp.debian.org.*?)\s+([a-z-]+)\s+(.*)$#$1$2http://snapshot.debian.org/archive/debian/$d/ $4 $5#' \
current_date=$(date +%Y%m%d)
perl -pi -e 'BEGIN { $d="'"$current_date"'"; } s#^(\s+)(deb.* )(.*://ftp.debian.org.*?)\s+([a-z-]+)\s+(.*)$#$1$2http://snapshot.debian.org/archive/debian/$d/ $4 $5#' \
"${target}/etc/apt/sources.list.d/debian.list"
fi

Expand Down
7 changes: 6 additions & 1 deletion etc/grml/fai/config/scripts/GRMLBASE/34-hosts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# shellcheck source=/dev/null
. "$GRML_LIVE_CONFIG"

fcopy -v /etc/hosts

# replace $HOSTNAME with the real hostname:
sed -i "s/\$HOSTNAME/$HOSTNAME/" $target/etc/hosts
sed -i "s/\$HOSTNAME/$HOSTNAME/" "$target"/etc/hosts

## END OF FILE #################################################################
# vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2
3 changes: 3 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/38-udev
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

CONFFILE="$target/etc/udev/rules.d/70-persistent-net.rules"
STRING='This file was automatically generated by the /lib/udev/write_net_rules'

Expand Down
3 changes: 3 additions & 0 deletions etc/grml/fai/config/scripts/GRMLBASE/39-modprobe
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -u
set -e

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

# Install all present modprobe.d configuration files
fcopy -v -i -r /etc/modprobe.d

Expand Down
7 changes: 5 additions & 2 deletions etc/grml/fai/config/scripts/GRMLBASE/45-grub-images
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
set -e
set -u

# FAI sets $target, but shellcheck does not know that.
target=${target:?}

TMP_CONFIG="/tmp/grub_config_efi"

# this allows us to find this specific Grml ISO,
Expand Down Expand Up @@ -70,10 +73,10 @@ for arch in "${ARCHS[@]}" ; do
arm64-efi) filename=/boot/bootaa64.efi ;;
esac

$ROOTCMD grub-mkimage -O $arch -o "$filename" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
$ROOTCMD grub-mkimage -O "$arch" -o "$filename" --prefix=/boot/grub/ --config="$TMP_CONFIG" \
echo iso9660 part_msdos search_fs_file test \
fat ext2 reiserfs xfs btrfs squash4 part_gpt lvm \
${ADDITIONAL_MODULES[$arch]}
"${ADDITIONAL_MODULES[$arch]}"
done

rm -f "${target}/${TMP_CONFIG}"
Expand Down
Loading

0 comments on commit fe3eef9

Please sign in to comment.