Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shellcheck: general linting and github action #763

Merged
merged 21 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
933438d
updates version on README.md
jdhg-orbiware Dec 9, 2024
50fd86a
github: fix typo
jdhg-orbiware Dec 9, 2024
5dbb196
github: fix typo in shellcheck action
jdhg-orbiware Dec 9, 2024
2be5238
github: shellcheck severity to warning
jdhg-orbiware Dec 9, 2024
302dfb9
github: shellcheck exclude some rules
jdhg-orbiware Dec 9, 2024
7c02c91
github: shellcheck exclude SC3037
jdhg-orbiware Dec 9, 2024
7e6a9fa
[WIP] shellcheck linting
jdhg-orbiware Dec 9, 2024
8808e8a
[WIP] shellcheck linting
jdhg-orbiware Dec 9, 2024
b6bf75a
[WIP] shellcheck linting
jdhg-orbiware Dec 9, 2024
7927385
[WIP] shellcheck linting
jdhg-orbiware Dec 9, 2024
7c000a0
[WIP] shellcheck linting
jdhg-orbiware Dec 9, 2024
d708a34
shellcheck: template, fix quotes
jdhg-orbiware Dec 9, 2024
097ad8e
shellcheck: template, revert single quotes
jdhg-orbiware Dec 10, 2024
7bad37c
shellcheck: export, mount. Logic syntax
jdhg-orbiware Dec 10, 2024
763184a
shellcheck: disable=SC2046 on verify.sh
jdhg-orbiware Dec 15, 2024
fd175fd
shellcheck: disable=SC2046 on verify.sh pt2
jdhg-orbiware Dec 15, 2024
63964b1
shellcheck: disable=SC3003 on verify.sh
jdhg-orbiware Dec 15, 2024
a906f14
shellcheck: fix double quote on `update TEMPLATES`
jdhg-orbiware Dec 15, 2024
124e968
shellcheck: fix zfs intentional '@' and disable SC2140
jdhg-orbiware Dec 15, 2024
78d2ae9
shellcheck: fix create intentional '@' and disable SC2140
jdhg-orbiware Dec 15, 2024
8893084
shellcheck: mount. Style: indication of line continuation
jdhg-orbiware Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ShellCheck Linting
on:
pull_request:
branches:
- main
- master

jobs:
lint:
Expand All @@ -15,8 +15,18 @@ jobs:
uses: actions/checkout@v4

- name: Run ShellCheck
uses: ludeeus/action-shellcheckudeeus/[email protected]
uses: ludeeus/[email protected]
env:
# Excluding SC3043: In POSIX sh, 'local' is undefined. Ignoring because local is a built-in command in FreeBSD
# Excluding SC2154: Variable is referenced but not assigned. Because we include files in the scripts
# Excluding SC3037: In POSIX sh, echo flags are undefined. Ignoring temporarily until we decide to keep it or
# use printf instead
# Excluding SC2155: Declare and assign separately to avoid masking return values.
# Excluding SC2124: Assigning an array to a string! Check instead if this is a false positive or if there is
# a better way to do it.
SHELLCHECK_OPTS: -e SC3043 -e SC2154 -e SC3037 -e SC2155 -e SC2124
with:
severity: warning
scandir: "./usr/local/share/bastille"
additional_files: "./usr/local/bin/bastille"
ignore_paths: "./usr/local/share/bastille/templates"
ignore_paths: "./usr/local/share/bastille/templates ./usr/local/share/bastille/colors.pre.sh"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Use "bastille command -h|--help" for more information about a command.

