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

[UPDATE] New Rewrite [UPDATE] - please test and report bugs #777

Closed
wants to merge 130 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
000635e
Update bootstrap.sh
tschettervictor Dec 19, 2024
2d4fc36
Update clone.sh
tschettervictor Dec 19, 2024
84eb497
Update clone.sh
tschettervictor Dec 19, 2024
2e67d85
Update clone.sh
tschettervictor Dec 19, 2024
10b84bb
Update clone.sh
tschettervictor Dec 19, 2024
608d046
Update clone.sh
tschettervictor Dec 19, 2024
5cbd3b4
Update cmd.sh
tschettervictor Dec 19, 2024
8dd5128
Update common.sh
tschettervictor Dec 19, 2024
86f6575
Update config.sh
tschettervictor Dec 19, 2024
77cb14a
Update console.sh
tschettervictor Dec 19, 2024
ff00e70
Update convert.sh
tschettervictor Dec 19, 2024
35d138d
Update cp.sh
tschettervictor Dec 19, 2024
0d4b8be
Update create.sh
tschettervictor Dec 19, 2024
70e8ec2
Update destroy.sh
tschettervictor Dec 19, 2024
4b735c0
Update edit.sh
tschettervictor Dec 19, 2024
572f3d0
Create etcupdate.sh
tschettervictor Dec 19, 2024
bf8aaf7
Update export.sh
tschettervictor Dec 19, 2024
5bc2c44
Update htop.sh
tschettervictor Dec 19, 2024
1e2936d
Update import.sh
tschettervictor Dec 19, 2024
736e070
Update limits.sh
tschettervictor Dec 19, 2024
f992c18
Update list.sh
tschettervictor Dec 19, 2024
897bd26
Update mount.sh
tschettervictor Dec 19, 2024
a66f525
Update pkg.sh
tschettervictor Dec 19, 2024
a40e861
Update rcp.sh
tschettervictor Dec 19, 2024
58ca2af
Update rdr.sh
tschettervictor Dec 19, 2024
b0b2d93
Update rename.sh
tschettervictor Dec 19, 2024
ca5febd
Update service.sh
tschettervictor Dec 19, 2024
bd5d603
Update start.sh
tschettervictor Dec 19, 2024
1aa8e80
Update stop.sh
tschettervictor Dec 19, 2024
818beed
Update sysrc.sh
tschettervictor Dec 19, 2024
86561fe
Update tags.sh
tschettervictor Dec 19, 2024
948af9b
Update template.sh
tschettervictor Dec 19, 2024
7a5223d
Update top.sh
tschettervictor Dec 19, 2024
37cf018
Update umount.sh
tschettervictor Dec 19, 2024
9030382
Update upgrade.sh
tschettervictor Dec 19, 2024
8a57cb5
Update update.sh
tschettervictor Dec 19, 2024
2df124a
Update verify.sh
tschettervictor Dec 19, 2024
7349638
Update zfs.sh
tschettervictor Dec 19, 2024
6ead268
final
tschettervictor Dec 21, 2024
e5fd655
Update Bastillefile
tschettervictor Dec 21, 2024
9073f75
final
tschettervictor Dec 21, 2024
8c1e6ae
final
tschettervictor Dec 21, 2024
33c577c
final
tschettervictor Dec 21, 2024
d2ac0d0
final
tschettervictor Dec 21, 2024
f5c7b43
final
tschettervictor Dec 21, 2024
0f708cc
final
tschettervictor Dec 21, 2024
844674f
Update convert.sh
tschettervictor Dec 21, 2024
b89c969
final
tschettervictor Dec 21, 2024
9a91b14
final
tschettervictor Dec 21, 2024
a06fbf6
final
tschettervictor Dec 21, 2024
6e6cc31
final
tschettervictor Dec 21, 2024
deb2f55
final
tschettervictor Dec 21, 2024
d3f82bc
final
tschettervictor Dec 21, 2024
715db61
final
tschettervictor Dec 21, 2024
d563d88
final
tschettervictor Dec 21, 2024
c34a299
final
tschettervictor Dec 21, 2024
6958f37
final
tschettervictor Dec 21, 2024
d18eae5
final
tschettervictor Dec 21, 2024
50f86ea
final
tschettervictor Dec 21, 2024
7d02dd9
final
tschettervictor Dec 21, 2024
acae673
final
tschettervictor Dec 21, 2024
807b11c
final
tschettervictor Dec 21, 2024
42450cb
final
tschettervictor Dec 21, 2024
6ea187a
final
tschettervictor Dec 21, 2024
50b8a2c
final
tschettervictor Dec 21, 2024
fc85e1e
final
tschettervictor Dec 21, 2024
ce1e338
final
tschettervictor Dec 21, 2024
0727798
final
tschettervictor Dec 21, 2024
fb09f0f
final
tschettervictor Dec 21, 2024
1c5930c
final
tschettervictor Dec 21, 2024
ec5fdb4
final
tschettervictor Dec 21, 2024
4640cae
first go at shellcheck correction
tschettervictor Dec 21, 2024
fccf4b5
next attempt at shellcheck
tschettervictor Dec 21, 2024
3b38f8f
next try
tschettervictor Dec 21, 2024
99830d2
next
tschettervictor Dec 21, 2024
c7f744f
next
tschettervictor Dec 21, 2024
8b4871c
copyright year
tschettervictor Dec 21, 2024
5cb6999
rename fixes
tschettervictor Dec 21, 2024
7c0acb1
integrate latest PRs
tschettervictor Dec 22, 2024
53f64f6
Allow file mounting
tschettervictor Dec 22, 2024
4d05174
Update mount.sh
tschettervictor Dec 22, 2024
72cceba
Strip // to /
tschettervictor Dec 22, 2024
f623d25
Strip // to /
tschettervictor Dec 22, 2024
138414d
Update umount.sh
tschettervictor Dec 22, 2024
16c9ac9
fix mounting and unmounting
tschettervictor Dec 23, 2024
7a82e71
Merge branch 'new_rewrite' of https://github.com/tschettervictor/bast…
tschettervictor Dec 23, 2024
fff6a03
Spacing
tschettervictor Dec 23, 2024
b3a042c
Spacing
tschettervictor Dec 23, 2024
d2d176d
More spacing
tschettervictor Dec 23, 2024
4ec894f
imporve mounting and add error_continue function
tschettervictor Dec 23, 2024
c5a3ad5
Merge branch 'new_rewrite' of https://github.com/tschettervictor/bast…
tschettervictor Dec 23, 2024
17f52a1
fix brace
tschettervictor Dec 23, 2024
484be5a
disable shellcheck 2104 as this is a special function
tschettervictor Dec 23, 2024
d5f03c6
spacing
tschettervictor Dec 23, 2024
bcf1634
mount and umount bug fixes
tschettervictor Dec 24, 2024
8732309
spacing fix
tschettervictor Dec 24, 2024
8be23ea
more fixes and improvements
tschettervictor Dec 24, 2024
6f055fe
more improvements and code cleanup
tschettervictor Dec 24, 2024
697c81d
more code cleanup
tschettervictor Dec 24, 2024
891a847
fix case
tschettervictor Dec 24, 2024
a953fb7
close to final arrangement of code
tschettervictor Dec 24, 2024
3fdd00a
fixes
tschettervictor Dec 24, 2024
96466c2
Remove warn about existing rdr rule
tschettervictor Dec 25, 2024
029c656
Optional stop on clone with zfs
tschettervictor Dec 25, 2024
d8b0a8d
Add restart to clone
tschettervictor Dec 25, 2024
b4060fe
more fixes and improvements
tschettervictor Dec 27, 2024
9c676f6
fix mount
tschettervictor Dec 27, 2024
8f57115
Merge branch 'master' into new_rewrite
tschettervictor Dec 27, 2024
f6a6439
update for multi interfaces
tschettervictor Dec 31, 2024
b5dcf5a
add autocomplete
tschettervictor Dec 31, 2024
2beeefe
fix ""
tschettervictor Dec 31, 2024
cf29557
fix ""
tschettervictor Dec 31, 2024
101d1b5
disable sc2010
tschettervictor Dec 31, 2024
54489a8
rewrite: update network and template
tschettervictor Jan 3, 2025
6f6412e
Merge branch 'master' into new_rewrite
tschettervictor Jan 3, 2025
140ac35
fix shellcheck
tschettervictor Jan 3, 2025
0e351f6
Merge branch 'new_rewrite' of https://github.com/tschettervictor/bast…
tschettervictor Jan 3, 2025
366d4e7
add classic jail multiple if
tschettervictor Jan 4, 2025
4db78eb
Merge branch 'BastilleBSD:master' into new_rewrite
tschettervictor Jan 4, 2025
6e3d207
update
tschettervictor Jan 4, 2025
82f94a6
Shellcheck 2034 disable
tschettervictor Jan 5, 2025
82be42f
Merge branch 'master' into new_rewrite
tschettervictor Jan 5, 2025
35ff2ec
new: add debug + code cleanup
tschettervictor Jan 10, 2025
00c51a4
Merge branch 'master' into new_rewrite
tschettervictor Jan 10, 2025
9381e19
new: fix shellcheck
tschettervictor Jan 10, 2025
5bc98c3
Merge branch 'new_rewrite' of https://github.com/tschettervictor/bast…
tschettervictor Jan 10, 2025
ffae769
new: fix more shellchek
tschettervictor Jan 10, 2025
0fc58fa
mount: allow options
tschettervictor Jan 10, 2025
cbae856
Merge branch 'master' into new_rewrite
tschettervictor Jan 13, 2025
83b3201
start/stop: update to allow new style interface
tschettervictor Jan 13, 2025
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
164 changes: 61 additions & 103 deletions usr/local/bin/bastille
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ bastille_perms_check() {
fi
}

