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

begin moving functions to common.sh (top htop) #776

Merged
merged 48 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
e4fb6e3
begin moving functions to common.sh
tschettervictor Dec 16, 2024
e448707
rename to be consistent
tschettervictor Dec 16, 2024
5bc7cd8
begin function define in top
tschettervictor Dec 16, 2024
e0dfc33
move jail running check to for loop
tschettervictor Dec 16, 2024
0e3f7a5
rename function to target
tschettervictor Dec 16, 2024
6331467
htop function add
tschettervictor Dec 16, 2024
3c92733
Update top.sh
tschettervictor Dec 16, 2024
dc55881
source config from common.sh
tschettervictor Dec 16, 2024
538ec81
move top and htop to no action command
tschettervictor Dec 16, 2024
fe029c0
exit if no args
tschettervictor Dec 16, 2024
d2943bd
exit if no args
tschettervictor Dec 16, 2024
6d2e9c2
also source config file
tschettervictor Dec 16, 2024
1fce192
spacing
tschettervictor Dec 16, 2024
3aeb17c
Merge branch 'BastilleBSD:master' into check_jail_exists-function
tschettervictor Dec 17, 2024
31cc087
Add set_target function
tschettervictor Dec 17, 2024
0ddd4d9
Fox vars
tschettervictor Dec 17, 2024
0874e02
Update common.sh
tschettervictor Dec 17, 2024
42a6a29
only accept one target for top
tschettervictor Dec 17, 2024
9e8cd7b
accept only one arg on htop
tschettervictor Dec 17, 2024
b225320
accept only one arg with htop
tschettervictor Dec 17, 2024
bff6b93
Update top.sh
tschettervictor Dec 17, 2024
1bcd44c
add set_target_single function to only allow single jail targetting
tschettervictor Dec 17, 2024
ac30b36
only set target with set_target_single
tschettervictor Dec 17, 2024
1b23c04
Update top.sh
tschettervictor Dec 17, 2024
f86ad1f
Update htop.sh
tschettervictor Dec 17, 2024
0d9a793
Update top.sh
tschettervictor Dec 17, 2024
4248ea9
Update common.sh
tschettervictor Dec 17, 2024
4276e63
Update htop.sh
tschettervictor Dec 17, 2024
9da73d6
set TARGET to local only for some functions
tschettervictor Dec 17, 2024
52c8d8e
Merge branch 'BastilleBSD:master' into check_jail_exists-function
tschettervictor Dec 17, 2024
cbcd388
organize functions in alphabetical order
tschettervictor Dec 19, 2024
76e6113
error handling
tschettervictor Dec 19, 2024
5b68630
remove 0
tschettervictor Dec 19, 2024
200321c
error handling
tschettervictor Dec 19, 2024
d458ed8
Update common.sh
tschettervictor Dec 21, 2024
4a93f61
Update htop.sh
tschettervictor Dec 21, 2024
5913fcc
Update top.sh
tschettervictor Dec 21, 2024
0413a94
spacing
tschettervictor Dec 22, 2024
d293db2
move help into options block
tschettervictor Dec 24, 2024
54bf9d6
move help into options block
tschettervictor Dec 24, 2024
db0f5c5
minor tweak
tschettervictor Dec 27, 2024
82a8d54
minor tweak
tschettervictor Dec 27, 2024
9b354c1
minor tweak
tschettervictor Dec 27, 2024
2bd0680
Merge branch 'master' into check_jail_exists-function
tschettervictor Dec 27, 2024
3c04a88
Merge branch 'BastilleBSD:master' into check_jail_exists-function
tschettervictor Dec 27, 2024
7a621b2
Merge branch 'master' into check_jail_exists-function
tschettervictor Dec 31, 2024
4bc76d5
fix brace
tschettervictor Dec 31, 2024
fedc7aa
Remove message on return 1
tschettervictor Dec 31, 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
6 changes: 3 additions & 3 deletions usr/local/bin/bastille
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ version|-v|--version)
help|-h|--help)
usage
;;
bootstrap|create|destroy|export|import|list|mount|rdr|restart|setup|start|umount|update|upgrade|verify)
bootstrap|create|destroy|export|htop|import|list|mount|rdr|restart|setup|start|top|umount|update|upgrade|verify)
# Nothing "extra" to do for these commands. -- cwells
;;
clone|config|cmd|console|convert|cp|edit|htop|limits|pkg|rcp|rename|service|stop|sysrc|tags|template|top|zfs)
clone|config|cmd|console|convert|cp|edit|limits|pkg|rcp|rename|service|stop|sysrc|tags|template|zfs)
# Parse the target and ensure it exists. -- cwells
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help'
Expand Down Expand Up @@ -205,7 +205,7 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|pkg|rcp|rename|service|stop
fi

