Skip to content

Commit

Permalink
Merge pull request #292 from grml/shellcheck
Browse files Browse the repository at this point in the history
Appease shellcheck
  • Loading branch information
zeha authored Oct 29, 2024
2 parents c6ec3e8 + 5bdbcfd commit 6f87c36
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 25 deletions.
50 changes: 25 additions & 25 deletions grml-debootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ cleanup() {
fi
done

[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1 || true
[ -x "$MNTPOINT"/bin/umount ] && { chroot "$MNTPOINT" umount -a >/dev/null 2>&1 || true; }

# ugly, but make sure we really don't leave anything (/proc /proc and
# /dev /dev are intended, trying to work around timing issues, see #657023)
for ARG in /run/udev /sys /proc /proc /dev/pts /dev/pts /dev /dev ; do
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true
[ -x "$MNTPOINT"/bin/umount ] && { chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true; }
umount "$MNTPOINT"/$ARG >/dev/null 2>&1 || true
done

Expand Down Expand Up @@ -614,7 +614,7 @@ done
[ "$_opt_arch" ] && ARCH=$_opt_arch
[ "$_opt_insecure" ] && echo "Warning: --insecure is deprecated, continuing anyway."
[ "$_opt_force" ] && FORCE=$_opt_force
[ "$_opt_verbose" ] && VERBOSE="-v"
[ "$_opt_verbose" ] && VERBOSE="true"
[ "$_opt_debug" ] && DEBUG="true"
[ "$_opt_remove_configs" ] && REMOVE_CONFIGS="yes"

Expand Down Expand Up @@ -820,8 +820,8 @@ prompt_for_bootmanager()
# ask for Debian release {{{
prompt_for_release()
{
[ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='bullseye'
RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
local default_value="$RELEASE"
RELEASE="$(dialog --stdout --title "${PN}" --default-item "$default_value" --menu \
"Please enter the Debian release you would like to use for installation:" \
0 50 8 \
buster Debian/10 \
Expand Down Expand Up @@ -873,7 +873,7 @@ prompt_for_mirror()
{
[ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'

CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item "$DEFAULT_MIRROR" \
--menu "Where do you want to install from?" 0 0 0 \
net "install via network (downloading from mirror)" \
local "install from local directory/mirror"
Expand All @@ -883,13 +883,13 @@ prompt_for_mirror()
[ -n "$MIRROR" ] || MIRROR='http://deb.debian.org/debian'
MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
"Please enter Debian mirror you would like to use for installing packages." \
0 0 $MIRROR)" || bailout
0 0 "$MIRROR")" || bailout

else # CHOOSE_MIRROR == local
[ -n "$ISO" ] || ISO='/mnt/mirror'
ISO="$(dialog --stdout --title "${PN}" --inputbox \
"Please enter directory name you would like to use for installing packages." \
0 0 $ISO)" || bailout
0 0 "$ISO")" || bailout
fi
}
# }}}
Expand Down Expand Up @@ -1828,12 +1828,12 @@ preparechroot() {
[ -n "$TUNE2FS" ] && echo "TUNE2FS='${TUNE2FS//\'/\'\\\'\'}'" >> "$CHROOT_VARIABLES"
[ -n "$VMSIZE" ] && echo "VMSIZE='${VMSIZE//\'/\'\\\'\'}'" >> "$CHROOT_VARIABLES"

cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script
cp ${VERBOSE:+-v} "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script
chmod 755 "${MNTPOINT}"/bin/chroot-script
[ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/

# make sure we have our files for later use via chroot-script
cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/
cp ${VERBOSE:+-v} "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/
# make sure we adjust the configuration variables accordingly:
sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" "${MNTPOINT}"/etc/debootstrap/config
sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" "${MNTPOINT}"/etc/debootstrap/config
Expand All @@ -1852,41 +1852,41 @@ preparechroot() {
PACKAGES_FILE="packages-arm64"
fi

cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \
cp ${VERBOSE:+-v} "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \
"${MNTPOINT}/etc/debootstrap/${PACKAGES_FILE}"
fi

# debconf preseeding:
_opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
[ -f "${_opt_debconf}" ] && [ "$DEBCONF" = 'yes' ] && \
cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections
cp ${VERBOSE:+-v} "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections

# copy scripts that should be executed inside the chroot:
_opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
[ -d "$_opt_chroot_scripts" ] && [ "$CHROOT_SCRIPTS" = 'yes' ] && {
mkdir -p "${MNTPOINT}"/etc/debootstrap/chroot-scripts
cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/
cp -a ${VERBOSE:+-v} "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/
}

# notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
cp $VERBOSE "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables
cp ${VERBOSE:+-v} "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables

cp $VERBOSE -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/
cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/

# make sure we can access network [relevant for cdebootstrap/mmdebstrap]
[ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf
[ -f "${MNTPOINT}"/etc/resolv.conf ] || cp ${VERBOSE:+-v} /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf

# setup default locales
[ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen
[ -n "$LOCALES" ] && cp ${VERBOSE:+-v} "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen

# copy any existing files to chroot
[ -d "${CONFFILES}"/bin ] && cp $VERBOSE -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/
[ -d "${CONFFILES}"/boot ] && cp $VERBOSE -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/
[ -d "${CONFFILES}"/etc ] && cp $VERBOSE -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/
[ -d "${CONFFILES}"/sbin ] && cp $VERBOSE -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/
[ -d "${CONFFILES}"/share ] && cp $VERBOSE -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/
[ -d "${CONFFILES}"/usr ] && cp $VERBOSE -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/
[ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/
[ -d "${CONFFILES}"/bin ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/
[ -d "${CONFFILES}"/boot ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/
[ -d "${CONFFILES}"/etc ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/
[ -d "${CONFFILES}"/sbin ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/
[ -d "${CONFFILES}"/share ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/
[ -d "${CONFFILES}"/usr ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/
[ -d "${CONFFILES}"/var ] && cp ${VERBOSE:+-v} -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/

# network setup
DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap
Expand Down Expand Up @@ -1941,7 +1941,7 @@ iface ${interface} inet dhcp
elif [ -r /etc/network/interfaces ] ; then
einfo "Copying /etc/network/interfaces from host to target system"
mkdir -p "${MNTPOINT}/etc/network"
cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
cp ${VERBOSE:+-v} /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces"
else
ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces"
mkdir -p "${MNTPOINT}/etc/network"
Expand Down
90 changes: 90 additions & 0 deletions tests/shellcheck-stub-debootstrap-variables
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,93 @@
# ARCH is defaulted in grml-debootstrap, so it is never empty.
ARCH=amd64

# defaulted
CHROOT_SCRIPTS=yes

# defaulted (conditional, but always set)
COMPONENTS=main

# defaulted
CONFFILES=/etc/debootstrap

# defaulted
DEBCONF=yes

# defaulted
DEBIAN_FRONTEND=noninteractive

# defaulted
DEFAULT_LANGUAGE=en_US:en

# defaulted
DEFAULT_LOCALES=en_US.UTF-8

# defaulted
EXTRAPACKAGES=yes

# defaulted
FALLBACK_MIRROR=http://deb.debian.org/debian

# defaulted
FORCE=

# defaulted
HOSTNAME=grml

# defaulted
INITRD=yes

# defaulted
INITRD_GENERATOR=initramfs-tools

# defaulted
INITRD_GENERATOR_OPTS=

# defaulted
INSTALL_NOTES=/etc/debootstrap/install_notes

# defaulted
LOCALES=yes

# defaulted
MIRROR=$FALLBACK_MIRROR

# defaulted
MKFS=mkfs.ext4

# defaulted
PACKAGES=yes

# defaulted
POST_SCRIPTS=yes

# defaulted
PRE_SCRIPTS=yes

# defaulted
RECONFIGURE=console-data

# defaulted
RELEASE=bookworm

# defaulted
RM_APTCACHE=yes

# defaulted
SCRIPTS=no

# defaulted
SECURE=yes

# defaulted
TIMEZONE=Europe/Vienna

# defaulted
TUNE2FS=tune2fs -c0 -i0

# defaulted
UPGRADE_SYSTEM=yes

# defaulted
VMSIZE=2G

0 comments on commit 6f87c36

Please sign in to comment.