## we only load the config if conf_check passes
. /usr/local/etc/bastille/bastille.conf

bastille_conf_check
bastille_perms_check

## version
Expand All @@ -99,13 +103,15 @@ Available Commands:
create Create a new thin container or a thick container if -T|--thick option specified.
destroy Destroy a stopped container or a FreeBSD release.
edit Edit container configuration files (advanced).
etcupdate Update container /etc directory to specified release.
export Exports a specified container.
help Help about any command.
htop Interactive process viewer (requires htop).
import Import a specified container.
limits Apply resources limits to targeted container(s). See rctl(8).
list List containers (running).
mount Mount a volume inside the targeted container(s).
network Add or remove interfaces from targeted container(s).
pkg Manipulate binary packages within targeted container(s). See pkg(8).
rcp reverse cp(1) files from a single container to the host.
rdr Redirect host port to container port.
Expand All @@ -132,119 +138,71 @@ EOF
exit 1
}

[ $# -lt 1 ] && usage

CMD=$1
shift

target_all_jails() {
_JAILS=$(/usr/sbin/jls name)
JAILS=""
for _jail in ${_JAILS}; do
_JAILPATH=$(/usr/sbin/jls -j "${_jail}" path)
if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then
JAILS="${JAILS} ${_jail}"
fi
done
}

check_target_is_running() {
if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
fi
}
if [ "$#" -lt 1 ]; then
usage
else
CMD="${1}"
shift
fi

# Handle special-case commands first.
case "${CMD}" in
version|-v|--version)
info "${BASTILLE_VERSION}"
exit 0
;;
help|-h|--help)
usage
;;
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|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'
elif [ "${1}" != 'help' ] && [ "${1}" != '-h' ] && [ "${1}" != '--help' ]; then
TARGET="${1}"
shift

