From d6f2a4985e653b03da6ccc7623ba1b095dd74351 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Tue, 30 Sep 2025 19:52:14 +0200 Subject: [PATCH] Apply version (natural) sort to listings When listing jails, releases, or alike sort them version-aware (natural) where 10 comes not after 1, but after 9. --- usr/local/share/bastille/destroy.sh | 2 +- usr/local/share/bastille/list.sh | 10 +++++----- usr/local/share/bastille/stop.sh | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index ef8ed63b..004bc8ab 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -156,7 +156,7 @@ destroy_rel() { BASE_HASCHILD="0" if [ -d "${bastille_jailsdir}" ]; then - JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g") + JAIL_LIST=$(ls -v --color=never "${bastille_jailsdir}" | sed "s/\n//g") for _jail in ${JAIL_LIST}; do diff --git a/usr/local/share/bastille/list.sh b/usr/local/share/bastille/list.sh index bd710e54..94238700 100644 --- a/usr/local/share/bastille/list.sh +++ b/usr/local/share/bastille/list.sh @@ -71,7 +71,7 @@ get_jail_list() { if [ -n "${TARGET}" ]; then JAIL_LIST="${TARGET}" else - JAIL_LIST="$(ls --color=never "${bastille_jailsdir}" | sed "s/\n//g")" + JAIL_LIST="$(ls -v --color=never "${bastille_jailsdir}" | sed "s/\n//g")" fi } @@ -584,7 +584,7 @@ list_release(){ if [ -d "${bastille_releasesdir}" ]; then # TODO: Check if this can be changed to `find` as SC2012 suggests. # shellcheck disable=SC2012 - REL_LIST="$(ls "${bastille_releasesdir}" | sed "s/\n//g")" + REL_LIST="$(ls -v --color=never "${bastille_releasesdir}" | sed "s/\n//g")" for _REL in ${REL_LIST}; do if [ -f "${bastille_releasesdir}/${_REL}/root/.profile" ] || [ -d "${bastille_releasesdir}/${_REL}/debootstrap" ]; then if [ "${1}" = "-p" ] && [ -f "${bastille_releasesdir}/${_REL}/bin/freebsd-version" ]; then @@ -603,7 +603,7 @@ list_snapshot(){ # TODO: Ability to list snapshot data for a single target. # List snapshots with its usage data for valid bastille jails only. if [ -d "${bastille_jailsdir}" ]; then - JAIL_LIST=$(ls --color=never "${bastille_jailsdir}" | sed "s/\n//g") + JAIL_LIST=$(ls -v --color=never "${bastille_jailsdir}" | sed "s/\n//g") for _JAIL in ${JAIL_LIST}; do if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then info "\n[${_JAIL}]:" @@ -619,7 +619,7 @@ list_template(){ list_jail(){ if [ -d "${bastille_jailsdir}" ]; then - JAIL_LIST=$(ls --color=never "${bastille_jailsdir}" | sed "s/\n//g") + JAIL_LIST=$(ls -v --color=never "${bastille_jailsdir}" | sed "s/\n//g") for _JAIL in ${JAIL_LIST}; do if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then echo "${_JAIL}" @@ -638,7 +638,7 @@ list_limit(){ list_import(){ # shellcheck disable=SC2010 - ls "${bastille_backupsdir}" | grep -v ".sha256$" + ls -v "${bastille_backupsdir}" | grep -v ".sha256$" } bastille_root_check diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index 59ecbe36..f62017dd 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -88,7 +88,7 @@ set_target "${TARGET}" "reverse" for _jail in ${JAILS}; do # Validate that all jails that 'depend' on this one are stopped - for _depend_jail in $(ls --color=never ${bastille_jailsdir} | sed -e 's/\n//g'); do + for _depend_jail in $(ls -v --color=never ${bastille_jailsdir} | sed -e 's/\n//g'); do if ! grep -hoqsw "depend=" ${bastille_jailsdir}/${_depend_jail}/settings.conf; then sysrc -q -f ${bastille_jailsdir}/${_depend_jail}/settings.conf depend="" >/dev/null fi