case "${CMD}" in
cmd|console|htop|pkg|service|stop|sysrc|template|top)
cmd|console|pkg|service|stop|sysrc|template)
check_target_is_running
;;
convert|rename)
Expand Down
48 changes: 47 additions & 1 deletion usr/local/share/bastille/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Source config file
. /usr/local/etc/bastille/bastille.conf

COLOR_RED=
COLOR_GREEN=
COLOR_YELLOW=
Expand All @@ -51,7 +54,7 @@ if [ -z "${NO_COLOR}" ] && [ -t 1 ]; then
enable_color
fi

# Notify message on error, but do not exit
# Error/Info functions
error_notify() {
echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2
}
Expand Down Expand Up @@ -86,6 +89,24 @@ check_target_exists() {
fi
}

check_target_is_running() {
local _TARGET="${1}"
if [ ! "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
return 1
else
return 0
fi
}

check_target_is_stopped() {
local _TARGET="${1}"
if [ "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
return 1
else
return 0
fi
}

generate_static_mac() {
local jail_name="${1}"
local external_interface="${2}"
Expand Down Expand Up @@ -160,6 +181,30 @@ set_target() {
fi
}

set_target_single() {
local _TARGET="${1}"
if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then
error_exit "[all|ALL] not supported with this command."
else
check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\""
JAILS="${_TARGET}"
TARGET="${_TARGET}"
export JAILS
export TARGET
fi
}

target_all_jails() {
local _JAILS="$(bastille list jails)"
JAILS=""
for _jail in ${_JAILS}; do
if [ -d "${bastille_jailsdir}/${_jail}" ]; then
JAILS="${JAILS} ${_jail}"
fi
done
export JAILS
}

checkyesno() {
## copied from /etc/rc.subr -- cedwards (20231125)
## issue #368 (lowercase values should be parsed)
Expand All @@ -180,3 +225,4 @@ checkyesno() {
;;
esac
}

63 changes: 45 additions & 18 deletions usr/local/share/bastille/htop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,56 @@
. /usr/local/etc/bastille/bastille.conf

usage() {
error_exit "Usage: bastille htop TARGET"
error_exit "Usage: bastille htop [option(s)] TARGET"
cat << EOF
Options:

-f | --force -- Start the jail if it is stopped.

EOF
exit 1
}

# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
# Handle options.
FORCE=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-f|--force)
FORCE=1
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
;;
*)
break
;;
esac
done

if [ $# -ne 0 ]; then
if [ "$#" -ne 1 ]; then
usage
fi

TARGET="${1}"

bastille_root_check
set_target_single "${TARGET}"

for _jail in ${JAILS}; do
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${_jail}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
info "[${_jail}]:"
jexec -l ${_jail} /usr/local/bin/htop
fi
echo -e "${COLOR_RESET}"
done
info "[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
bastille start "${TARGET}"
else
error_notify "Jail is not running."
error_continue "Use [-f|--force] to force start the jail."
fi

bastille_jail_path="${bastille_jailsdir}/${TARGET}/root"
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
error_notify "htop not found on ${TARGET}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
jexec -l ${TARGET} /usr/local/bin/htop
fi
53 changes: 40 additions & 13 deletions usr/local/share/bastille/top.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,53 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

. /usr/local/share/bastille/common.sh
. /usr/local/etc/bastille/bastille.conf

usage() {
error_exit "Usage: bastille top TARGET"
error_notify "Usage: bastille top [options(s)] TARGET"
cat << EOF
Options:

-f | --force -- Start the jail if it is stopped.

EOF
exit 1
}

# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
# Handle options.
FORCE=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-f|--force)
FORCE=1
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
;;
*)
break
;;
esac
done

if [ $# -ne 0 ]; then
if [ "$#" -ne 1 ]; then
usage
fi

TARGET="${1}"

bastille_root_check
set_target_single "${TARGET}"

for _jail in ${JAILS}; do
info "[${_jail}]:"
jexec -l "${_jail}" /usr/bin/top
echo -e "${COLOR_RESET}"
done
info "[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
bastille start "${TARGET}"
else
error_notify "Jail is not running."
error_continue "Use [-f|--force] to force start the jail."
fi
jexec -l "${TARGET}" /usr/bin/top