# This is needed to handle the special case of 'bastille rcp' and 'bastille cp' with the '-q' or '--quiet'
# option specified before the TARGET. Also seems the cp and rcp commands does not support ALL as a target, so
# that's why is handled here. Maybe this behaviour needs an improvement later. -- yaazkal
if { [ "${CMD}" = 'rcp' ] || [ "${CMD}" = 'cp' ]; } && \
{ [ "${TARGET}" = '-q' ] || [ "${TARGET}" = '--quiet' ]; }; then
TARGET="${1}"
JAILS="${TARGET}"
OPTION="-q"
export OPTION
shift
fi

if [ "${TARGET}" = 'ALL' ]; then
target_all_jails
elif [ "${CMD}" = "pkg" ] && [ "${TARGET}" = '-H' ] || [ "${TARGET}" = '--host' ]; then
TARGET="${1}"
USE_HOST_PKG=1
if [ "${TARGET}" = 'ALL' ]; then
target_all_jails
else
JAILS="${TARGET}"
check_target_is_running
fi
shift
elif [ "${CMD}" = 'template' ] && [ "${TARGET}" = '--convert' ]; then
# This command does not act on a jail, so we are temporarily bypassing the presence/started
# checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells
:
else
JAILS="${TARGET}"

# Ensure the target exists. -- cwells
if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then
error_exit "[${TARGET}]: Not found."
fi

case "${CMD}" in
cmd|console|pkg|service|stop|sysrc|template)
check_target_is_running
;;
convert|rename)
# Require the target to be stopped. -- cwells
if [ "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then
error_exit "${TARGET} is running. See 'bastille stop ${TARGET}'."
fi
;;
esac
fi
export USE_HOST_PKG
export TARGET
export JAILS
fi
;;
*) # Filter out all non-commands
usage
;;
version|-v|--version)
info "${BASTILLE_VERSION}"
exit 0
;;
help|-h|--help)
usage
;;
bootstrap| \
clone| \
cmd| \
config| \
console| \
convert| \
cp| \
create| \
destroy| \
edit| \
etcupdate| \
export| \
htop| \
import| \
limits| \
list| \
mount| \
network| \
pkg| \
rcp| \
rdr| \
rename| \
restart| \
service| \
setup| \
start| \
stop| \
sysrc| \
tags| \
template| \
top| \
umount| \
update| \
upgrade| \
verify| \
zfs)
;;
*)
usage
;;
esac

# shellcheck disable=SC2154
SCRIPTPATH="${bastille_sharedir}/${CMD}.sh"
if [ -f "${SCRIPTPATH}" ]; then
: "${UMASK:=022}"
umask "${UMASK}"

: "${SH:=sh}"

if [ -n "${PARAMS}" ]; then
exec "${SH}" "${SCRIPTPATH}" "${PARAMS}"
else
exec "${SH}" "${SCRIPTPATH}" "$@"
fi
exec "${SH}" "${SCRIPTPATH}" "$@"
else
error_exit "${SCRIPTPATH} not found."
fi
fi
Loading