```

## 0.10-beta
## 0.12-beta
This document outlines the basic usage of the Bastille container management
framework. This release is still considered beta.

Expand Down
4 changes: 3 additions & 1 deletion usr/local/share/bastille/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ bootstrap_release() {
if [ -f "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" ]; then
## check distfiles list and skip existing cached files
bastille_bootstrap_archives=$(echo "${bastille_bootstrap_archives}" | sed "s/base//")
# TODO check how to handle this
# shellcheck disable=SC2010
bastille_cached_files=$(ls "${bastille_cachedir}/${RELEASE}" | grep -v "MANIFEST" | tr -d ".txz")
for distfile in ${bastille_cached_files}; do
bastille_bootstrap_archives=$(echo "${bastille_bootstrap_archives}" | sed "s/${distfile}//")
Expand Down Expand Up @@ -452,7 +454,7 @@ HW_MACHINE_ARCH=$(sysctl hw.machine_arch | awk '{ print $2 }')

# bootstrapping from aarch64/arm64 Debian or Ubuntu require a different value for ARCH
# create a new variable
if [ "${HW_MACHINE_ARCH}" == "aarch64" ]; then
if [ "${HW_MACHINE_ARCH}" = "aarch64" ]; then
HW_MACHINE_ARCH_LINUX="arm64"
else
HW_MACHINE_ARCH_LINUX=${HW_MACHINE_ARCH}
Expand Down
7 changes: 4 additions & 3 deletions usr/local/share/bastille/clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ validate_ip() {
if [ -n "${ip6}" ]; then
info "Valid: (${ip6})."
IPX_ADDR="ip6.addr"
# shellcheck disable=SC2034
IP6_MODE="new"
else
local IFS
Expand Down Expand Up @@ -104,8 +105,8 @@ update_jailconf_vnet() {
bastille_jail_rc_conf="${bastille_jailsdir}/${NEWNAME}/root/etc/rc.conf"

# Determine number of containers and define an uniq_epair
local list_jails_num=$(bastille list jails | wc -l | awk '{print $1}')
local num_range=$(expr "${list_jails_num}" + 1)
local list_jails_num="$(bastille list jails | wc -l | awk '{print $1}')"
local num_range="$(expr "${list_jails_num}" + 1)"
jail_list=$(bastille list jail)
for _num in $(seq 0 "${num_range}"); do
if [ -n "${jail_list}" ]; then
Expand All @@ -125,7 +126,7 @@ update_jailconf_vnet() {
sed -i '' "s|ifconfig_e0b_bastille.*_name|ifconfig_e0b_${uniq_epair}_name|" "${bastille_jail_rc_conf}"

# If 0.0.0.0 set DHCP, else set static IP address
if [ "${IP}" == "0.0.0.0" ]; then
if [ "${IP}" = "0.0.0.0" ]; then
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="SYNCDHCP"
else
sysrc -f "${bastille_jail_rc_conf}" ifconfig_vnet0="inet ${IP}"
Expand Down
6 changes: 3 additions & 3 deletions usr/local/share/bastille/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enable_color() {

# If "NO_COLOR" environment variable is present, or we aren't speaking to a
# tty, disable output colors.
if [ -z "${NO_COLOR}" -a -t 1 ]; then
if [ -z "${NO_COLOR}" ] && [ -t 1 ]; then
enable_color
fi

Expand Down Expand Up @@ -77,9 +77,9 @@ generate_vnet_jail_netblock() {
## determine number of containers + 1
## iterate num and grep all jail configs
## define uniq_epair
local jail_list=$(bastille list jails)
local jail_list="$(bastille list jails)"
if [ -n "${jail_list}" ]; then
local list_jails_num=$(echo "${jail_list}" | wc -l | awk '{print $1}')
local list_jails_num="$(echo "${jail_list}" | wc -l | awk '{print $1}')"
local num_range=$((list_jails_num + 1))
for _num in $(seq 0 "${num_range}"); do
if ! grep -q "e[0-9]b_bastille${_num}" "${bastille_jailsdir}"/*/jail.conf; then
Expand Down
4 changes: 3 additions & 1 deletion usr/local/share/bastille/convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ start_convert() {
HASPORTS=$(grep -w ${bastille_releasesdir}/${RELEASE}/usr/ports ${bastille_jailsdir}/${TARGET}/fstab)

if [ -n "${RELEASE}" ]; then
cd "${bastille_jailsdir}/${TARGET}/root"
cd "${bastille_jailsdir}/${TARGET}/root" || error_exit "Failed to change directory to ${bastille_jailsdir}/${TARGET}/root"

# Work with the symlinks
convert_symlinks
Expand Down Expand Up @@ -149,6 +149,8 @@ fi
# Be interactive here since this cannot be easily undone
while :; do
error_notify "Warning: container conversion from thin to thick can't be undone!"
# shellcheck disable=SC2162
# shellcheck disable=SC3045
read -p "Do you really wish to convert '${TARGET}' into a thick container? [y/N]:" yn
case ${yn} in
[Yy]) start_convert;;
Expand Down
18 changes: 14 additions & 4 deletions usr/local/share/bastille/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ running_jail() {

validate_name() {
local NAME_VERIFY=${NAME}
local NAME_SANITY=$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')
local NAME_SANITY="$(echo "${NAME_VERIFY}" | tr -c -d 'a-zA-Z0-9-_')"
if [ -n "$(echo "${NAME_SANITY}" | awk "/^[-_].*$/" )" ]; then
error_exit "Container names may not begin with (-|_) characters!"
elif [ "${NAME_VERIFY}" != "${NAME_SANITY}" ]; then
Expand Down Expand Up @@ -123,7 +123,7 @@ validate_ips() {
}

validate_netif() {
local LIST_INTERFACES=$(ifconfig -l)
local LIST_INTERFACES="$(ifconfig -l)"
if echo "${LIST_INTERFACES} VNET" | grep -qwo "${INTERFACE}"; then
info "Valid: (${INTERFACE})."
else
Expand Down Expand Up @@ -253,7 +253,7 @@ post_create_jail() {

# Using relative paths here.
# MAKE SURE WE'RE IN THE RIGHT PLACE.
cd "${bastille_jail_path}"
cd "${bastille_jail_path}" || error_exit "Failed to change directory."
echo

if [ ! -f "${bastille_jail_conf}" ]; then
Expand Down Expand Up @@ -292,7 +292,9 @@ create_jail() {
bastille_jail_fstab="${bastille_jailsdir}/${NAME}/fstab" ## file
bastille_jail_conf="${bastille_jailsdir}/${NAME}/jail.conf" ## file
bastille_jail_log="${bastille_logsdir}/${NAME}_console.log" ## file
# shellcheck disable=SC2034
bastille_jail_rc_conf="${bastille_jailsdir}/${NAME}/root/etc/rc.conf" ## file
# shellcheck disable=SC2034
bastille_jail_resolv_conf="${bastille_jailsdir}/${NAME}/root/etc/resolv.conf" ## file

if [ ! -d "${bastille_jailsdir}/${NAME}" ]; then
Expand Down Expand Up @@ -409,8 +411,10 @@ create_jail() {
info "Creating a clonejail...\n"
## clone the release base to the new basejail
SNAP_NAME="bastille-clone-$(date +%Y-%m-%d-%H%M%S)"
# shellcheck disable=SC2140
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"

# shellcheck disable=SC2140
zfs clone -p "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" \
"${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"

Expand All @@ -425,16 +429,20 @@ create_jail() {

## take a temp snapshot of the base release
SNAP_NAME="bastille-$(date +%Y-%m-%d-%H%M%S)"
# shellcheck disable=SC2140
zfs snapshot "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"

## replicate the release base to the new thickjail and set the default mountpoint
# shellcheck disable=SC2140
zfs send -R "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}" | \
zfs receive "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs set ${ZFS_OPTIONS} mountpoint=none "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"
zfs inherit mountpoint "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"

## cleanup temp snapshots initially
# shellcheck disable=SC2140
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/releases/${RELEASE}"@"${SNAP_NAME}"
# shellcheck disable=SC2140
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NAME}/root"@"${SNAP_NAME}"
fi

Expand Down Expand Up @@ -608,7 +616,9 @@ esac
bastille_root_check

if echo "$3" | grep '@'; then
# shellcheck disable=SC2034
BASTILLE_JAIL_IP=$(echo "$3" | awk -F@ '{print $2}')
# shellcheck disable=SC2034
BASTILLE_JAIL_INTERFACES=$( echo "$3" | awk -F@ '{print $1}')
fi

Expand Down Expand Up @@ -691,7 +701,7 @@ while [ $# -gt 0 ]; do
VNET_JAIL_BRIDGE="1"
shift
;;
-*|--*)
--*|-*)
error_notify "Unknown Option."
usage
;;
Expand Down
2 changes: 1 addition & 1 deletion usr/local/share/bastille/destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ destroy_rel() {
if [ "${FORCE}" = "1" ]; then
## remove cache on force
if [ -d "${bastille_cachedir}/${TARGET}" ]; then
rm -rf "${bastille_cachedir}/${TARGET}"
rm -rf "${bastille_cachedir:?}/${TARGET}"
fi
fi
echo
Expand Down
1 change: 1 addition & 0 deletions usr/local/share/bastille/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fi
bastille_root_check

if [ -z "${EDITOR}" ]; then
# shellcheck disable=SC2209
EDITOR=vi
fi

Expand Down
18 changes: 12 additions & 6 deletions usr/local/share/bastille/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ bastille_root_check
zfs_enable_check() {
# Temporarily disable ZFS so we can create a standard backup archive
if checkyesno bastille_zfs_enable; then
# shellcheck disable=SC2034
bastille_zfs_enable="NO"
fi
}
Expand Down Expand Up @@ -135,7 +136,7 @@ if [ -n "${bastille_export_options}" ]; then
--verbose)
OPT_ZSEND="-Rv"
shift;;
-*|--*) error_notify "Unknown Option."
--*|-*) error_notify "Unknown Option."
usage;;
esac
done
Expand Down Expand Up @@ -185,7 +186,7 @@ else
TARGET="${2}"
shift
;;
-*|--*)
--*|-*)
error_notify "Unknown Option."
usage
;;
Expand All @@ -208,12 +209,16 @@ if [ "${COMP_OPTION}" -gt "1" ]; then
error_exit "Error: Only one compression format can be used during export."
fi

if [ -n "${TXZ_EXPORT}" -o -n "${TGZ_EXPORT}" ] && [ -n "${SAFE_EXPORT}" ]; then
if { [ -n "${TXZ_EXPORT}" ] || [ -n "${TGZ_EXPORT}" ]; } && [ -n "${SAFE_EXPORT}" ]; then
error_exit "Error: Simple archive modes with safe ZFS export can't be used together."
fi

if ! checkyesno bastille_zfs_enable; then
if [ -n "${XZ_EXPORT}" -o -n "${GZIP_EXPORT}" -o -n "${RAW_EXPORT}" -o -n "${SAFE_EXPORT}" -o "${OPT_ZSEND}" = "-Rv" ]; then
if [ -n "${XZ_EXPORT}" ] ||
[ -n "${GZIP_EXPORT}" ] ||
[ -n "${RAW_EXPORT}" ] ||
[ -n "${SAFE_EXPORT}" ] ||
[ "${OPT_ZSEND}" = "-Rv" ]; then
error_exit "Options --xz, --gz, --raw, --safe, --verbose are valid for ZFS configured systems only."
fi
fi
Expand Down Expand Up @@ -270,7 +275,7 @@ export_check() {
EXPORT_AS="Exporting"
fi

if [ "${FILE_EXT}" = ".xz" -o "${FILE_EXT}" = ".gz" -o "${FILE_EXT}" = "" ]; then
if [ "${FILE_EXT}" = ".xz" ] || [ "${FILE_EXT}" = ".gz" ] || [ "${FILE_EXT}" = "" ]; then
EXPORT_TYPE="image"
else
EXPORT_TYPE="archive"
Expand Down Expand Up @@ -360,12 +365,13 @@ jail_export() {
fi
fi

# shellcheck disable=SC2181
if [ "$?" -ne 0 ]; then
error_exit "Failed to export '${TARGET}' container."
else
if [ -z "${USER_EXPORT}" ]; then
# Generate container checksum file
cd "${bastille_backupsdir}"
cd "${bastille_backupsdir}" || error_exit "Failed to change directory."
sha256 -q "${TARGET}_${DATE}${FILE_EXT}" > "${TARGET}_${DATE}.sha256"
info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}' successfully."
fi
Expand Down
8 changes: 4 additions & 4 deletions usr/local/share/bastille/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ while [ $# -gt 0 ]; do
TARGET="${2}"
shift
;;
-*|--*)
--*|-*)
error_notify "Unknown Option."
usage
;;
Expand Down Expand Up @@ -281,7 +281,7 @@ EOF
>> "${bastille_jailsdir}/${TARGET_TRIM}/fstab"

# Work with the symlinks
cd "${bastille_jailsdir}/${TARGET_TRIM}/root"
cd "${bastille_jailsdir}/${TARGET_TRIM}/root" || error_exit "Failed to change directory."
update_symlinks
else
# Generate new empty fstab file
Expand Down Expand Up @@ -324,7 +324,7 @@ update_config() {
>> "${bastille_jailsdir}/${TARGET_TRIM}/fstab"

# Work with the symlinks
cd "${bastille_jailsdir}/${TARGET_TRIM}/root"
cd "${bastille_jailsdir}/${TARGET_TRIM}/root" || error_exit "Failed to change directory."
update_symlinks
}

Expand Down Expand Up @@ -377,7 +377,7 @@ update_symlinks() {
for _link in ${SYMLINKS}; do
if [ -L "${_link}" ]; then
ln -sf /.bastille/${_link} ${_link}
elif [ "${ALLOW_EMPTY_DIRS_TO_BE_SYMLINKED:-0}" = "1" -a -d "${_link}" ]; then
elif [ "${ALLOW_EMPTY_DIRS_TO_BE_SYMLINKED:-0}" = "1" ] && [ -d "${_link}" ]; then
# -F will enforce that the directory is empty and replaced by the symlink
ln -sfF /.bastille/${_link} ${_link} || EXIT_CODE=$?
if [ "${EXIT_CODE:-0}" != "0" ]; then
Expand Down
Loading